diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-01-18 13:45:32 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:52 +0100 |
commit | a3532e7730b9f776c5590f2680f444306e411bdd (patch) | |
tree | c9ae07235db1597bb741e5283a32c4a6f40dffe6 | |
parent | 69e860329b92796fc9d7e648f67ae09a77d41840 (diff) |
libmm-common: flags string builders are now all autogenerated
-rw-r--r-- | libmm-common/mm-common-helpers.c | 141 | ||||
-rw-r--r-- | libmm-common/mm-common-helpers.h | 7 |
2 files changed, 8 insertions, 140 deletions
diff --git a/libmm-common/mm-common-helpers.c b/libmm-common/mm-common-helpers.c index 5410a313..86519b27 100644 --- a/libmm-common/mm-common-helpers.c +++ b/libmm-common/mm-common-helpers.c @@ -22,154 +22,25 @@ #include "mm-common-helpers.h" gchar * -mm_common_get_capabilities_string (MMModemCapability caps) +mm_common_build_bands_string (const MMModemBand *bands, + guint n_bands) { - GFlagsClass *flags_class; - GString *str; - - str = g_string_new (""); - flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_CAPABILITY)); - - if (caps == MM_MODEM_CAPABILITY_NONE) { - GFlagsValue *value; - - value = g_flags_get_first_value (flags_class, caps); - g_string_append (str, value->value_nick); - } else { - MMModemCapability it; - gboolean first = TRUE; - - for (it = MM_MODEM_CAPABILITY_POTS; /* first */ - it <= MM_MODEM_CAPABILITY_LTE_ADVANCED; /* last */ - it = it << 1) { - if (caps & 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_access_technologies_string (MMModemAccessTechnology access_tech) -{ - GFlagsClass *flags_class; - GString *str; - - str = g_string_new (""); - flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_ACCESS_TECHNOLOGY)); - - if (access_tech == MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN) { - GFlagsValue *value; - - value = g_flags_get_first_value (flags_class, access_tech); - g_string_append (str, value->value_nick); - } else { - MMModemAccessTechnology it; - gboolean first = TRUE; - - for (it = MM_MODEM_ACCESS_TECHNOLOGY_GSM; /* first */ - it <= MM_MODEM_ACCESS_TECHNOLOGY_LTE; /* last */ - it = it << 1) { - if (access_tech & 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_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_CS; /* first */ - it <= MM_MODEM_MODE_4G; /* last */ - it = it << 1) { - if (mode & it) { - GFlagsValue *value; - gchar *up; - - value = g_flags_get_first_value (flags_class, it); - up = g_ascii_strup (value->value_nick, -1); - g_string_append_printf (str, "%s%s", - first ? "" : ", ", - up); - g_free (up); - - 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) -{ - GEnumClass *enum_class; gboolean first = TRUE; GString *str; guint i; - str = g_string_new (""); - if (n_bands == 0) { - g_string_append (str, "none"); - return g_string_free (str, FALSE); - } + if (!bands || !n_bands) + return g_strdup ("none"); - enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_BAND)); + str = g_string_new (""); for (i = 0; i < n_bands; i++) { - GEnumValue *value; - - value = g_enum_get_value (enum_class, bands[i]); g_string_append_printf (str, "%s%s", first ? "" : ", ", - value->value_nick); + mm_modem_band_get_string (bands[i])); if (first) first = FALSE; } - g_type_class_unref (enum_class); return g_string_free (str, FALSE); } diff --git a/libmm-common/mm-common-helpers.h b/libmm-common/mm-common-helpers.h index 34119744..fa39a7be 100644 --- a/libmm-common/mm-common-helpers.h +++ b/libmm-common/mm-common-helpers.h @@ -19,11 +19,8 @@ #ifndef MM_COMMON_HELPERS_H #define MM_COMMON_HELPERS_H -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); +gchar *mm_common_build_bands_string (const MMModemBand *bands, + guint n_bands); MMModemMode mm_common_get_modes_from_string (const gchar *str, GError **error); |