aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-02-12 12:28:22 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-25 14:13:03 +0100
commit381e2f382ba09005648669859288e2a725fe6af2 (patch)
tree4ed4d492ebedf132eeb2e0b997e3b06572999796
parentb8e076f9c47669d58179cb67a829966b867c6fe6 (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.
-rw-r--r--plugins/huawei/mm-broadband-modem-huawei.c6
-rw-r--r--plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c3
-rw-r--r--src/mm-base-modem.c52
-rw-r--r--src/mm-base-modem.h11
-rw-r--r--src/mm-broadband-modem-mbim.c6
-rw-r--r--src/mm-broadband-modem-qmi.c6
6 files changed, 53 insertions, 31 deletions
diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c
index 250784be..2c341d3e 100644
--- a/plugins/huawei/mm-broadband-modem-huawei.c
+++ b/plugins/huawei/mm-broadband-modem-huawei.c
@@ -177,8 +177,7 @@ mm_broadband_modem_huawei_get_at_port_list (MMBroadbandModemHuawei *self)
/* Additional cdc-wdm ports used for dialing */
cdc_wdm_at_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self),
MM_PORT_SUBSYS_USBMISC,
- MM_PORT_TYPE_AT,
- NULL);
+ MM_PORT_TYPE_AT);
return g_list_concat (out, cdc_wdm_at_ports);
}
@@ -2201,8 +2200,7 @@ peek_port_at_for_data (MMBroadbandModemHuawei *self,
/* Find the CDC-WDM port on the same USB interface as the given net port */
cdc_wdm_at_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self),
MM_PORT_SUBSYS_USBMISC,
- MM_PORT_TYPE_AT,
- NULL);
+ MM_PORT_TYPE_AT);
for (l = cdc_wdm_at_ports; l && !found; l = g_list_next (l)) {
const gchar *wdm_port_parent_path;
diff --git a/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c
index 58a6e5e3..b49fec40 100644
--- a/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c
+++ b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c
@@ -81,8 +81,7 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self,
/* Find one QMI port, we don't care which one */
rpmsg_qmi_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self),
MM_PORT_SUBSYS_RPMSG,
- MM_PORT_TYPE_QMI,
- NULL);
+ MM_PORT_TYPE_QMI);
if (!rpmsg_qmi_ports) {
g_set_error (error,
MM_CORE_ERROR,
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;