From 8e4f6a5a556bf63871eaf7aceaeb40d73d7e6173 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 8 Nov 2012 09:06:44 +0100 Subject: [PATCH] modem-manager,broadband: use the primary port as unique ID Instead of a 'modem#' identifier, use the primary port of the modem as unique identifier. The modem UID will be set afterwards as the Device Iface, which is then used by libnm-glib to gather vendor/product string from the udev device associated with the Device Iface; so it really needs to be a real port. --- src/modem-manager/nm-modem-broadband.c | 27 +++++++------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/modem-manager/nm-modem-broadband.c b/src/modem-manager/nm-modem-broadband.c index cb141e3392..d4d89d6122 100644 --- a/src/modem-manager/nm-modem-broadband.c +++ b/src/modem-manager/nm-modem-broadband.c @@ -875,45 +875,32 @@ NMModem * nm_modem_broadband_new (GObject *object) { MMObject *modem_object; - NMModem *self; MMModem *modem_iface; - gchar *uid; - const gchar *path; - const gchar *aux; g_return_val_if_fail (MM_IS_OBJECT (object), NULL); modem_object = MM_OBJECT (object); - /* Ensure we have the 'Modem' interface at least */ + /* Ensure we have the 'Modem' interface and the primary port at least */ modem_iface = mm_object_peek_modem (modem_object); g_return_val_if_fail (!!modem_iface, NULL); - - /* Uid is just a unique string we build for logs and such */ - path = mm_object_get_path (modem_object); - g_assert (g_str_has_prefix (path, MM_DBUS_MODEM_PREFIX)); - aux = &path[strlen (MM_DBUS_MODEM_PREFIX)]; - while (*aux == '/') - aux++; - uid = g_strdup_printf ("modem%s", aux); + g_return_val_if_fail (!!mm_modem_get_primary_port (modem_iface), NULL); /* If the modem is in 'FAILED' state we cannot do anything with it. * This happens when a severe error happened when trying to initialize it, * like missing SIM. */ if (mm_modem_get_state (modem_iface) == MM_MODEM_STATE_FAILED) { - nm_log_warn (LOGD_MB, "(%s): unusable modem detected", uid); - g_free (uid); + nm_log_warn (LOGD_MB, "(%s): unusable modem detected", + mm_modem_get_primary_port (modem_iface)); return NULL; } - self = (NMModem *) g_object_new (NM_TYPE_MODEM_BROADBAND, - NM_MODEM_PATH, path, - NM_MODEM_UID, uid, + return (NMModem *) g_object_new (NM_TYPE_MODEM_BROADBAND, + NM_MODEM_PATH, mm_object_get_path (modem_object), + NM_MODEM_UID, mm_modem_get_primary_port (modem_iface), NM_MODEM_CONTROL_PORT, mm_modem_get_primary_port (modem_iface), NM_MODEM_DATA_PORT, NULL, /* We don't know it until bearer created */ NM_MODEM_BROADBAND_MODEM, modem_object, NULL); - g_free (uid); - return self; } static void