aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-common-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-06-20 23:45:12 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-06-24 19:44:57 +0200
commit3206e9566392e8a9678bbd49e0de9bb21ed75291 (patch)
tree20c5321317ccf6968b9de0c50a7fd7b8df853c65 /libmm-glib/mm-common-helpers.c
parent30fe6eab4844966a9ad99599aeac910fd9898798 (diff)
api,introspection: new 'Ports' property in the Modem interface
We will expose a new 'Ports' property listing all ports currently known by a given modem. Ports which are not used but are detected as being part of the modem will be listed with an 'unknown' port type. This change uses the new 'MMModemPortType' enum and the new 'MMModemPortInfo' helper struct to handle these values in libmm-glib. The already available 'MMPortType' enum hasn't been re-used for the interface because it contains values that we don't need (e.g. IGNORED). The port list is now also included in the modem information command of mmcli: $ sudo mmcli -m 0 /org/freedesktop/ModemManager1/Modem/0 (device id '97b7b99e3e2bea103880545b619fb05a3cc81b26') ------------------------- System | device: '/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4' | drivers: 'qcserial, qmi_wwan' | plugin: 'Gobi' | primary port: 'cdc-wdm0' | ports: 'ttyUSB0 (qcdm), ttyUSB1 (at), cdc-wdm0 (qmi), wwp0s29u1u4 (net)' https://bugzilla.gnome.org/show_bug.cgi?id=702678
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r--libmm-glib/mm-common-helpers.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 838e09f6..740b3169 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -78,6 +78,31 @@ mm_common_build_bands_string (const MMModemBand *bands,
}
gchar *
+mm_common_build_ports_string (const MMModemPortInfo *ports,
+ guint n_ports)
+{
+ gboolean first = TRUE;
+ GString *str;
+ guint i;
+
+ if (!ports || !n_ports)
+ return g_strdup ("none");
+
+ str = g_string_new ("");
+ for (i = 0; i < n_ports; i++) {
+ g_string_append_printf (str, "%s%s (%s)",
+ first ? "" : ", ",
+ ports[i].name,
+ mm_modem_port_type_get_string (ports[i].type));
+
+ if (first)
+ first = FALSE;
+ }
+
+ return g_string_free (str, FALSE);
+}
+
+gchar *
mm_common_build_sms_storages_string (const MMSmsStorage *storages,
guint n_storages)
{
@@ -194,6 +219,72 @@ mm_common_sms_storages_garray_to_variant (GArray *array)
return mm_common_sms_storages_array_to_variant (NULL, 0);
}
+GArray *
+mm_common_ports_variant_to_garray (GVariant *variant)
+{
+ GArray *array = NULL;
+
+ if (variant) {
+ guint i;
+ guint n;
+
+ n = g_variant_n_children (variant);
+
+ if (n > 0) {
+ array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemPortInfo), n);
+ for (i = 0; i < n; i++) {
+ MMModemPortInfo info;
+
+ g_variant_get_child (variant, i, "(su)", &info.name, &info.type);
+ g_array_append_val (array, info);
+ }
+ }
+ }
+
+ return array;
+}
+
+MMModemPortInfo *
+mm_common_ports_variant_to_array (GVariant *variant,
+ guint *n_ports)
+{
+ GArray *array;
+
+ array = mm_common_ports_variant_to_garray (variant);
+ if (n_ports)
+ *n_ports = array->len;
+ return (MMModemPortInfo *) g_array_free (array, FALSE);
+}
+
+GVariant *
+mm_common_ports_array_to_variant (const MMModemPortInfo *ports,
+ guint n_ports)
+{
+ GVariantBuilder builder;
+ guint i;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(su)"));
+
+ for (i = 0; i < n_ports; i++) {
+ GVariant *tuple[2];
+
+ tuple[0] = g_variant_new_string (ports[i].name);
+ tuple[1] = g_variant_new_uint32 ((guint32)ports[i].type);
+ g_variant_builder_add_value (&builder, g_variant_new_tuple (tuple, 2));
+ }
+ return g_variant_builder_end (&builder);
+}
+
+GVariant *
+mm_common_ports_garray_to_variant (GArray *array)
+{
+ if (array)
+ return mm_common_ports_array_to_variant ((const MMModemPortInfo *)array->data,
+ array->len);
+
+ return mm_common_ports_array_to_variant (NULL, 0);
+}
+
MMModemCapability
mm_common_get_capabilities_from_string (const gchar *str,
GError **error)