diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2021-02-12 12:28:22 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2021-02-25 14:13:03 +0100 |
commit | 381e2f382ba09005648669859288e2a725fe6af2 (patch) | |
tree | 4ed4d492ebedf132eeb2e0b997e3b06572999796 /src | |
parent | b8e076f9c47669d58179cb67a829966b867c6fe6 (diff) |
base-modem: separate method to lookup exact port by name
There's no point in returning a list of all ports with a given name,
just provide a lookup method that returns the single port with the
given name.
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-base-modem.c | 52 | ||||
-rw-r--r-- | src/mm-base-modem.h | 11 | ||||
-rw-r--r-- | src/mm-broadband-modem-mbim.c | 6 | ||||
-rw-r--r-- | src/mm-broadband-modem-qmi.c | 6 |
4 files changed, 50 insertions, 25 deletions
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index e5030dcb..72b9b849 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -822,21 +822,18 @@ port_cmp (MMPort *a, } GList * -mm_base_modem_find_ports (MMBaseModem *self, - MMPortSubsys subsys, - MMPortType type, - const gchar *name) +mm_base_modem_find_ports (MMBaseModem *self, + MMPortSubsys subsys, + MMPortType type) { - GList *out = NULL; - GHashTableIter iter; - gpointer value; - gpointer key; + GList *out = NULL; + GHashTableIter iter; + gpointer value; + gpointer key; if (!self->priv->ports) return NULL; - /* We'll iterate the ht of ports, looking for any port which is matches - * the compare function */ g_hash_table_iter_init (&iter, self->priv->ports); while (g_hash_table_iter_next (&iter, &key, &value)) { MMPort *port = MM_PORT (value); @@ -847,15 +844,44 @@ mm_base_modem_find_ports (MMBaseModem *self, if (type != MM_PORT_TYPE_UNKNOWN && mm_port_get_port_type (port) != type) continue; - if (name != NULL && !g_str_equal (mm_port_get_device (port), name)) - continue; - out = g_list_append (out, g_object_ref (port)); } return g_list_sort (out, (GCompareFunc) port_cmp); } +MMPort * +mm_base_modem_peek_port (MMBaseModem *self, + const gchar *name) +{ + GHashTableIter iter; + gpointer value; + gpointer key; + + if (!self->priv->ports) + return NULL; + + g_hash_table_iter_init (&iter, self->priv->ports); + while (g_hash_table_iter_next (&iter, &key, &value)) { + MMPort *port = MM_PORT (value); + + if (g_str_equal (mm_port_get_device (port), name)) + return port; + } + + return NULL; +} + +MMPort * +mm_base_modem_get_port (MMBaseModem *self, + const gchar *name) +{ + MMPort *port; + + port = mm_base_modem_peek_port (self, name); + return (port ? g_object_ref (port) : NULL); +} + static void initialize_ready (MMBaseModem *self, GAsyncResult *res) diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h index 24634814..11c3993c 100644 --- a/src/mm-base-modem.h +++ b/src/mm-base-modem.h @@ -142,10 +142,13 @@ GList *mm_base_modem_get_data_ports (MMBaseModem *self); MMModemPortInfo *mm_base_modem_get_port_infos (MMBaseModem *self, guint *n_port_infos); -GList *mm_base_modem_find_ports (MMBaseModem *self, - MMPortSubsys subsys, - MMPortType type, - const gchar *name); +GList *mm_base_modem_find_ports (MMBaseModem *self, + MMPortSubsys subsys, + MMPortType type); +MMPort *mm_base_modem_peek_port (MMBaseModem *self, + const gchar *name); +MMPort *mm_base_modem_get_port (MMBaseModem *self, + const gchar *name); void mm_base_modem_set_hotplugged (MMBaseModem *self, gboolean hotplugged); diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index df9fc15a..4ee5b226 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -237,8 +237,7 @@ mm_broadband_modem_mbim_peek_port_mbim (MMBroadbandModemMbim *self) mbim_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self), MM_PORT_SUBSYS_UNKNOWN, - MM_PORT_TYPE_MBIM, - NULL); + MM_PORT_TYPE_MBIM); /* First MBIM port in the list is the primary one always */ if (mbim_ports) @@ -302,8 +301,7 @@ peek_port_mbim_for_data (MMBroadbandModemMbim *self, /* Find the CDC-WDM port on the same USB interface as the given net port */ cdc_wdm_mbim_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self), MM_PORT_SUBSYS_USBMISC, - MM_PORT_TYPE_MBIM, - NULL); + MM_PORT_TYPE_MBIM); for (l = cdc_wdm_mbim_ports; l && !found; l = g_list_next (l)) { const gchar *wdm_port_parent_path; diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index e89aa111..d2f85b0e 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -202,8 +202,7 @@ mm_broadband_modem_qmi_peek_port_qmi (MMBroadbandModemQmi *self) qmi_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self), MM_PORT_SUBSYS_UNKNOWN, - MM_PORT_TYPE_QMI, - NULL); + MM_PORT_TYPE_QMI); /* First QMI port in the list is the primary one always */ if (qmi_ports) @@ -269,8 +268,7 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self, /* Find the CDC-WDM port on the same USB interface as the given net port */ cdc_wdm_qmi_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self), MM_PORT_SUBSYS_USBMISC, - MM_PORT_TYPE_QMI, - NULL); + MM_PORT_TYPE_QMI); for (l = cdc_wdm_qmi_ports; l && !found; l = g_list_next (l)) { const gchar *wdm_port_parent_path; |