aboutsummaryrefslogtreecommitdiff
path: root/src/mm-base-modem.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-10-25 22:10:28 +0100
committerAleksander Morgado <aleksander@aleksander.es>2020-10-30 09:30:46 +0100
commitc385031941c9cd1ce07ae2d5b37ded26e4838dae (patch)
tree839d336650a1fed9329d2b515f288b38926f055b /src/mm-base-modem.c
parenta174edb74dc81f63932c212483bc9546de12ff95 (diff)
base-modem: sort port info array by port name
So that the list of ports shown in the Ports DBus property is also alphabetically sorted by port name, instead of having a mess like this: ----------------------------- System | device: qcom-soc | drivers: bam-dmux | plugin: qcom-soc | primary port: rpmsg0 | ports: rmnet5 (net), rmnet_usb0 (unknown), rmnet4 (net), | rpmsg1 (at), rmnet3 (net), rpmsg0 (qmi), rmnet2 (net), rmnet1 (net), | rmnet7 (net), rmnet0 (net), rmnet6 (net)
Diffstat (limited to 'src/mm-base-modem.c')
-rw-r--r--src/mm-base-modem.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index b151e820..d7c0e477 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -928,56 +928,66 @@ mm_base_modem_has_at_port (MMBaseModem *self)
return FALSE;
}
+static gint
+port_info_cmp (const MMModemPortInfo *a,
+ const MMModemPortInfo *b)
+{
+ /* default to alphabetical sorting on the port name */
+ return g_strcmp0 (a->name, b->name);
+}
+
MMModemPortInfo *
mm_base_modem_get_port_infos (MMBaseModem *self,
- guint *n_port_infos)
+ guint *n_port_infos)
{
- GHashTableIter iter;
- MMModemPortInfo *port_infos;
- MMPort *port;
- guint i;
+ GHashTableIter iter;
+ GArray *port_infos;
+ MMPort *port;
*n_port_infos = g_hash_table_size (self->priv->ports);
- port_infos = g_new (MMModemPortInfo, *n_port_infos);
+ port_infos = g_array_sized_new (FALSE, FALSE, sizeof (MMModemPortInfo), *n_port_infos);
g_hash_table_iter_init (&iter, self->priv->ports);
- i = 0;
while (g_hash_table_iter_next (&iter, NULL, (gpointer)&port)) {
- port_infos[i].name = g_strdup (mm_port_get_device (port));
+ MMModemPortInfo port_info;
+
+ port_info.name = g_strdup (mm_port_get_device (port));
switch (mm_port_get_port_type (port)) {
case MM_PORT_TYPE_NET:
- port_infos[i].type = MM_MODEM_PORT_TYPE_NET;
+ port_info.type = MM_MODEM_PORT_TYPE_NET;
break;
case MM_PORT_TYPE_AT:
- port_infos[i].type = MM_MODEM_PORT_TYPE_AT;
+ port_info.type = MM_MODEM_PORT_TYPE_AT;
break;
case MM_PORT_TYPE_QCDM:
- port_infos[i].type = MM_MODEM_PORT_TYPE_QCDM;
+ port_info.type = MM_MODEM_PORT_TYPE_QCDM;
break;
case MM_PORT_TYPE_GPS:
- port_infos[i].type = MM_MODEM_PORT_TYPE_GPS;
+ port_info.type = MM_MODEM_PORT_TYPE_GPS;
break;
case MM_PORT_TYPE_AUDIO:
- port_infos[i].type = MM_MODEM_PORT_TYPE_AUDIO;
+ port_info.type = MM_MODEM_PORT_TYPE_AUDIO;
break;
case MM_PORT_TYPE_QMI:
- port_infos[i].type = MM_MODEM_PORT_TYPE_QMI;
+ port_info.type = MM_MODEM_PORT_TYPE_QMI;
break;
case MM_PORT_TYPE_MBIM:
- port_infos[i].type = MM_MODEM_PORT_TYPE_MBIM;
+ port_info.type = MM_MODEM_PORT_TYPE_MBIM;
break;
case MM_PORT_TYPE_IGNORED:
port_info.type = MM_MODEM_PORT_TYPE_IGNORED;
break;
case MM_PORT_TYPE_UNKNOWN:
default:
- port_infos[i].type = MM_MODEM_PORT_TYPE_UNKNOWN;
+ port_info.type = MM_MODEM_PORT_TYPE_UNKNOWN;
break;
}
- i++;
+ g_array_append_val (port_infos, port_info);
}
- return port_infos;
+ g_assert (*n_port_infos == port_infos->len);
+ g_array_sort (port_infos, (GCompareFunc) port_info_cmp);
+ return (MMModemPortInfo *) g_array_free (port_infos, FALSE);
}
GList *