plugin: don't match generic plugin by name

This commit is contained in:
Aleksander Morgado
2020-04-08 16:22:52 +02:00
parent 4b058872a0
commit 93e4c8625b
5 changed files with 39 additions and 15 deletions

View File

@@ -95,7 +95,8 @@ mm_plugin_create (void)
return MM_PLUGIN (
g_object_new (MM_TYPE_PLUGIN_GENERIC,
MM_PLUGIN_NAME, MM_PLUGIN_GENERIC_NAME,
MM_PLUGIN_NAME, MM_MODULE_NAME,
MM_PLUGIN_IS_GENERIC, TRUE,
MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
MM_PLUGIN_ALLOWED_AT, TRUE,
MM_PLUGIN_ALLOWED_QCDM, TRUE,

View File

@@ -51,7 +51,7 @@ test_enable_disable (TestFixture *fixture)
/* Set the test profile */
test_fixture_set_profile (fixture,
"test-enable-disable",
"Generic",
"generic",
(const gchar *const *)ports);
/* Wait and get the modem object */

View File

@@ -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 */

View File

@@ -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;
@@ -1369,6 +1384,14 @@ mm_plugin_class_init (MMPluginClass *klass)
NULL,
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,

View File

@@ -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. */