aboutsummaryrefslogtreecommitdiff
path: root/libmm-common/mm-common-simple-properties.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-12-28 14:30:20 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:39 +0100
commit1745d8c9ebf00dc06ff4f2172d754b54c2ec9fbc (patch)
tree77e66c07ae645e6f96a086b98edbe8a08fb272f0 /libmm-common/mm-common-simple-properties.c
parent0edf4037349ab087925de1e47faf609c78f225e8 (diff)
libmm-common: let the simple properties object be built from a dictionary
Diffstat (limited to 'libmm-common/mm-common-simple-properties.c')
-rw-r--r--libmm-common/mm-common-simple-properties.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libmm-common/mm-common-simple-properties.c b/libmm-common/mm-common-simple-properties.c
index 36679395..64150b42 100644
--- a/libmm-common/mm-common-simple-properties.c
+++ b/libmm-common/mm-common-simple-properties.c
@@ -169,6 +169,70 @@ mm_common_simple_properties_get_dictionary (MMCommonSimpleProperties *self)
/*****************************************************************************/
MMCommonSimpleProperties *
+mm_common_simple_properties_new_from_dictionary (GVariant *dictionary,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ GVariantIter iter;
+ gchar *key;
+ GVariant *value;
+ MMCommonSimpleProperties *properties;
+
+ properties = mm_common_simple_properties_new ();
+ if (!dictionary)
+ return properties;
+
+ g_variant_iter_init (&iter, dictionary);
+ while (!inner_error &&
+ g_variant_iter_next (&iter, "{sv}", &key, &value)) {
+ /* Note: we could do a more efficient matching by checking the variant type
+ * and just g_object_set()-ing they specific 'key' and value, but we do want
+ * to check which input keys we receive, in order to propagate the error.
+ */
+ if (g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_STATE) ||
+ g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_ACCESS_TECHNOLOGIES) ||
+ g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_3GPP_REGISTRATION_STATE)) {
+ /* uint properties */
+ g_object_set (properties,
+ key, g_variant_get_uint32 (value),
+ NULL);
+ } else if (g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_3GPP_OPERATOR_CODE) ||
+ g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_3GPP_OPERATOR_NAME)) {
+ /* string properties */
+ g_object_set (properties,
+ key, g_variant_get_string (value, NULL),
+ NULL);
+ } else if (g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_BANDS) ||
+ g_str_equal (key, MM_COMMON_SIMPLE_PROPERTY_SIGNAL_QUALITY)) {
+ /* remaining complex types, as variant */
+ g_object_set (properties,
+ key, value,
+ NULL);
+ } else {
+ /* Set inner error, will stop the loop */
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Invalid properties dictionary, unexpected key '%s'",
+ key);
+ }
+
+ g_free (key);
+ g_variant_unref (value);
+ }
+
+ /* If error, destroy the object */
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ g_object_unref (properties);
+ properties = NULL;
+ }
+
+ return properties;
+}
+
+/*****************************************************************************/
+
+MMCommonSimpleProperties *
mm_common_simple_properties_new (void)
{
return (MM_COMMON_SIMPLE_PROPERTIES (