From 6cfccb14526a6b0fa27f680cb76d7bef165cd169 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 26 Dec 2011 21:29:01 +0100 Subject: [PATCH] libmm-common,libmm-glib: new modes string builder --- libmm-common/mm-common-helpers.c | 40 ++++++++++++++++++++++++++++++++ libmm-common/mm-common-helpers.h | 1 + libmm-glib/mm-modem.c | 14 +++++++++++ libmm-glib/mm-modem.h | 1 + 4 files changed, 56 insertions(+) diff --git a/libmm-common/mm-common-helpers.c b/libmm-common/mm-common-helpers.c index 93509f11..48a535f2 100644 --- a/libmm-common/mm-common-helpers.c +++ b/libmm-common/mm-common-helpers.c @@ -96,6 +96,46 @@ mm_common_get_access_technologies_string (MMModemAccessTechnology access_tech) return g_string_free (str, FALSE); } +gchar * +mm_common_get_modes_string (MMModemMode mode) +{ + GFlagsClass *flags_class; + GString *str; + + str = g_string_new (""); + flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_MODE)); + + if (mode == MM_MODEM_MODE_NONE || + mode == MM_MODEM_MODE_ANY) { + GFlagsValue *value; + + value = g_flags_get_first_value (flags_class, mode); + g_string_append (str, value->value_nick); + } else { + MMModemMode it; + gboolean first = TRUE; + + for (it = MM_MODEM_MODE_1G; /* first */ + it <= MM_MODEM_MODE_4G; /* last */ + it = it << 1) { + if (mode & it) { + GFlagsValue *value; + + value = g_flags_get_first_value (flags_class, it); + g_string_append_printf (str, "%s%s", + first ? "" : ", ", + value->value_nick); + + if (first) + first = FALSE; + } + } + } + g_type_class_unref (flags_class); + + return g_string_free (str, FALSE); +} + gchar * mm_common_get_bands_string (const MMModemBand *bands, guint n_bands) diff --git a/libmm-common/mm-common-helpers.h b/libmm-common/mm-common-helpers.h index 595705b0..1d2969b2 100644 --- a/libmm-common/mm-common-helpers.h +++ b/libmm-common/mm-common-helpers.h @@ -21,6 +21,7 @@ gchar *mm_common_get_capabilities_string (MMModemCapability caps); gchar *mm_common_get_access_technologies_string (MMModemAccessTechnology access_tech); +gchar *mm_common_get_modes_string (MMModemMode mode); gchar *mm_common_get_bands_string (const MMModemBand *bands, guint n_bands); diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index fd348a18..e6bec310 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -1699,6 +1699,20 @@ mm_modem_get_access_technologies_string (MMModemAccessTechnology access_tech) return mm_common_get_access_technologies_string (access_tech); } +/** + * mm_modem_get_modes_string: + * @mode: Bitmask of #MMModemMode flags. + * + * Build a string with a list of modes. + * + * Returns: (transfer full): A string specifying the modes given in @mode. The returned value should be freed with g_free(). + */ +gchar * +mm_modem_get_modes_string (MMModemMode mode) +{ + return mm_common_get_modes_string (mode); +} + /** * mm_modem_get_bands_string: * @bands: List of #MMModemBand values. diff --git a/libmm-glib/mm-modem.h b/libmm-glib/mm-modem.h index 16015d53..24982196 100644 --- a/libmm-glib/mm-modem.h +++ b/libmm-glib/mm-modem.h @@ -212,6 +212,7 @@ MMSim *mm_modem_get_sim_sync (MMModem *self, gchar *mm_modem_get_capabilities_string (MMModemCapability caps); gchar *mm_modem_get_access_technologies_string (MMModemAccessTechnology access_tech); +gchar *mm_modem_get_modes_string (MMModemMode mode); gchar *mm_modem_get_bands_string (const MMModemBand *bands, guint n_bands);