plugin-manager: use a double-linked list for the plugin list

This commit is contained in:
Aleksander Morgado
2012-07-11 12:12:01 +02:00
parent 86f4923d7f
commit 9be646f274

View File

@@ -44,7 +44,7 @@ G_DEFINE_TYPE_EXTENDED (MMPluginManager, mm_plugin_manager, G_TYPE_OBJECT, 0,
struct _MMPluginManagerPrivate { struct _MMPluginManagerPrivate {
/* The list of plugins. It is loaded once when the program starts, and the /* The list of plugins. It is loaded once when the program starts, and the
* list is NOT expected to change after that. */ * list is NOT expected to change after that. */
GSList *plugins; GList *plugins;
}; };
/*****************************************************************************/ /*****************************************************************************/
@@ -65,7 +65,7 @@ typedef struct {
FindDeviceSupportContext *parent_ctx; FindDeviceSupportContext *parent_ctx;
GUdevDevice *port; GUdevDevice *port;
GSList *current; GList *current;
MMPlugin *best_plugin; MMPlugin *best_plugin;
MMPlugin *suggested_plugin; MMPlugin *suggested_plugin;
guint defer_id; guint defer_id;
@@ -314,14 +314,14 @@ plugin_supports_port_ready (MMPlugin *plugin,
/* The last plugin we tried is NOT the one we got suggested, so /* The last plugin we tried is NOT the one we got suggested, so
* directly check support with the suggested plugin. If we * directly check support with the suggested plugin. If we
* already checked its support, it won't be checked again. */ * already checked its support, it won't be checked again. */
port_probe_ctx->current = g_slist_find (port_probe_ctx->current, port_probe_ctx->current = g_list_find (port_probe_ctx->current,
port_probe_ctx->suggested_plugin); port_probe_ctx->suggested_plugin);
} }
} else { } else {
/* If the plugin knows it doesn't support the modem, just keep on /* If the plugin knows it doesn't support the modem, just keep on
* checking the next plugin. * checking the next plugin.
*/ */
port_probe_ctx->current = g_slist_next (port_probe_ctx->current); port_probe_ctx->current = g_list_next (port_probe_ctx->current);
} }
/* Step */ /* Step */
@@ -337,7 +337,7 @@ plugin_supports_port_ready (MMPlugin *plugin,
g_udev_device_get_subsystem (port_probe_ctx->port), g_udev_device_get_subsystem (port_probe_ctx->port),
g_udev_device_get_name (port_probe_ctx->port), g_udev_device_get_name (port_probe_ctx->port),
mm_plugin_get_name (MM_PLUGIN (port_probe_ctx->suggested_plugin))); mm_plugin_get_name (MM_PLUGIN (port_probe_ctx->suggested_plugin)));
port_probe_ctx->current = g_slist_find (port_probe_ctx->current, port_probe_ctx->current = g_list_find (port_probe_ctx->current,
port_probe_ctx->suggested_plugin); port_probe_ctx->suggested_plugin);
} else { } else {
mm_dbg ("(%s): (%s/%s) deferring support check", mm_dbg ("(%s): (%s/%s) deferring support check",
@@ -420,7 +420,7 @@ device_port_grabbed_cb (MMDevice *device,
/* If we got one suggested, it will be the first one */ /* If we got one suggested, it will be the first one */
port_probe_ctx->suggested_plugin = mm_device_get_plugin (device); port_probe_ctx->suggested_plugin = mm_device_get_plugin (device);
if (port_probe_ctx->suggested_plugin) if (port_probe_ctx->suggested_plugin)
port_probe_ctx->current = g_slist_find (port_probe_ctx->current, port_probe_ctx->current = g_list_find (port_probe_ctx->current,
port_probe_ctx->suggested_plugin); port_probe_ctx->suggested_plugin);
/* Set as running */ /* Set as running */
@@ -602,18 +602,18 @@ load_plugins (MMPluginManager *self,
MM_PLUGIN_GENERIC_NAME)) MM_PLUGIN_GENERIC_NAME))
generic_plugin = plugin; generic_plugin = plugin;
else else
self->priv->plugins = g_slist_append (self->priv->plugins, self->priv->plugins = g_list_append (self->priv->plugins,
plugin); plugin);
} }
} }
/* Sort last plugins that request it */ /* Sort last plugins that request it */
self->priv->plugins = g_slist_sort (self->priv->plugins, self->priv->plugins = g_list_sort (self->priv->plugins,
(GCompareFunc)mm_plugin_cmp); (GCompareFunc)mm_plugin_cmp);
/* Make sure the generic plugin is last */ /* Make sure the generic plugin is last */
if (generic_plugin) if (generic_plugin)
self->priv->plugins = g_slist_append (self->priv->plugins, self->priv->plugins = g_list_append (self->priv->plugins,
generic_plugin); generic_plugin);
/* Treat as error if we don't find any plugin */ /* Treat as error if we don't find any plugin */
@@ -628,10 +628,10 @@ load_plugins (MMPluginManager *self,
/* Now report about all the found plugins, in the same order they will be /* Now report about all the found plugins, in the same order they will be
* used while checking support */ * used while checking support */
g_slist_foreach (self->priv->plugins, (GFunc)found_plugin, NULL); g_list_foreach (self->priv->plugins, (GFunc)found_plugin, NULL);
mm_info ("Successfully loaded %u plugins", mm_info ("Successfully loaded %u plugins",
g_slist_length (self->priv->plugins)); g_list_length (self->priv->plugins));
out: out:
if (dir) if (dir)
@@ -687,8 +687,7 @@ finalize (GObject *object)
/* g_hash_table_destroy (self->priv->supports); */ /* g_hash_table_destroy (self->priv->supports); */
/* Cleanup list of plugins */ /* Cleanup list of plugins */
g_slist_foreach (self->priv->plugins, (GFunc)g_object_unref, NULL); g_list_free_full (self->priv->plugins, (GDestroyNotify)g_object_unref);
g_slist_free (self->priv->plugins);
G_OBJECT_CLASS (mm_plugin_manager_parent_class)->finalize (object); G_OBJECT_CLASS (mm_plugin_manager_parent_class)->finalize (object);
} }