plugin: simplify interface by passing around the device and/or port objects
This commit is contained in:
@@ -292,7 +292,7 @@ mm_device_create_modem (MMDevice *self,
|
|||||||
g_list_length (self->priv->port_probes));
|
g_list_length (self->priv->port_probes));
|
||||||
|
|
||||||
self->priv->modem = mm_plugin_create_modem (self->priv->plugin,
|
self->priv->modem = mm_plugin_create_modem (self->priv->plugin,
|
||||||
self->priv->port_probes,
|
G_OBJECT (self),
|
||||||
error);
|
error);
|
||||||
if (self->priv->modem) {
|
if (self->priv->modem) {
|
||||||
/* Keep the object manager */
|
/* Keep the object manager */
|
||||||
|
@@ -392,10 +392,8 @@ port_probe_context_step (PortProbeContext *port_probe_ctx)
|
|||||||
|
|
||||||
/* Ask the current plugin to check support of this port */
|
/* Ask the current plugin to check support of this port */
|
||||||
mm_plugin_supports_port (MM_PLUGIN (port_probe_ctx->current->data),
|
mm_plugin_supports_port (MM_PLUGIN (port_probe_ctx->current->data),
|
||||||
g_udev_device_get_subsystem (port_probe_ctx->port),
|
G_OBJECT (ctx->device),
|
||||||
g_udev_device_get_name (port_probe_ctx->port),
|
port_probe_ctx->port,
|
||||||
mm_device_get_path (ctx->device),
|
|
||||||
NULL, /* TODO: existing modem */
|
|
||||||
(GAsyncReadyCallback)plugin_supports_port_ready,
|
(GAsyncReadyCallback)plugin_supports_port_ready,
|
||||||
port_probe_ctx);
|
port_probe_ctx);
|
||||||
}
|
}
|
||||||
|
159
src/mm-plugin.c
159
src/mm-plugin.c
@@ -29,6 +29,7 @@
|
|||||||
#include <mm-errors-types.h>
|
#include <mm-errors-types.h>
|
||||||
|
|
||||||
#include "mm-plugin.h"
|
#include "mm-plugin.h"
|
||||||
|
#include "mm-device.h"
|
||||||
#include "mm-port-probe-cache.h"
|
#include "mm-port-probe-cache.h"
|
||||||
#include "mm-at-serial-port.h"
|
#include "mm-at-serial-port.h"
|
||||||
#include "mm-qcdm-serial-port.h"
|
#include "mm-qcdm-serial-port.h"
|
||||||
@@ -207,37 +208,6 @@ mm_plugin_get_sort_last (const MMPlugin *plugin)
|
|||||||
return (priv->vendor_strings || priv->product_strings);
|
return (priv->vendor_strings || priv->product_strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
get_driver_name (GUdevDevice *device)
|
|
||||||
{
|
|
||||||
GUdevDevice *parent = NULL;
|
|
||||||
const char *driver, *subsys;
|
|
||||||
char *ret = NULL;
|
|
||||||
|
|
||||||
driver = g_udev_device_get_driver (device);
|
|
||||||
if (!driver) {
|
|
||||||
parent = g_udev_device_get_parent (device);
|
|
||||||
if (parent)
|
|
||||||
driver = g_udev_device_get_driver (parent);
|
|
||||||
|
|
||||||
/* Check for bluetooth; it's driver is a bunch of levels up so we
|
|
||||||
* just check for the subsystem of the parent being bluetooth.
|
|
||||||
*/
|
|
||||||
if (!driver && parent) {
|
|
||||||
subsys = g_udev_device_get_subsystem (parent);
|
|
||||||
if (subsys && !strcmp (subsys, "bluetooth"))
|
|
||||||
driver = "bluetooth";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (driver)
|
|
||||||
ret = g_strdup (driver);
|
|
||||||
if (parent)
|
|
||||||
g_object_unref (parent);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
device_file_exists (const char *name)
|
device_file_exists (const char *name)
|
||||||
{
|
{
|
||||||
@@ -273,10 +243,8 @@ is_virtual_port (const gchar *device_name)
|
|||||||
/* Returns TRUE if the support check request was filtered out */
|
/* Returns TRUE if the support check request was filtered out */
|
||||||
static gboolean
|
static gboolean
|
||||||
apply_pre_probing_filters (MMPlugin *self,
|
apply_pre_probing_filters (MMPlugin *self,
|
||||||
|
MMDevice *device,
|
||||||
GUdevDevice *port,
|
GUdevDevice *port,
|
||||||
const gchar *subsys,
|
|
||||||
const gchar *name,
|
|
||||||
const gchar *driver,
|
|
||||||
gboolean *need_vendor_probing,
|
gboolean *need_vendor_probing,
|
||||||
gboolean *need_product_probing)
|
gboolean *need_product_probing)
|
||||||
{
|
{
|
||||||
@@ -286,6 +254,11 @@ apply_pre_probing_filters (MMPlugin *self,
|
|||||||
gboolean product_filtered = FALSE;
|
gboolean product_filtered = FALSE;
|
||||||
gboolean vendor_filtered = FALSE;
|
gboolean vendor_filtered = FALSE;
|
||||||
guint i;
|
guint i;
|
||||||
|
const gchar *subsys;
|
||||||
|
const gchar *name;
|
||||||
|
|
||||||
|
subsys = g_udev_device_get_subsystem (port);
|
||||||
|
name = g_udev_device_get_name (port);
|
||||||
|
|
||||||
*need_vendor_probing = FALSE;
|
*need_vendor_probing = FALSE;
|
||||||
*need_product_probing = FALSE;
|
*need_product_probing = FALSE;
|
||||||
@@ -306,6 +279,17 @@ apply_pre_probing_filters (MMPlugin *self,
|
|||||||
/* The plugin may specify that only some drivers are supported. If that
|
/* The plugin may specify that only some drivers are supported. If that
|
||||||
* is the case, filter by driver */
|
* is the case, filter by driver */
|
||||||
if (priv->drivers) {
|
if (priv->drivers) {
|
||||||
|
const gchar *driver;
|
||||||
|
|
||||||
|
/* Detect any modems accessible through the list of virtual ports */
|
||||||
|
driver = (is_virtual_port (name) ?
|
||||||
|
"virtual" :
|
||||||
|
mm_device_get_driver (device));
|
||||||
|
|
||||||
|
/* If error retrieving driver: unsupported */
|
||||||
|
if (!driver)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
for (i = 0; priv->drivers[i]; i++) {
|
for (i = 0; priv->drivers[i]; i++) {
|
||||||
if (g_str_equal (driver, priv->drivers[i]))
|
if (g_str_equal (driver, priv->drivers[i]))
|
||||||
break;
|
break;
|
||||||
@@ -572,18 +556,14 @@ mm_plugin_supports_port_finish (MMPlugin *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mm_plugin_supports_port (MMPlugin *plugin,
|
mm_plugin_supports_port (MMPlugin *self,
|
||||||
const gchar *subsys,
|
GObject *device_o,
|
||||||
const gchar *name,
|
GUdevDevice *port,
|
||||||
const gchar *physdev_path,
|
|
||||||
MMBaseModem *existing,
|
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMPlugin *self = MM_PLUGIN (plugin);
|
MMDevice *device = MM_DEVICE (device_o);
|
||||||
MMPluginPrivate *priv = MM_PLUGIN_GET_PRIVATE (self);
|
MMPluginPrivate *priv = MM_PLUGIN_GET_PRIVATE (self);
|
||||||
GUdevDevice *port = NULL;
|
|
||||||
gchar *driver = NULL;
|
|
||||||
gchar *key = NULL;
|
gchar *key = NULL;
|
||||||
MMPortProbe *probe;
|
MMPortProbe *probe;
|
||||||
GSimpleAsyncResult *async_result;
|
GSimpleAsyncResult *async_result;
|
||||||
@@ -593,47 +573,18 @@ mm_plugin_supports_port (MMPlugin *plugin,
|
|||||||
MMPortProbeFlag probe_run_flags;
|
MMPortProbeFlag probe_run_flags;
|
||||||
|
|
||||||
/* Setup key */
|
/* Setup key */
|
||||||
key = get_key (subsys, name);
|
key = get_key (g_udev_device_get_subsystem (port),
|
||||||
|
g_udev_device_get_name (port));
|
||||||
|
|
||||||
async_result = g_simple_async_result_new (G_OBJECT (self),
|
async_result = g_simple_async_result_new (G_OBJECT (self),
|
||||||
callback,
|
callback,
|
||||||
user_data,
|
user_data,
|
||||||
mm_plugin_supports_port);
|
mm_plugin_supports_port);
|
||||||
|
|
||||||
/* Get port device */
|
|
||||||
if (!(port = g_udev_client_query_by_subsystem_and_name (priv->client,
|
|
||||||
subsys,
|
|
||||||
name))) {
|
|
||||||
g_simple_async_result_set_error (async_result,
|
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_FAILED,
|
|
||||||
"Couldn't find port for (%s/%s)",
|
|
||||||
subsys,
|
|
||||||
name);
|
|
||||||
g_simple_async_result_complete_in_idle (async_result);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect any modems accessible through the list of virtual ports */
|
|
||||||
if (!(driver = (is_virtual_port (name) ?
|
|
||||||
g_strdup ("virtual") :
|
|
||||||
get_driver_name (port)))) {
|
|
||||||
g_simple_async_result_set_error (async_result,
|
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_FAILED,
|
|
||||||
"Couldn't find driver for (%s/%s)",
|
|
||||||
subsys,
|
|
||||||
name);
|
|
||||||
g_simple_async_result_complete_in_idle (async_result);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply filters before launching the probing */
|
/* Apply filters before launching the probing */
|
||||||
if (apply_pre_probing_filters (self,
|
if (apply_pre_probing_filters (self,
|
||||||
|
device,
|
||||||
port,
|
port,
|
||||||
subsys,
|
|
||||||
name,
|
|
||||||
driver,
|
|
||||||
&need_vendor_probing,
|
&need_vendor_probing,
|
||||||
&need_product_probing)) {
|
&need_product_probing)) {
|
||||||
/* Filtered! */
|
/* Filtered! */
|
||||||
@@ -644,34 +595,30 @@ mm_plugin_supports_port (MMPlugin *plugin,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
mm_dbg ("(%s) checking port support (%s,%s)", priv->name, subsys, name);
|
mm_dbg ("(%s) checking port support (%s,%s)",
|
||||||
|
priv->name,
|
||||||
|
g_udev_device_get_subsystem (port),
|
||||||
|
g_udev_device_get_name (port));
|
||||||
|
|
||||||
/* Need to launch new probing */
|
/* Need to launch new probing */
|
||||||
|
|
||||||
/* Lookup current probes, there shouldn't be any (unless for net devices) */
|
probe = mm_device_get_port_probe (device, port);
|
||||||
probe = g_hash_table_lookup (priv->tasks, key);
|
|
||||||
if (!probe)
|
|
||||||
probe = mm_port_probe_cache_get (port, physdev_path, driver);
|
|
||||||
g_assert (probe);
|
g_assert (probe);
|
||||||
|
|
||||||
/* Before launching any probing, check if the port is a net device (which
|
/* Before launching any probing, check if the port is a net device (which
|
||||||
* cannot be probed).
|
* cannot be probed).
|
||||||
* TODO: With the new defer-until-suggested we probably don't need the modem
|
* TODO: With the new defer-until-suggested we probably don't need the modem
|
||||||
* object being passed down here just for this. */
|
* object being passed down here just for this. */
|
||||||
if (g_str_equal (subsys, "net")) {
|
if (g_str_equal (g_udev_device_get_subsystem (port), "net")) {
|
||||||
/* Keep track of the probe object, which is considered finished */
|
/* Keep track of the probe object, which is considered finished */
|
||||||
if (!g_hash_table_lookup (priv->tasks, key))
|
if (!g_hash_table_lookup (priv->tasks, key))
|
||||||
g_hash_table_insert (priv->tasks,
|
g_hash_table_insert (priv->tasks,
|
||||||
g_strdup (key),
|
g_strdup (key),
|
||||||
g_object_ref (probe));
|
g_object_ref (probe));
|
||||||
|
|
||||||
/* If we already have a existing modem, then mark it as supported.
|
|
||||||
* Otherwise, just defer a bit */
|
|
||||||
g_simple_async_result_set_op_res_gpointer (
|
g_simple_async_result_set_op_res_gpointer (
|
||||||
async_result,
|
async_result,
|
||||||
GUINT_TO_POINTER ((existing ?
|
GUINT_TO_POINTER (MM_PLUGIN_SUPPORTS_PORT_DEFER_UNTIL_SUGGESTED),
|
||||||
MM_PLUGIN_SUPPORTS_PORT_SUPPORTED :
|
|
||||||
MM_PLUGIN_SUPPORTS_PORT_DEFER_UNTIL_SUGGESTED)),
|
|
||||||
NULL);
|
NULL);
|
||||||
g_simple_async_result_complete_in_idle (async_result);
|
g_simple_async_result_complete_in_idle (async_result);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -696,11 +643,12 @@ mm_plugin_supports_port (MMPlugin *plugin,
|
|||||||
* expected, check if we alredy got the single AT port. And if so, we know this
|
* expected, check if we alredy got the single AT port. And if so, we know this
|
||||||
* port being probed won't be AT. */
|
* port being probed won't be AT. */
|
||||||
if (priv->single_at &&
|
if (priv->single_at &&
|
||||||
existing &&
|
mm_port_probe_list_has_at_port (mm_device_peek_port_probe_list (device))) {
|
||||||
mm_base_modem_has_at_port (existing)) {
|
|
||||||
mm_dbg ("(%s) not setting up AT probing tasks for (%s,%s): "
|
mm_dbg ("(%s) not setting up AT probing tasks for (%s,%s): "
|
||||||
"modem already has the expected single AT port",
|
"modem already has the expected single AT port",
|
||||||
priv->name, subsys, name);
|
priv->name,
|
||||||
|
g_udev_device_get_subsystem (port),
|
||||||
|
g_udev_device_get_name (port));
|
||||||
|
|
||||||
/* Assuming it won't be an AT port. We still run the probe anyway, in
|
/* Assuming it won't be an AT port. We still run the probe anyway, in
|
||||||
* case we need to check for other port types (e.g. QCDM) */
|
* case we need to check for other port types (e.g. QCDM) */
|
||||||
@@ -714,7 +662,10 @@ mm_plugin_supports_port (MMPlugin *plugin,
|
|||||||
ctx->flags = probe_run_flags;
|
ctx->flags = probe_run_flags;
|
||||||
|
|
||||||
/* Launch the probe */
|
/* Launch the probe */
|
||||||
mm_dbg ("(%s) launching probe for (%s,%s)", priv->name, subsys, name);
|
mm_dbg ("(%s) launching probe for (%s,%s)",
|
||||||
|
priv->name,
|
||||||
|
g_udev_device_get_subsystem (port),
|
||||||
|
g_udev_device_get_name (port));
|
||||||
mm_port_probe_run (probe,
|
mm_port_probe_run (probe,
|
||||||
ctx->flags,
|
ctx->flags,
|
||||||
priv->send_delay,
|
priv->send_delay,
|
||||||
@@ -729,10 +680,7 @@ mm_plugin_supports_port (MMPlugin *plugin,
|
|||||||
probe);
|
probe);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (port)
|
|
||||||
g_object_unref (port);
|
|
||||||
g_free (key);
|
g_free (key);
|
||||||
g_free (driver);
|
|
||||||
g_object_unref (async_result);
|
g_object_unref (async_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -760,33 +708,36 @@ mm_plugin_supports_port_cancel (MMPlugin *plugin,
|
|||||||
|
|
||||||
MMBaseModem *
|
MMBaseModem *
|
||||||
mm_plugin_create_modem (MMPlugin *self,
|
mm_plugin_create_modem (MMPlugin *self,
|
||||||
GList *port_probes,
|
GObject *device_o,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
MMBaseModem *modem = NULL;
|
MMDevice *device = MM_DEVICE (device_o);
|
||||||
MMPluginPrivate *priv = MM_PLUGIN_GET_PRIVATE (self);
|
MMPluginPrivate *priv = MM_PLUGIN_GET_PRIVATE (self);
|
||||||
GList *l;
|
MMBaseModem *modem = NULL;
|
||||||
const gchar *name, *subsys, *sysfs_path, *driver;
|
const gchar *name, *subsys;
|
||||||
guint16 vendor = 0, product = 0;
|
guint16 vendor = 0, product = 0;
|
||||||
|
GList *port_probes, *l;
|
||||||
|
|
||||||
/* Get info from the first probe in the list */
|
/* Get info from the first probe in the list */
|
||||||
subsys = mm_port_probe_get_port_subsys (probes->data);
|
port_probes = mm_device_peek_port_probe_list (device);
|
||||||
name = mm_port_probe_get_port_name (probes->data);
|
subsys = mm_port_probe_get_port_subsys (port_probes->data);
|
||||||
sysfs_path = mm_port_probe_get_port_physdev (probes->data);
|
name = mm_port_probe_get_port_name (port_probes->data);
|
||||||
driver = mm_port_probe_get_port_driver (probes->data);
|
|
||||||
|
|
||||||
/* Vendor and Product IDs are really optional, we'll just warn if they
|
/* Vendor and Product IDs are really optional, we'll just warn if they
|
||||||
* cannot get loaded */
|
* cannot get loaded.
|
||||||
|
*
|
||||||
|
* TODO: load them in MMDevice once
|
||||||
|
**/
|
||||||
if (!get_device_ids (MM_PLUGIN (self), subsys, name, &vendor, &product))
|
if (!get_device_ids (MM_PLUGIN (self), subsys, name, &vendor, &product))
|
||||||
mm_warn ("Could not get modem vendor/product ID");
|
mm_warn ("Could not get modem vendor/product ID");
|
||||||
|
|
||||||
/* Let the plugin create the modem from the port probe results */
|
/* Let the plugin create the modem from the port probe results */
|
||||||
modem = MM_PLUGIN_GET_CLASS (self)->create_modem (MM_PLUGIN (self),
|
modem = MM_PLUGIN_GET_CLASS (self)->create_modem (MM_PLUGIN (self),
|
||||||
sysfs_path,
|
mm_device_get_path (device),
|
||||||
driver,
|
mm_device_get_driver (device),
|
||||||
vendor,
|
vendor,
|
||||||
product,
|
product,
|
||||||
probes,
|
port_probes,
|
||||||
error);
|
error);
|
||||||
if (modem) {
|
if (modem) {
|
||||||
/* Grab each port */
|
/* Grab each port */
|
||||||
|
@@ -97,10 +97,8 @@ const char *mm_plugin_get_name (MMPlugin *plugin);
|
|||||||
gboolean mm_plugin_get_sort_last (const MMPlugin *plugin);
|
gboolean mm_plugin_get_sort_last (const MMPlugin *plugin);
|
||||||
|
|
||||||
void mm_plugin_supports_port (MMPlugin *plugin,
|
void mm_plugin_supports_port (MMPlugin *plugin,
|
||||||
const gchar *subsys,
|
GObject *device,
|
||||||
const gchar *name,
|
GUdevDevice *port,
|
||||||
const gchar *physdev_path,
|
|
||||||
MMBaseModem *existing,
|
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
MMPluginSupportsResult mm_plugin_supports_port_finish (MMPlugin *plugin,
|
MMPluginSupportsResult mm_plugin_supports_port_finish (MMPlugin *plugin,
|
||||||
@@ -111,7 +109,7 @@ void mm_plugin_supports_port_cancel (MMPlugin *plugin,
|
|||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
MMBaseModem *mm_plugin_create_modem (MMPlugin *plugin,
|
MMBaseModem *mm_plugin_create_modem (MMPlugin *plugin,
|
||||||
GList *port_probes,
|
GObject *device,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
#endif /* MM_PLUGIN_H */
|
#endif /* MM_PLUGIN_H */
|
||||||
|
Reference in New Issue
Block a user