diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-08 16:22:52 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-08 17:53:42 +0200 |
commit | 93e4c8625beb1dab16dd2ae23b6d09587200fea8 (patch) | |
tree | 4b6ccdb25a17247ab839110412faf13c82499533 /src | |
parent | 4b058872a092fa85413fa905c37a6a1510a7a056 (diff) |
plugin: don't match generic plugin by name
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 | 3 |
3 files changed, 36 insertions, 13 deletions
diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index d00b65e3..9ee4edae 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -363,7 +363,7 @@ port_context_set_suggestion (PortContext *port_context, return; /* The GENERIC plugin is NEVER suggested to others */ - if (g_str_equal (mm_plugin_get_name (suggested_plugin), MM_PLUGIN_GENERIC_NAME)) + if (mm_plugin_is_generic (suggested_plugin)) return; /* If the plugin has MM_PLUGIN_FORBIDDEN_ICERA set, we do *not* suggest @@ -974,10 +974,10 @@ device_context_set_best_plugin (DeviceContext *device_context, * one and now we're reporting a more specific one, use the new one. */ if (!device_context->best_plugin || - (g_str_equal (mm_plugin_get_name (device_context->best_plugin), MM_PLUGIN_GENERIC_NAME) && + (mm_plugin_is_generic (device_context->best_plugin) && device_context->best_plugin != best_plugin)) { /* Only log best plugin if it's not the generic one */ - if (!g_str_equal (mm_plugin_get_name (best_plugin), MM_PLUGIN_GENERIC_NAME)) + if (!mm_plugin_is_generic (best_plugin)) mm_obj_dbg (self, "task %s: found best plugin: %s", port_context->name, mm_plugin_get_name (best_plugin)); /* Store and suggest this plugin also to other port probes */ @@ -1170,10 +1170,8 @@ device_context_run_port_context (DeviceContext *device_context, /* If we got one already set in the device context, it will be the first one, * unless it is the generic plugin */ - if (device_context->best_plugin && - !g_str_equal (mm_plugin_get_name (device_context->best_plugin), MM_PLUGIN_GENERIC_NAME)) { + if (device_context->best_plugin && !mm_plugin_is_generic (device_context->best_plugin)) suggested = device_context->best_plugin; - } port_context_run (self, port_context, @@ -1805,11 +1803,12 @@ load_plugins (MMPluginManager *self, if (!plugin) continue; - if (g_str_equal (mm_plugin_get_name (plugin), MM_PLUGIN_GENERIC_NAME)) - /* Generic plugin */ - self->priv->generic = plugin; - else - /* Vendor specific plugin */ + if (mm_plugin_is_generic (plugin)) { + if (self->priv->generic) + mm_obj_warn (self, "cannot register more than one generic plugin"); + else + self->priv->generic = plugin; + } else self->priv->plugins = g_list_append (self->priv->plugins, plugin); /* Register plugin whitelist rules in filter, if any */ diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 6849218d..4f3ec18d 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -64,8 +64,9 @@ static const gchar *virtual_port[] = {"smd0", NULL}; struct _MMPluginPrivate { - gchar *name; + gchar *name; GHashTable *tasks; + gboolean is_generic; /* Pre-probing filters */ gchar **subsystems; @@ -107,6 +108,7 @@ struct _MMPluginPrivate { enum { PROP_0, PROP_NAME, + PROP_IS_GENERIC, PROP_ALLOWED_SUBSYSTEMS, PROP_ALLOWED_DRIVERS, PROP_FORBIDDEN_DRIVERS, @@ -156,6 +158,12 @@ mm_plugin_get_allowed_product_ids (MMPlugin *self) return self->priv->product_ids; } +gboolean +mm_plugin_is_generic (MMPlugin *self) +{ + return self->priv->is_generic; +} + /*****************************************************************************/ static gboolean @@ -1110,6 +1118,10 @@ set_property (GObject *object, /* Construct only */ self->priv->name = g_value_dup_string (value); break; + case PROP_IS_GENERIC: + /* Construct only */ + self->priv->is_generic = g_value_get_boolean (value); + break; case PROP_ALLOWED_SUBSYSTEMS: /* Construct only */ self->priv->subsystems = g_value_dup_boxed (value); @@ -1232,6 +1244,9 @@ get_property (GObject *object, case PROP_NAME: g_value_set_string (value, self->priv->name); break; + case PROP_IS_GENERIC: + g_value_set_boolean (value, self->priv->is_generic); + break; case PROP_ALLOWED_SUBSYSTEMS: g_value_set_boxed (value, self->priv->subsystems); break; @@ -1370,6 +1385,14 @@ mm_plugin_class_init (MMPluginClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property + (object_class, PROP_IS_GENERIC, + g_param_spec_boolean (MM_PLUGIN_IS_GENERIC, + "Generic", + "Whether the plugin is the generic one", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_ALLOWED_SUBSYSTEMS, g_param_spec_boxed (MM_PLUGIN_ALLOWED_SUBSYSTEMS, "Allowed subsystems", diff --git a/src/mm-plugin.h b/src/mm-plugin.h index 926840bf..fe0469c1 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -27,7 +27,6 @@ #include "mm-device.h" #include "mm-kernel-device.h" -#define MM_PLUGIN_GENERIC_NAME "Generic" #define MM_PLUGIN_MAJOR_VERSION 4 #define MM_PLUGIN_MINOR_VERSION 0 @@ -48,6 +47,7 @@ #define MM_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN, MMPluginClass)) #define MM_PLUGIN_NAME "name" +#define MM_PLUGIN_IS_GENERIC "is-generic" #define MM_PLUGIN_ALLOWED_SUBSYSTEMS "allowed-subsystems" #define MM_PLUGIN_ALLOWED_DRIVERS "allowed-drivers" #define MM_PLUGIN_FORBIDDEN_DRIVERS "forbidden-drivers" @@ -127,6 +127,7 @@ GType mm_plugin_get_type (void); const gchar *mm_plugin_get_name (MMPlugin *self); const gchar **mm_plugin_get_allowed_udev_tags (MMPlugin *self); const mm_uint16_pair *mm_plugin_get_allowed_product_ids (MMPlugin *self); +gboolean mm_plugin_is_generic (MMPlugin *self); /* This method will run all pre-probing filters, to see if we can discard this * plugin from the probing logic as soon as possible. */ |