plugin-base: improve the logic to check whether vendor or product probing needed
If the plugin does a Vendor ID check and it passes, it doesn't need Vendor string probing. If the plugin does a Vendor ID check and it fails: - If Vendor strings reported, it needs Vendor probing. - If Vendor strings not reported, fail as unsupported. If the plugin does a Product ID check and it passes, it doesn't need Product string probing. If the plugin does a Product ID check and it fails: - If Product strings reported, it needs Product probing. - If Product strings not reported, fail as unsupported.
This commit is contained in:

committed by
Aleksander Morgado

parent
0646fc9d99
commit
afd386738d
@@ -275,11 +275,16 @@ apply_pre_probing_filters (MMPluginBase *self,
|
|||||||
GUdevDevice *port,
|
GUdevDevice *port,
|
||||||
const gchar *subsys,
|
const gchar *subsys,
|
||||||
const gchar *name,
|
const gchar *name,
|
||||||
const gchar *driver)
|
const gchar *driver,
|
||||||
|
gboolean *need_vendor_probing,
|
||||||
|
gboolean *need_product_probing)
|
||||||
{
|
{
|
||||||
MMPluginBasePrivate *priv = MM_PLUGIN_BASE_GET_PRIVATE (self);
|
MMPluginBasePrivate *priv = MM_PLUGIN_BASE_GET_PRIVATE (self);
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
|
*need_vendor_probing = FALSE;
|
||||||
|
*need_product_probing = FALSE;
|
||||||
|
|
||||||
/* The plugin may specify that only some subsystems are supported. If that
|
/* The plugin may specify that only some subsystems are supported. If that
|
||||||
* is the case, filter by subsystem */
|
* is the case, filter by subsystem */
|
||||||
if (priv->subsystems) {
|
if (priv->subsystems) {
|
||||||
@@ -309,6 +314,7 @@ apply_pre_probing_filters (MMPluginBase *self,
|
|||||||
/* The plugin may specify that only some vendor IDs are supported. If that
|
/* The plugin may specify that only some vendor IDs are supported. If that
|
||||||
* is the case, filter by vendor ID. */
|
* is the case, filter by vendor ID. */
|
||||||
if (priv->vendor_ids) {
|
if (priv->vendor_ids) {
|
||||||
|
gboolean vendor_filtered = FALSE;
|
||||||
guint16 vendor = 0;
|
guint16 vendor = 0;
|
||||||
guint16 product = 0;
|
guint16 product = 0;
|
||||||
|
|
||||||
@@ -316,32 +322,62 @@ apply_pre_probing_filters (MMPluginBase *self,
|
|||||||
|
|
||||||
/* If we didn't get any vendor: unsupported */
|
/* If we didn't get any vendor: unsupported */
|
||||||
if (!vendor)
|
if (!vendor)
|
||||||
return TRUE;
|
vendor_filtered = TRUE;
|
||||||
|
else {
|
||||||
for (i = 0; priv->vendor_ids[i]; i++)
|
for (i = 0; priv->vendor_ids[i]; i++)
|
||||||
if (vendor == priv->vendor_ids[i])
|
if (vendor == priv->vendor_ids[i])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* If we didn't match any vendor: unsupported */
|
/* If we didn't match any vendor: unsupported */
|
||||||
if (!priv->vendor_ids[i])
|
if (!priv->vendor_ids[i])
|
||||||
|
vendor_filtered = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vendor_filtered) {
|
||||||
|
/* If we got filtered by vendor and we do not have vendor strings
|
||||||
|
* to compare with: unsupported */
|
||||||
|
if (!priv->vendor_strings)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* Otherwise, we need to probe vendor strings. This cover the
|
||||||
|
* case where a RS232 modem is connected via a USB<->RS232 adaptor,
|
||||||
|
* and we get in udev the vendor ID of the adaptor */
|
||||||
|
*need_vendor_probing = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* The plugin may specify that only some product IDs are supported. If
|
/* The plugin may specify that only some product IDs are supported. If
|
||||||
* that is the case, filter by product ID */
|
* that is the case, filter by product ID */
|
||||||
if (priv->product_ids) {
|
if (priv->product_ids) {
|
||||||
|
gboolean product_filtered = FALSE;
|
||||||
|
|
||||||
/* If we didn't get any product: unsupported */
|
/* If we didn't get any product: unsupported */
|
||||||
if (!product)
|
if (!product)
|
||||||
return TRUE;
|
product_filtered = TRUE;
|
||||||
|
else {;
|
||||||
for (i = 0; priv->product_ids[i]; i++)
|
for (i = 0; priv->product_ids[i]; i++)
|
||||||
if (product == priv->product_ids[i])
|
if (product == priv->product_ids[i])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* If we didn't match any product: unsupported */
|
/* If we didn't match any product: unsupported */
|
||||||
if (!priv->product_ids[i])
|
if (!priv->product_ids[i])
|
||||||
|
product_filtered = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (product_filtered) {
|
||||||
|
/* If we got filtered by product and we do not have product
|
||||||
|
* strings to compare with: unsupported */
|
||||||
|
if (!priv->product_strings)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* Otherwise, we need to probe product strings. This cover the
|
||||||
|
* case where a RS232 modem is connected via a USB<->RS232
|
||||||
|
* adaptor, and we get in udev the product ID of the adaptor */
|
||||||
|
*need_product_probing = TRUE;
|
||||||
}
|
}
|
||||||
}
|
} else if (priv->vendor_strings)
|
||||||
|
*need_product_probing = TRUE;
|
||||||
|
} else if (priv->vendor_strings)
|
||||||
|
*need_vendor_probing = TRUE;
|
||||||
|
|
||||||
/* The plugin may specify that only ports with some given udev tags are
|
/* The plugin may specify that only ports with some given udev tags are
|
||||||
* supported. If that is the case, filter by udev tag */
|
* supported. If that is the case, filter by udev tag */
|
||||||
@@ -505,6 +541,8 @@ supports_port (MMPlugin *plugin,
|
|||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
GSimpleAsyncResult *async_result;
|
GSimpleAsyncResult *async_result;
|
||||||
PortProbeRunContext *ctx;
|
PortProbeRunContext *ctx;
|
||||||
|
gboolean need_vendor_probing;
|
||||||
|
gboolean need_product_probing;
|
||||||
guint32 probe_run_flags;
|
guint32 probe_run_flags;
|
||||||
|
|
||||||
async_result = g_simple_async_result_new (G_OBJECT (self),
|
async_result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
@@ -553,7 +591,9 @@ supports_port (MMPlugin *plugin,
|
|||||||
port,
|
port,
|
||||||
subsys,
|
subsys,
|
||||||
name,
|
name,
|
||||||
driver)) {
|
driver,
|
||||||
|
&need_vendor_probing,
|
||||||
|
&need_product_probing)) {
|
||||||
/* Filtered! */
|
/* Filtered! */
|
||||||
g_simple_async_result_set_op_res_gboolean (async_result, FALSE);
|
g_simple_async_result_set_op_res_gboolean (async_result, FALSE);
|
||||||
g_simple_async_result_complete_in_idle (async_result);
|
g_simple_async_result_complete_in_idle (async_result);
|
||||||
@@ -568,9 +608,9 @@ supports_port (MMPlugin *plugin,
|
|||||||
probe_run_flags = 0;
|
probe_run_flags = 0;
|
||||||
if (priv->capabilities)
|
if (priv->capabilities)
|
||||||
probe_run_flags |= MM_PORT_PROBE_AT_CAPABILITIES;
|
probe_run_flags |= MM_PORT_PROBE_AT_CAPABILITIES;
|
||||||
if (priv->vendor_strings)
|
if (need_vendor_probing)
|
||||||
probe_run_flags |= MM_PORT_PROBE_AT_VENDOR;
|
probe_run_flags |= MM_PORT_PROBE_AT_VENDOR;
|
||||||
if (priv->product_strings)
|
if (need_product_probing)
|
||||||
probe_run_flags |= MM_PORT_PROBE_AT_PRODUCT;
|
probe_run_flags |= MM_PORT_PROBE_AT_PRODUCT;
|
||||||
if (priv->qcdm)
|
if (priv->qcdm)
|
||||||
probe_run_flags |= MM_PORT_PROBE_QCDM;
|
probe_run_flags |= MM_PORT_PROBE_QCDM;
|
||||||
|
Reference in New Issue
Block a user