qulogic/gplugin

Parents 2d8020b09ddd
Children 82e7038e37cf
Finally implement gplugin_manager_real_get_plugin_dependencies and use it from gplugin_manager_load_dependencies
--- a/gplugin/gplugin-manager.c Mon Feb 10 04:32:22 2020 -0600
+++ b/gplugin/gplugin-manager.c Mon Feb 10 05:14:14 2020 -0600
@@ -605,19 +605,52 @@
GPluginPluginInfo *info,
GError **error)
{
+ GSList *dependencies = NULL, *l = NULL;
+ GError *ourerror = NULL;
+ gboolean all_loaded = TRUE;
+
+ dependencies = gplugin_manager_get_plugin_dependencies(plugin, &ourerror);
+ if(ourerror != NULL) {
+ g_propagate_error(error, ourerror);
+
+ return FALSE;
+ }
+
+ for(l = dependencies; l != NULL; l = l->next) {
+ GPluginPlugin *dependency = GPLUGIN_PLUGIN(l->data);
+ gboolean loaded = FALSE;
+
+ loaded = gplugin_manager_load_plugin(dependency, error);
+
+ if(!loaded) {
+ all_loaded = FALSE;
+ break;
+ }
+ }
+
+ gplugin_manager_free_plugin_list(dependencies);
+
+ return all_loaded;
+}
+
+static GSList *
+gplugin_manager_real_get_plugin_dependencies(G_GNUC_UNUSED GPluginManager *manager,
+ GPluginPlugin *plugin,
+ GError **error)
+{
+ GPluginPluginInfo *info = NULL;
+ GSList *ret = NULL;
const gchar * const *dependencies = NULL;
- gboolean all_found = TRUE;
gint i = 0;
- /* now walk through any dependencies the plugin has and load them. If they
- * fail to load we need to fail as well.
- */
+ info = gplugin_plugin_get_info(plugin);
dependencies = gplugin_plugin_info_get_dependencies(info);
+
if(dependencies == NULL) {
- return TRUE;
+ return NULL;
}
- for(i = 0; dependencies[i]; i++) {
+ for(i = 0; dependencies[i] != NULL; i++) {
gboolean found = FALSE;
gchar **ors = NULL;
gint o = 0;
@@ -625,7 +658,7 @@
ors = g_strsplit(dependencies[i], "|", 0);
for(o = 0; ors[o]; o++) {
GMatchInfo *match = NULL;
- GSList *matches = NULL, *m = NULL;
+ GSList *matches = NULL;
gchar *oid = NULL, *oop = NULL, *over = NULL;
if(!g_regex_match(dependency_regex, ors[o], 0, &match)) {
@@ -643,88 +676,38 @@
/* now look for a plugin matching the id */
matches = gplugin_manager_find_plugins_with_version(oid, oop,
over);
-
- g_message("looking for %s %s%s: found %p", oid, oop, over, matches);
- if(matches == NULL) {
- g_free(oid);
- g_free(oop);
- g_free(over);
- continue;
- }
-
- /* now iterate the matches */
- for(m = matches; m; m = m->next) {
- GPluginPlugin *dplugin = GPLUGIN_PLUGIN(g_object_ref(G_OBJECT(m->data)));
- gboolean ret = FALSE;
-
- ret = gplugin_manager_load_plugin(dplugin, error);
-
-# warning need to figure out dependencies
-// gplugin_plugin_add_dependent_plugin(dplugin, plugin);
-
- g_object_unref(G_OBJECT(dplugin));
-
- if(ret) {
- found = TRUE;
- break;
- }
- }
-
g_free(oid);
g_free(oop);
g_free(over);
- if(found) {
- break;
+ if(matches == NULL) {
+ continue;
}
+
+ /* prepend the first found match to our return value */
+ ret = g_slist_prepend(ret, g_object_ref(matches->data));
+ gplugin_manager_free_plugin_list(matches);
+
+ found = TRUE;
+
+ break;
}
g_strfreev(ors);
if(!found) {
- all_found = FALSE;
+ g_set_error(error, GPLUGIN_DOMAIN, 0,
+ _("failed to find dependency %s for %s"),
+ dependencies[i], gplugin_plugin_info_get_id(info));
+
+ gplugin_manager_free_plugin_list(ret);
+
+ g_object_unref(G_OBJECT(info));
+
+ return NULL;
}
}
- return all_found;
-}
-
-static GSList *
-gplugin_manager_real_get_plugin_dependencies(G_GNUC_UNUSED GPluginManager *manager,
- GPluginPlugin *plugin,
- GError **error)
-{
- GPluginPluginInfo *info = NULL;
- GSList *ret = NULL;
- const gchar * const *dependencies = NULL;
- gint idx = 0;
-
- info = gplugin_plugin_get_info(plugin);
- dependencies = gplugin_plugin_info_get_dependencies(info);
-
- if(dependencies == NULL) {
- return NULL;
- }
-
- for(idx = 0; dependencies[idx] != NULL; idx++) {
- GPluginPlugin *dep = gplugin_manager_find_plugin(dependencies[idx]);
-
- if(!GPLUGIN_IS_PLUGIN(dep)) {
- if(error) {
- *error = g_error_new(
- GPLUGIN_DOMAIN,
- 0,
- "failed to find plugin dependency '%s'",
- dependencies[idx]
- );
-
- g_slist_free_full(ret, g_object_unref);
-
- return NULL;
- }
- }
-
- ret = g_slist_prepend(ret, dep);
- }
+ g_object_unref(G_OBJECT(info));
return ret;
}
@@ -1334,8 +1317,6 @@
gint result = 0;
gboolean keep = FALSE;
- g_message("----");
-
/* get the plugin's version from it's info */
info = gplugin_plugin_get_info(plugin);
found_version = gplugin_plugin_info_get_version(info);
@@ -1383,7 +1364,7 @@
/**
* gplugin_manager_free_plugin_list:
- * @plugins_list: (element-type GPlugin.Plugin): Returned value from
+ * @plugins_list: (element-type GPlugin.Plugin) (nullable): Returned value from
* #gplugin_manager_find_plugins
*
* Frees the return value of #gplugin_manager_find_plugins.
@@ -1392,8 +1373,6 @@
gplugin_manager_free_plugin_list(GSList *plugins_list) {
GSList *l = NULL;
- g_return_if_fail(plugins_list != NULL);
-
for(l = plugins_list; l; l = l->next) {
GPluginPlugin *plugin = NULL;
@@ -1446,7 +1425,8 @@
*
* Return value: (element-type GPlugin.Plugin) (transfer full): A #GSList of
* #GPluginPlugin's that @plugin depends on, or NULL on error
- * with @error set.
+ * with @error set. Call #gplugin_manager_free_plugin_list on
+ * the returned value when you're done with it.
*/
GSList *
gplugin_manager_get_plugin_dependencies(GPluginPlugin *plugin, GError **error) {