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.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
+39
-13
@@ -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)
|
||||
|
||||
+7
-4
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user