libmm-common,libmm-glib: new modes string builder

This commit is contained in:
Aleksander Morgado
2012-03-15 14:14:37 +01:00
parent aa3d98d0ff
commit 6cfccb1452
4 changed files with 56 additions and 0 deletions
+40
View File
@@ -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)
+1
View File
@@ -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);
+14
View File
@@ -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.
+1
View File
@@ -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);