plugin: new `MM_PLUGIN_FORBIDDEN_DRIVERS' property

It allows plugins to specify whether they cannot support ports handled by
specific drivers.
This commit is contained in:
Aleksander Morgado
2012-07-11 07:03:56 +02:00
parent 1078b246b0
commit f5fdf946c9
3 changed files with 48 additions and 13 deletions

View File

@@ -142,9 +142,13 @@
any port detected being managed by a driver not listed by the plugin.
</para>
<para>
This filter is specified by the <type>MM_PLUGIN_ALLOWED_DRIVERS</type>
property in the <structname>MMPlugin</structname> object provided
by the plugin.
Plugins can also specify which drivers they do not expect, so that we
filter out any port detected being managed by a driver listed by the plugin.
</para>
<para>
These filters are specified by the <type>MM_PLUGIN_ALLOWED_DRIVERS</type>
and <type>MM_PLUGIN_FORBIDDEN_DRIVERS</type> properties in the
<structname>MMPlugin</structname> object provided by the plugin.
</para>
</listitem>
<listitem>

View File

@@ -52,6 +52,7 @@ struct _MMPluginPrivate {
/* Plugin-specific setups */
gchar **subsystems;
gchar **drivers;
gchar **forbidden_drivers;
guint16 *vendor_ids;
mm_uint16_pair *product_ids;
gchar **vendor_strings;
@@ -69,6 +70,7 @@ enum {
PROP_NAME,
PROP_ALLOWED_SUBSYSTEMS,
PROP_ALLOWED_DRIVERS,
PROP_FORBIDDEN_DRIVERS,
PROP_ALLOWED_VENDOR_IDS,
PROP_ALLOWED_PRODUCT_IDS,
PROP_ALLOWED_VENDOR_STRINGS,
@@ -162,9 +164,10 @@ apply_pre_probing_filters (MMPlugin *self,
return TRUE;
}
/* The plugin may specify that only some drivers are supported. If that
* is the case, filter by driver */
if (self->priv->drivers) {
/* The plugin may specify that only some drivers are supported, or that some
* drivers are not supported. If that is the case, filter by driver */
if (self->priv->drivers ||
self->priv->forbidden_drivers) {
const gchar *driver;
/* Detect any modems accessible through the list of virtual ports */
@@ -176,6 +179,8 @@ apply_pre_probing_filters (MMPlugin *self,
if (!driver)
return TRUE;
/* Filtering by allowed drivers */
if (self->priv->drivers) {
for (i = 0; self->priv->drivers[i]; i++) {
if (g_str_equal (driver, self->priv->drivers[i]))
break;
@@ -185,6 +190,15 @@ apply_pre_probing_filters (MMPlugin *self,
if (!self->priv->drivers[i])
return TRUE;
}
/* Filtering by forbidden drivers */
else {
for (i = 0; self->priv->forbidden_drivers[i]; i++) {
/* If we match a forbidden driver: unsupported */
if (g_str_equal (driver, self->priv->forbidden_drivers[i]))
return TRUE;
}
}
}
vendor = mm_device_get_vendor (device);
product = mm_device_get_product (device);
@@ -614,6 +628,10 @@ set_property (GObject *object,
/* Construct only */
self->priv->drivers = g_value_dup_boxed (value);
break;
case PROP_FORBIDDEN_DRIVERS:
/* Construct only */
self->priv->forbidden_drivers = g_value_dup_boxed (value);
break;
case PROP_ALLOWED_VENDOR_IDS:
/* Construct only */
self->priv->vendor_ids = g_value_dup_boxed (value);
@@ -678,6 +696,9 @@ get_property (GObject *object,
case PROP_ALLOWED_DRIVERS:
g_value_set_boxed (value, self->priv->drivers);
break;
case PROP_FORBIDDEN_DRIVERS:
g_value_set_boxed (value, self->priv->forbidden_drivers);
break;
case PROP_ALLOWED_VENDOR_IDS:
g_value_set_boxed (value, self->priv->vendor_ids);
break;
@@ -762,6 +783,15 @@ mm_plugin_class_init (MMPluginClass *klass)
G_TYPE_STRV,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_FORBIDDEN_DRIVERS,
g_param_spec_boxed (MM_PLUGIN_FORBIDDEN_DRIVERS,
"Forbidden drivers",
"List of drivers this plugin cannot support, "
"should be an array of strings finished with 'NULL'",
G_TYPE_STRV,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_ALLOWED_VENDOR_IDS,
g_param_spec_boxed (MM_PLUGIN_ALLOWED_VENDOR_IDS,

View File

@@ -40,6 +40,7 @@
#define MM_PLUGIN_NAME "name"
#define MM_PLUGIN_ALLOWED_SUBSYSTEMS "allowed-subsystems"
#define MM_PLUGIN_ALLOWED_DRIVERS "allowed-drivers"
#define MM_PLUGIN_FORBIDDEN_DRIVERS "forbidden-drivers"
#define MM_PLUGIN_ALLOWED_VENDOR_IDS "allowed-vendor-ids"
#define MM_PLUGIN_ALLOWED_PRODUCT_IDS "allowed-product-ids"
#define MM_PLUGIN_ALLOWED_VENDOR_STRINGS "allowed-vendor-strings"