libmm-common: new modes string parser

This commit is contained in:
Aleksander Morgado
2012-03-15 14:14:37 +01:00
parent 6cfccb1452
commit 0343812502
2 changed files with 39 additions and 0 deletions
+38
View File
@@ -168,6 +168,44 @@ mm_common_get_bands_string (const MMModemBand *bands,
return g_string_free (str, FALSE);
}
MMModemMode
mm_common_get_modes_from_string (const gchar *str)
{
MMModemMode modes;
gchar **mode_strings;
GFlagsClass *flags_class;
modes = MM_MODEM_MODE_NONE;
flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_MODE));
mode_strings = g_strsplit (str, "|", -1);
if (mode_strings) {
guint i;
for (i = 0; mode_strings[i]; i++) {
guint j;
gboolean found = FALSE;
for (j = 0; flags_class->values[j].value_nick; j++) {
if (g_str_equal (mode_strings[i], flags_class->values[j].value_nick)) {
modes |= flags_class->values[j].value;
found = TRUE;
break;
}
}
if (!found)
g_warning ("Couldn't match '%s' with a valid MMModemMode value",
mode_strings[i]);
}
}
g_type_class_unref (flags_class);
g_strfreev (mode_strings);
return modes;
}
void
mm_common_get_bands_from_string (const gchar *str,
MMModemBand **bands,
+1
View File
@@ -25,6 +25,7 @@ gchar *mm_common_get_modes_string (MMModemMode mode);
gchar *mm_common_get_bands_string (const MMModemBand *bands,
guint n_bands);
MMModemMode mm_common_get_modes_from_string (const gchar *str);
void mm_common_get_bands_from_string (const gchar *str,
MMModemBand **bands,
guint *n_bands);