aboutsummaryrefslogtreecommitdiff
path: root/plugins/mm-plugin-hso.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mm-plugin-hso.c')
-rw-r--r--plugins/mm-plugin-hso.c240
1 files changed, 69 insertions, 171 deletions
diff --git a/plugins/mm-plugin-hso.c b/plugins/mm-plugin-hso.c
index 9481bbf4..edcabab2 100644
--- a/plugins/mm-plugin-hso.c
+++ b/plugins/mm-plugin-hso.c
@@ -23,165 +23,89 @@
#include "mm-plugin-hso.h"
#include "mm-modem-hso.h"
-static void plugin_init (MMPlugin *plugin_class);
-
-G_DEFINE_TYPE_EXTENDED (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN_BASE,
- 0, G_IMPLEMENT_INTERFACE (MM_TYPE_PLUGIN, plugin_init))
+G_DEFINE_TYPE (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN_BASE)
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
-#define MM_PLUGIN_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_HSO, MMPluginHsoPrivate))
-
-typedef struct {
- GUdevClient *client;
-} MMPluginHsoPrivate;
-
G_MODULE_EXPORT MMPlugin *
mm_plugin_create (void)
{
- return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_HSO, NULL));
+ return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_HSO,
+ MM_PLUGIN_BASE_NAME, "Option High-Speed",
+ NULL));
}
/*****************************************************************************/
-static char *
-get_driver_name (GUdevDevice *device)
+static guint32
+get_level_for_capabilities (guint32 capabilities)
{
- GUdevDevice *parent = NULL;
- const char *driver;
- char *ret;
-
- 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);
- }
-
- if (driver)
- ret = g_strdup (driver);
- if (parent)
- g_object_unref (parent);
-
- return ret;
+ if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM)
+ return 10;
+ return 0;
}
-static GUdevDevice *
-find_physical_device (GUdevDevice *child)
+static void
+probe_result (MMPluginBase *base,
+ MMPluginBaseSupportsTask *task,
+ guint32 capabilities,
+ gpointer user_data)
{
- GUdevDevice *iter, *old = NULL;
- const char *type;
-
- g_return_val_if_fail (child != NULL, NULL);
-
- /* Walk the parents to find the first 'usb_device' for this device. */
- iter = g_object_ref (child);
- while (iter) {
- type = g_udev_device_get_devtype (iter);
- if (type && !strcmp (type, "usb_device"))
- return iter;
-
- old = iter;
- iter = g_udev_device_get_parent (old);
- g_object_unref (old);
- }
- g_object_unref (child);
-
- return NULL;
+ mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities));
}
-static GUdevDevice *
-get_device (GUdevClient *client,
- const char *subsys,
- const char *name,
- GUdevDevice **physdev,
- char **driver,
- GError **error)
+static MMPluginSupportsResult
+supports_port (MMPluginBase *base,
+ MMModem *existing,
+ MMPluginBaseSupportsTask *task)
{
- GUdevDevice *device = NULL;
+ GUdevDevice *port;
+ guint32 cached = 0, level;
+ const char *driver;
- if (strcmp (subsys, "tty") && strcmp (subsys, "net")) {
- g_set_error (error, 0, 0, "Unsupported subsystem.");
- return NULL;
- }
+ port = mm_plugin_base_supports_task_get_port (task);
- device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
- if (!device) {
- g_set_error (error, 0, 0, "Coud not get port's udev device.");
- return NULL;
- }
+ driver = mm_plugin_base_supports_task_get_driver (task);
+ if (!driver || strcmp (driver, "hso"))
+ return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
- *driver = get_driver_name (device);
- if (!*driver || strcmp (*driver, "hso")) {
- g_set_error (error, 0, 0, "Unsupported driver (not 'hso').");
- g_object_unref (device);
- device = NULL;
- goto out;
+ if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) {
+ level = get_level_for_capabilities (cached);
+ if (level) {
+ mm_plugin_base_supports_task_complete (task, level);
+ return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
+ }
+ return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
}
- *physdev = find_physical_device (device);
- if (!*physdev) {
- g_set_error (error, 0, 0, "Could not get port's physical udev device.");
- g_object_unref (device);
- device = NULL;
- }
+ /* Otherwise kick off a probe */
+ if (mm_plugin_base_probe_port (base, task, NULL))
+ return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
-out:
- return device;
-}
-
-static guint32
-supports_port (MMPlugin *plugin,
- const char *subsys,
- const char *name)
-{
- MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
- GUdevDevice *device, *physdev = NULL;
- guint32 level = 0;
- char *driver = NULL;
-
- g_return_val_if_fail (plugin != NULL, 0);
- g_return_val_if_fail (MM_IS_PLUGIN (plugin), 0);
- g_return_val_if_fail (subsys != NULL, 0);
- g_return_val_if_fail (name != NULL, 0);
-
- device = get_device (priv->client, subsys, name, &physdev, &driver, NULL);
- if (device)
- level = 10;
-
- g_free (driver);
- if (physdev)
- g_object_unref (physdev);
- if (device)
- g_object_unref (device);
- return level;
+ return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
}
static MMModem *
-grab_port (MMPlugin *plugin,
- const char *subsys,
- const char *name,
+grab_port (MMPluginBase *base,
+ MMModem *existing,
+ MMPluginBaseSupportsTask *task,
GError **error)
{
- MMPluginHso *self = MM_PLUGIN_HSO (plugin);
- MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
- GUdevDevice *device = NULL, *physdev = NULL;
- const char *sysfs_path = NULL;
- char *driver = NULL, *devfile = NULL;
+ GUdevDevice *port = NULL, *physdev = NULL;
MMModem *modem = NULL;
+ const char *name, *subsys, *sysfs_path;
+ char *devfile;
+ guint32 caps;
- g_return_val_if_fail (subsys != NULL, NULL);
- g_return_val_if_fail (name != NULL, NULL);
+ port = mm_plugin_base_supports_task_get_port (task);
+ g_assert (port);
- device = get_device (priv->client, subsys, name, &physdev, &driver, error);
- if (!device) {
- g_set_error (error, 0, 0, "Could not get port's udev device.");
- return NULL;
- }
+ subsys = g_udev_device_get_subsystem (port);
+ name = g_udev_device_get_name (port);
- devfile = g_strdup (g_udev_device_get_device_file (device));
+ devfile = g_strdup (g_udev_device_get_device_file (port));
if (!devfile) {
if (!strcmp (subsys, "net")) {
/* Apparently 'hso' doesn't set up the right links for the netdevice,
@@ -200,80 +124,54 @@ grab_port (MMPlugin *plugin,
}
}
+ physdev = mm_plugin_base_supports_task_get_physdev (task);
+ g_assert (physdev);
sysfs_path = g_udev_device_get_sysfs_path (physdev);
if (!sysfs_path) {
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
goto out;
}
- modem = mm_plugin_base_find_modem (MM_PLUGIN_BASE (self), sysfs_path);
- if (!modem) {
- modem = mm_modem_hso_new (sysfs_path,
- driver,
- mm_plugin_get_name (plugin));
+ caps = mm_plugin_base_supports_task_get_probed_capabilities (task);
+ if (!existing) {
+ if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) {
+ modem = mm_modem_hso_new (sysfs_path,
+ mm_plugin_base_supports_task_get_driver (task),
+ mm_plugin_get_name (MM_PLUGIN (base)));
+ }
if (modem) {
- if (!mm_modem_grab_port (modem, subsys, name, error)) {
+ if (!mm_modem_grab_port (modem, subsys, name, NULL, error)) {
g_object_unref (modem);
- modem = NULL;
+ return NULL;
}
}
-
- if (modem)
- mm_plugin_base_add_modem (MM_PLUGIN_BASE (self), modem);
} else {
- if (!mm_modem_grab_port (modem, subsys, name, error))
- modem = NULL;
+ if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) {
+ modem = existing;
+ if (!mm_modem_grab_port (modem, subsys, name, NULL, error))
+ return NULL;
+ }
}
out:
g_free (devfile);
- g_free (driver);
- g_object_unref (device);
- g_object_unref (physdev);
return modem;
}
-static const char *
-get_name (MMPlugin *plugin)
-{
- return "HSO";
-}
-
/*****************************************************************************/
static void
-plugin_init (MMPlugin *plugin_class)
-{
- /* interface implementation */
- plugin_class->get_name = get_name;
- plugin_class->supports_port = supports_port;
- plugin_class->grab_port = grab_port;
-}
-
-static void
mm_plugin_hso_init (MMPluginHso *self)
{
- MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (self);
- const char *subsys[] = { "tty", "net", NULL };
-
- priv->client = g_udev_client_new (subsys);
-}
-
-static void
-dispose (GObject *object)
-{
- MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (object);
-
- g_object_unref (priv->client);
+ g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
}
static void
mm_plugin_hso_class_init (MMPluginHsoClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (object_class, sizeof (MMPluginHsoPrivate));
+ MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
- object_class->dispose = dispose;
+ pb_class->supports_port = supports_port;
+ pb_class->grab_port = grab_port;
}