From df08f6a43ff8acc617f7330d25450a3a62809ffb Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 30 Mar 2010 15:03:35 -0700 Subject: core: find the existing modem for a port in the manager --- src/mm-manager.c | 10 +++++++++- src/mm-plugin-base.c | 50 ++++---------------------------------------------- src/mm-plugin-base.h | 3 --- src/mm-plugin.c | 5 ++++- src/mm-plugin.h | 4 ++++ 5 files changed, 21 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/mm-manager.c b/src/mm-manager.c index 5a85f02a..bb1137e0 100644 --- a/src/mm-manager.c +++ b/src/mm-manager.c @@ -383,11 +383,15 @@ try_supports_port (MMManager *manager, SupportsInfo *info) { MMPluginSupportsResult result; + MMModem *existing; + + existing = find_modem_for_device (manager, info->physdev_path); result = mm_plugin_supports_port (plugin, info->subsys, info->name, info->physdev_path, + existing, supports_callback, info); @@ -426,8 +430,12 @@ do_grab_port (gpointer user_data) /* No more plugins to try */ if (info->best_plugin) { + MMModem *existing; + + existing = g_hash_table_lookup (priv->modems, info->physdev_path); + /* Create the modem */ - modem = mm_plugin_grab_port (info->best_plugin, info->subsys, info->name, &error); + modem = mm_plugin_grab_port (info->best_plugin, info->subsys, info->name, existing, &error); if (modem) { guint32 modem_type = MM_MODEM_TYPE_UNKNOWN; const char *type_name = "UNKNOWN"; diff --git a/src/mm-plugin-base.c b/src/mm-plugin-base.c index a8784be4..5bad7d99 100644 --- a/src/mm-plugin-base.c +++ b/src/mm-plugin-base.c @@ -51,8 +51,6 @@ static GHashTable *cached_caps = NULL; typedef struct { char *name; GUdevClient *client; - - GHashTable *modems; GHashTable *tasks; } MMPluginBasePrivate; @@ -873,20 +871,6 @@ mm_plugin_base_get_cached_port_capabilities (MMPluginBase *self, static void modem_destroyed (gpointer data, GObject *modem) { - MMPluginBase *self = MM_PLUGIN_BASE (data); - MMPluginBasePrivate *priv = MM_PLUGIN_BASE_GET_PRIVATE (self); - GHashTableIter iter; - gpointer key, value; - - /* Remove it from the modems info */ - g_hash_table_iter_init (&iter, priv->modems); - while (g_hash_table_iter_next (&iter, &key, &value)) { - if (value == modem) { - g_hash_table_iter_remove (&iter); - break; - } - } - /* Since we don't track port cached capabilities on a per-modem basis, * we just have to live with blowing away the cached capabilities whenever * a modem gets removed. Could do better here by storing a structure @@ -897,21 +881,6 @@ modem_destroyed (gpointer data, GObject *modem) g_hash_table_remove_all (cached_caps); } -MMModem * -mm_plugin_base_find_modem (MMPluginBase *self, - const char *master_device) -{ - MMPluginBasePrivate *priv; - - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (MM_IS_PLUGIN_BASE (self), NULL); - g_return_val_if_fail (master_device != NULL, NULL); - g_return_val_if_fail (strlen (master_device) > 0, NULL); - - priv = MM_PLUGIN_BASE_GET_PRIVATE (self); - return g_hash_table_lookup (priv->modems, master_device); -} - /* From hostap, Copyright (c) 2002-2005, Jouni Malinen */ static int hex2num (char c) @@ -1042,6 +1011,7 @@ supports_port (MMPlugin *plugin, const char *subsys, const char *name, const char *physdev_path, + MMModem *existing, MMSupportsPortResultFunc callback, gpointer callback_data) { @@ -1051,7 +1021,6 @@ supports_port (MMPlugin *plugin, char *driver = NULL, *key = NULL; MMPluginBaseSupportsTask *task; MMPluginSupportsResult result = MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - MMModem *existing; key = get_key (subsys, name); task = g_hash_table_lookup (priv->tasks, key); @@ -1072,9 +1041,6 @@ supports_port (MMPlugin *plugin, g_assert (task); g_hash_table_insert (priv->tasks, g_strdup (key), g_object_ref (task)); - /* Help the plugin out a bit by finding an existing modem for this port */ - existing = g_hash_table_lookup (priv->modems, physdev_path); - result = MM_PLUGIN_BASE_GET_CLASS (self)->supports_port (self, existing, task); if (result != MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS) { /* If the plugin doesn't support the port at all, the supports task is @@ -1118,14 +1084,14 @@ static MMModem * grab_port (MMPlugin *plugin, const char *subsys, const char *name, + MMModem *existing, GError **error) { MMPluginBase *self = MM_PLUGIN_BASE (plugin); MMPluginBasePrivate *priv = MM_PLUGIN_BASE_GET_PRIVATE (self); MMPluginBaseSupportsTask *task; + MMModem *modem = NULL; char *key; - MMModem *existing = NULL, *modem = NULL; - const char *physdev_path; key = get_key (subsys, name); task = g_hash_table_lookup (priv->tasks, key); @@ -1134,16 +1100,10 @@ grab_port (MMPlugin *plugin, g_return_val_if_fail (task != NULL, FALSE); } - /* Help the plugin out a bit by finding an existing modem for this port */ - physdev_path = mm_plugin_base_supports_task_get_physdev_path (task); - existing = g_hash_table_lookup (priv->modems, physdev_path); - /* Let the modem grab the port */ modem = MM_PLUGIN_BASE_GET_CLASS (self)->grab_port (self, existing, task, error); - if (modem && !existing) { - g_hash_table_insert (priv->modems, g_strdup (physdev_path), modem); + if (modem && !existing) g_object_weak_ref (G_OBJECT (modem), modem_destroyed, self); - } g_hash_table_remove (priv->tasks, key); g_free (key); @@ -1173,7 +1133,6 @@ mm_plugin_base_init (MMPluginBase *self) priv->client = g_udev_client_new (subsys); - priv->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); priv->tasks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); } @@ -1220,7 +1179,6 @@ finalize (GObject *object) g_object_unref (priv->client); - g_hash_table_destroy (priv->modems); g_hash_table_destroy (priv->tasks); G_OBJECT_CLASS (mm_plugin_base_parent_class)->finalize (object); diff --git a/src/mm-plugin-base.h b/src/mm-plugin-base.h index fd3e7368..a32d53bf 100644 --- a/src/mm-plugin-base.h +++ b/src/mm-plugin-base.h @@ -122,9 +122,6 @@ struct _MMPluginBaseClass { GType mm_plugin_base_get_type (void); -MMModem *mm_plugin_base_find_modem (MMPluginBase *self, - const char *master_device); - gboolean mm_plugin_base_get_device_ids (MMPluginBase *self, const char *subsys, const char *name, diff --git a/src/mm-plugin.c b/src/mm-plugin.c index cc58e621..7e5c582b 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -29,6 +29,7 @@ mm_plugin_supports_port (MMPlugin *plugin, const char *subsys, const char *name, const char *physdev_path, + MMModem *existing, MMSupportsPortResultFunc callback, gpointer user_data) { @@ -42,6 +43,7 @@ mm_plugin_supports_port (MMPlugin *plugin, subsys, name, physdev_path, + existing, callback, user_data); } @@ -62,13 +64,14 @@ MMModem * mm_plugin_grab_port (MMPlugin *plugin, const char *subsys, const char *name, + MMModem *existing, GError **error) { g_return_val_if_fail (MM_IS_PLUGIN (plugin), FALSE); g_return_val_if_fail (subsys != NULL, FALSE); g_return_val_if_fail (name != NULL, FALSE); - return MM_PLUGIN_GET_INTERFACE (plugin)->grab_port (plugin, subsys, name, error); + return MM_PLUGIN_GET_INTERFACE (plugin)->grab_port (plugin, subsys, name, existing, error); } /*****************************************************************************/ diff --git a/src/mm-plugin.h b/src/mm-plugin.h index 40419d41..4f1dfc09 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -71,6 +71,7 @@ struct _MMPlugin { const char *subsys, const char *name, const char *physdev_path, + MMModem *existing, MMSupportsPortResultFunc callback, gpointer user_data); @@ -95,6 +96,7 @@ struct _MMPlugin { MMModem * (*grab_port) (MMPlugin *self, const char *subsys, const char *name, + MMModem *existing, GError **error); }; @@ -106,6 +108,7 @@ MMPluginSupportsResult mm_plugin_supports_port (MMPlugin *plugin, const char *subsys, const char *name, const char *physdev_path, + MMModem *existing, MMSupportsPortResultFunc callback, gpointer user_data); @@ -116,6 +119,7 @@ void mm_plugin_cancel_supports_port (MMPlugin *plugin, MMModem *mm_plugin_grab_port (MMPlugin *plugin, const char *subsys, const char *name, + MMModem *existing, GError **error); #endif /* MM_PLUGIN_H */ -- cgit v1.2.3-70-g09d2