plugin base: let plugins decide if they should be sorted last
Note that even if a plugin says it wants to be sorted last, the generic plugin will always be the last one. Also, there is no order guaranteed between two plugins that request to be sorted last.
This commit is contained in:
@@ -113,7 +113,6 @@ load_plugin (const char *path)
|
|||||||
plugin = (*plugin_create_func) ();
|
plugin = (*plugin_create_func) ();
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module);
|
g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module);
|
||||||
mm_info ("Loaded plugin %s", mm_plugin_get_name (plugin));
|
|
||||||
} else
|
} else
|
||||||
mm_warn ("Could not load plugin %s: initialization failed", path);
|
mm_warn ("Could not load plugin %s: initialization failed", path);
|
||||||
|
|
||||||
@@ -124,6 +123,31 @@ load_plugin (const char *path)
|
|||||||
return plugin;
|
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)
|
||||||
|
{
|
||||||
|
mm_info ("Loaded plugin '%s'", mm_plugin_get_name (plugin));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_plugins (MMManager *manager)
|
load_plugins (MMManager *manager)
|
||||||
{
|
{
|
||||||
@@ -162,10 +186,19 @@ load_plugins (MMManager *manager)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sort last plugins that request it */
|
||||||
|
priv->plugins = g_slist_sort (priv->plugins, (GCompareFunc)compare_plugins);
|
||||||
|
|
||||||
/* Make sure the generic plugin is last */
|
/* Make sure the generic plugin is last */
|
||||||
if (generic_plugin)
|
if (generic_plugin)
|
||||||
priv->plugins = g_slist_append (priv->plugins, generic_plugin);
|
priv->plugins = g_slist_append (priv->plugins, generic_plugin);
|
||||||
|
|
||||||
|
/* Now report about all the found plugins, in the same order they will be
|
||||||
|
* used while checking support */
|
||||||
|
g_slist_foreach (priv->plugins, (GFunc)found_plugin, NULL);
|
||||||
|
|
||||||
|
mm_info ("Successfully loaded %u plugins", g_slist_length (priv->plugins));
|
||||||
|
|
||||||
g_dir_close (dir);
|
g_dir_close (dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -65,11 +65,13 @@ typedef struct {
|
|||||||
char *name;
|
char *name;
|
||||||
GUdevClient *client;
|
GUdevClient *client;
|
||||||
GHashTable *tasks;
|
GHashTable *tasks;
|
||||||
|
gboolean sort_last;
|
||||||
} MMPluginBasePrivate;
|
} MMPluginBasePrivate;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_NAME,
|
PROP_NAME,
|
||||||
|
PROP_SORT_LAST,
|
||||||
LAST_PROP
|
LAST_PROP
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1216,6 +1218,12 @@ get_name (MMPlugin *plugin)
|
|||||||
return MM_PLUGIN_BASE_GET_PRIVATE (plugin)->name;
|
return MM_PLUGIN_BASE_GET_PRIVATE (plugin)->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
get_sort_last (const MMPlugin *plugin)
|
||||||
|
{
|
||||||
|
return MM_PLUGIN_BASE_GET_PRIVATE (plugin)->sort_last;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_driver_name (GUdevDevice *device)
|
get_driver_name (GUdevDevice *device)
|
||||||
{
|
{
|
||||||
@@ -1387,6 +1395,7 @@ plugin_init (MMPlugin *plugin_class)
|
|||||||
{
|
{
|
||||||
/* interface implementation */
|
/* interface implementation */
|
||||||
plugin_class->get_name = get_name;
|
plugin_class->get_name = get_name;
|
||||||
|
plugin_class->get_sort_last = get_sort_last;
|
||||||
plugin_class->supports_port = supports_port;
|
plugin_class->supports_port = supports_port;
|
||||||
plugin_class->cancel_supports_port = cancel_supports_port;
|
plugin_class->cancel_supports_port = cancel_supports_port;
|
||||||
plugin_class->grab_port = grab_port;
|
plugin_class->grab_port = grab_port;
|
||||||
@@ -1424,6 +1433,10 @@ set_property (GObject *object, guint prop_id,
|
|||||||
/* Construct only */
|
/* Construct only */
|
||||||
priv->name = g_value_dup_string (value);
|
priv->name = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_SORT_LAST:
|
||||||
|
/* Construct only */
|
||||||
|
priv->sort_last = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -1440,6 +1453,9 @@ get_property (GObject *object, guint prop_id,
|
|||||||
case PROP_NAME:
|
case PROP_NAME:
|
||||||
g_value_set_string (value, priv->name);
|
g_value_set_string (value, priv->name);
|
||||||
break;
|
break;
|
||||||
|
case PROP_SORT_LAST:
|
||||||
|
g_value_set_boolean (value, priv->sort_last);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -1482,6 +1498,15 @@ mm_plugin_base_class_init (MMPluginBaseClass *klass)
|
|||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||||
|
|
||||||
|
g_object_class_install_property
|
||||||
|
(object_class, PROP_SORT_LAST,
|
||||||
|
g_param_spec_boolean (MM_PLUGIN_BASE_SORT_LAST,
|
||||||
|
"Sort Last",
|
||||||
|
"Whether the plugin should be sorted last in the"
|
||||||
|
"list of plugins loaded",
|
||||||
|
FALSE,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||||
|
|
||||||
signals[PROBE_RESULT] =
|
signals[PROBE_RESULT] =
|
||||||
g_signal_new ("probe-result",
|
g_signal_new ("probe-result",
|
||||||
G_OBJECT_CLASS_TYPE (object_class),
|
G_OBJECT_CLASS_TYPE (object_class),
|
||||||
|
@@ -106,7 +106,8 @@ void mm_plugin_base_supports_task_add_custom_init_command (MMPluginBaseSupportsT
|
|||||||
#define MM_IS_PLUBIN_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_BASE))
|
#define MM_IS_PLUBIN_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_BASE))
|
||||||
#define MM_PLUGIN_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_BASE, MMPluginBaseClass))
|
#define MM_PLUGIN_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_BASE, MMPluginBaseClass))
|
||||||
|
|
||||||
#define MM_PLUGIN_BASE_NAME "name"
|
#define MM_PLUGIN_BASE_NAME "name"
|
||||||
|
#define MM_PLUGIN_BASE_SORT_LAST "sort-last"
|
||||||
|
|
||||||
typedef struct _MMPluginBase MMPluginBase;
|
typedef struct _MMPluginBase MMPluginBase;
|
||||||
typedef struct _MMPluginBaseClass MMPluginBaseClass;
|
typedef struct _MMPluginBaseClass MMPluginBaseClass;
|
||||||
|
@@ -24,6 +24,14 @@ mm_plugin_get_name (MMPlugin *plugin)
|
|||||||
return MM_PLUGIN_GET_INTERFACE (plugin)->get_name (plugin);
|
return MM_PLUGIN_GET_INTERFACE (plugin)->get_name (plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_plugin_get_sort_last (const MMPlugin *plugin)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MM_IS_PLUGIN (plugin), FALSE);
|
||||||
|
|
||||||
|
return MM_PLUGIN_GET_INTERFACE (plugin)->get_sort_last (plugin);
|
||||||
|
}
|
||||||
|
|
||||||
MMPluginSupportsResult
|
MMPluginSupportsResult
|
||||||
mm_plugin_supports_port (MMPlugin *plugin,
|
mm_plugin_supports_port (MMPlugin *plugin,
|
||||||
const char *subsys,
|
const char *subsys,
|
||||||
@@ -100,8 +108,8 @@ mm_plugin_get_type (void)
|
|||||||
};
|
};
|
||||||
|
|
||||||
plugin_type = g_type_register_static (G_TYPE_INTERFACE,
|
plugin_type = g_type_register_static (G_TYPE_INTERFACE,
|
||||||
"MMPlugin",
|
"MMPlugin",
|
||||||
&plugin_info, 0);
|
&plugin_info, 0);
|
||||||
|
|
||||||
g_type_interface_add_prerequisite (plugin_type, G_TYPE_OBJECT);
|
g_type_interface_add_prerequisite (plugin_type, G_TYPE_OBJECT);
|
||||||
}
|
}
|
||||||
|
@@ -54,9 +54,14 @@ typedef enum {
|
|||||||
struct _MMPlugin {
|
struct _MMPlugin {
|
||||||
GTypeInterface g_iface;
|
GTypeInterface g_iface;
|
||||||
|
|
||||||
/* Methods */
|
/* Get plugin name */
|
||||||
const char *(*get_name) (MMPlugin *self);
|
const char *(*get_name) (MMPlugin *self);
|
||||||
|
|
||||||
|
/* Returns TRUE if the plugin should be sorted last in the list of plugins
|
||||||
|
* loaded. This is useful to indicate plugins that need an additional check
|
||||||
|
* on the probed vendor ID to see if they can support it. */
|
||||||
|
gboolean (*get_sort_last) (const MMPlugin *self);
|
||||||
|
|
||||||
/* Check whether a plugin supports a particular modem port, and what level
|
/* Check whether a plugin supports a particular modem port, and what level
|
||||||
* of support the plugin has for the device. If the plugin can immediately
|
* of support the plugin has for the device. If the plugin can immediately
|
||||||
* determine whether a port is unsupported, it should return
|
* determine whether a port is unsupported, it should return
|
||||||
@@ -104,6 +109,8 @@ GType mm_plugin_get_type (void);
|
|||||||
|
|
||||||
const char *mm_plugin_get_name (MMPlugin *plugin);
|
const char *mm_plugin_get_name (MMPlugin *plugin);
|
||||||
|
|
||||||
|
gboolean mm_plugin_get_sort_last (const MMPlugin *plugin);
|
||||||
|
|
||||||
MMPluginSupportsResult mm_plugin_supports_port (MMPlugin *plugin,
|
MMPluginSupportsResult mm_plugin_supports_port (MMPlugin *plugin,
|
||||||
const char *subsys,
|
const char *subsys,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
Reference in New Issue
Block a user