diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-11 12:08:35 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-06 20:06:46 +0200 |
commit | 86f4923d7f69e7adcd488fb7085429b04dec3190 (patch) | |
tree | e96deedcab0067be4046039e95e1dc894a09b88d /src | |
parent | 624a1e9087a7020824a94914d3989ebf00093c07 (diff) |
plugin: new method to compare plugins
Instead of providing a method to get if a plugin is requesting to get sorted
last, we provide a way to comparing two plugins, compatible with the
GCompareFunc required in g_list_sort().
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-plugin-manager.c | 21 | ||||
-rw-r--r-- | src/mm-plugin.c | 25 | ||||
-rw-r--r-- | src/mm-plugin.h | 5 |
3 files changed, 25 insertions, 26 deletions
diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index b506f6da..fd7d3864 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -549,25 +549,6 @@ out: return plugin; } -static gint -compare_plugins (const MMPlugin *plugin_a, - const MMPlugin *plugin_b) -{ - /* The order of the plugins in the list is the same order used to check - * whether the plugin can manage a given modem: - * - First, modems that will check vendor ID from udev. - * - Then, modems that report to be sorted last (those which will check - * vendor ID also from the probed ones.. - */ - if (mm_plugin_get_sort_last (plugin_a) && - !mm_plugin_get_sort_last (plugin_b)) - return 1; - if (!mm_plugin_get_sort_last (plugin_a) && - mm_plugin_get_sort_last (plugin_b)) - return -1; - return 0; -} - static void found_plugin (MMPlugin *plugin) { @@ -628,7 +609,7 @@ load_plugins (MMPluginManager *self, /* Sort last plugins that request it */ self->priv->plugins = g_slist_sort (self->priv->plugins, - (GCompareFunc)compare_plugins); + (GCompareFunc)mm_plugin_cmp); /* Make sure the generic plugin is last */ if (generic_plugin) diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 3771272a..5bc62c09 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -88,19 +88,36 @@ enum { /*****************************************************************************/ -const char * +const gchar * mm_plugin_get_name (MMPlugin *self) { return self->priv->name; } -gboolean -mm_plugin_get_sort_last (const MMPlugin *self) +/*****************************************************************************/ + +gint +mm_plugin_cmp (const MMPlugin *plugin_a, + const MMPlugin *plugin_b) { /* If we have any post-probing filter, we need to sort the plugin last */ - return (self->priv->vendor_strings || self->priv->product_strings); +#define SORT_LAST(self) (self->priv->vendor_strings || self->priv->product_strings) + + /* The order of the plugins in the list is the same order used to check + * whether the plugin can manage a given modem: + * - First, modems that will check vendor ID from udev. + * - Then, modems that report to be sorted last (those which will check + * vendor ID also from the probed ones.. + */ + if (SORT_LAST (plugin_a) && !SORT_LAST (plugin_b)) + return 1; + if (!SORT_LAST (plugin_a) && SORT_LAST (plugin_b)) + return -1; + return 0; } +/*****************************************************************************/ + static gboolean device_file_exists (const char *name) { diff --git a/src/mm-plugin.h b/src/mm-plugin.h index d9efa69b..5a2c9c73 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -96,8 +96,9 @@ struct _MMPluginClass { GType mm_plugin_get_type (void); -const char *mm_plugin_get_name (MMPlugin *plugin); -gboolean mm_plugin_get_sort_last (const MMPlugin *plugin); +const gchar *mm_plugin_get_name (MMPlugin *plugin); +gint mm_plugin_cmp (const MMPlugin *plugin_a, + const MMPlugin *plugin_b); void mm_plugin_supports_port (MMPlugin *plugin, GObject *device, |