diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-12-26 21:29:18 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:37 +0100 |
commit | 034381250277751741f134123fc61c0c5405adea (patch) | |
tree | cbe8ee33d9c4400beb5d9e239f7c880eac23c2c1 | |
parent | 6cfccb14526a6b0fa27f680cb76d7bef165cd169 (diff) |
libmm-common: new modes string parser
-rw-r--r-- | libmm-common/mm-common-helpers.c | 38 | ||||
-rw-r--r-- | libmm-common/mm-common-helpers.h | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/libmm-common/mm-common-helpers.c b/libmm-common/mm-common-helpers.c index 48a535f2..c7eb4821 100644 --- a/libmm-common/mm-common-helpers.c +++ b/libmm-common/mm-common-helpers.c @@ -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, diff --git a/libmm-common/mm-common-helpers.h b/libmm-common/mm-common-helpers.h index 1d2969b2..1c3dcc28 100644 --- a/libmm-common/mm-common-helpers.h +++ b/libmm-common/mm-common-helpers.h @@ -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); |