From d7bc696eda45064550af928688eaf3b560280c39 Mon Sep 17 00:00:00 2001 From: lucas Date: Mon, 14 Nov 2011 15:19:52 +0000 Subject: [PATCH] e_dbus/connman: allow a property inside a dict to be an array git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@65184 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/connman/E_Connman.h | 2 + src/lib/connman/e_connman_element.c | 80 ++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/lib/connman/E_Connman.h b/src/lib/connman/E_Connman.h index a8ed701..caf179c 100644 --- a/src/lib/connman/E_Connman.h +++ b/src/lib/connman/E_Connman.h @@ -212,6 +212,8 @@ EAPI Eina_Bool e_connman_element_property_dict_set_full(E_Connman_E EAPI Eina_Bool e_connman_element_property_type_get_stringshared(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; EAPI Eina_Bool e_connman_element_property_type_get(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; EAPI Eina_Bool e_connman_element_property_dict_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key_name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; +EAPI Eina_Bool e_connman_element_property_dict_strings_array_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key, unsigned int *count, const char ***strings) EINA_ARG_NONNULL(1, 2, 3, 4) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_connman_element_property_get_stringshared(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; EAPI Eina_Bool e_connman_element_property_get(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; diff --git a/src/lib/connman/e_connman_element.c b/src/lib/connman/e_connman_element.c index cfeae8f..3a2f6f6 100644 --- a/src/lib/connman/e_connman_element.c +++ b/src/lib/connman/e_connman_element.c @@ -49,12 +49,13 @@ struct _E_Connman_Element_Dict_Entry const char *name; int type; union { - Eina_Bool boolean; - const char *str; - unsigned short u16; - unsigned int u32; - unsigned char byte; - const char *path; + Eina_Bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + E_Connman_Array *array; } value; }; @@ -1837,6 +1838,10 @@ e_connman_element_property_dict_get_stringshared(const E_Connman_Element *elemen *(const char **)value = entry->value.path; return EINA_TRUE; + case DBUS_TYPE_ARRAY: + *(E_Connman_Array **)value = entry->value.array; + return EINA_TRUE; + default: ERR("don't know how to get property %s, key %s type %c (%d)", dict_name, key, entry->type, entry->type); @@ -1849,6 +1854,69 @@ e_connman_element_property_dict_get_stringshared(const E_Connman_Element *elemen return EINA_FALSE; } +Eina_Bool +e_connman_element_property_dict_strings_array_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key, unsigned int *count, const char ***strings) +{ + const char **ret, **p; + Eina_Array_Iterator iterator; + E_Connman_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(dict_name, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(strings, EINA_FALSE); + + *count = 0; + *strings = NULL; + + if (!e_connman_element_property_dict_get_stringshared(element, dict_name, + key, &type, &array)) + return EINA_FALSE; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s.%s is not an array!", dict_name, key); + return EINA_FALSE; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return EINA_FALSE; + + if (array->type != DBUS_TYPE_STRING) + { + ERR("property %s.%s is not an array of strings!", dict_name, key); + return EINA_FALSE; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(char *)); + if (!ret) + { + ERR("could not allocate return array of %d strings: %s", + *count, strerror(errno)); + *count = 0; + return EINA_FALSE; + } + + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + if (!item) + continue; + + *p = item; + p++; + } + *count = p - ret; + *strings = ret; + return EINA_TRUE; +} + /** * Get property value given its name. * -- 2.7.4