diff options
author | Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com> | 2014-08-19 13:36:32 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2014-09-08 00:38:53 +0200 |
commit | 43eb332a06c05964ee3c391c9b1ef6a50bd6b543 (patch) | |
tree | c5d6ceffa88c1b2b427e2d71035b76b4b9d956ef /lib | |
parent | 93d77f01cc46b8e4452227bb527d027a3112d28c (diff) | |
download | neardal-43eb332a06c05964ee3c391c9b1ef6a50bd6b543.tar.gz neardal-43eb332a06c05964ee3c391c9b1ef6a50bd6b543.tar.bz2 neardal-43eb332a06c05964ee3c391c9b1ef6a50bd6b543.zip |
Add datalist convenience functions.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/neardal_tools.c | 45 | ||||
-rw-r--r-- | lib/neardal_tools.h | 5 |
2 files changed, 50 insertions, 0 deletions
diff --git a/lib/neardal_tools.c b/lib/neardal_tools.c index 36f17c0..c312d54 100644 --- a/lib/neardal_tools.c +++ b/lib/neardal_tools.c @@ -66,6 +66,51 @@ void *neardal_g_variant_get(GVariant *data, const char *key, const char *fmt) return out; } +void *neardal_data_search(const char *name) +{ + GData **l = &(neardalMgr.dbus_data); + return g_datalist_get_data(l, name); +} + +void **neardal_arrayv_append(void **array, void *data) +{ + guint len = array ? g_strv_length((gchar **) array) : 0; + void **out = g_realloc(array, sizeof(void *) * (len + 2)); + out[len] = data; + out[len + 1] = NULL; + return out; +} + +static void neardal_data_cb(GQuark id, gpointer data, gpointer user_data) +{ + void ***array = user_data; + *array = neardal_arrayv_append(*array, data); +} + +guint neardal_data_to_arrayv(void ***array) +{ + GData **l = &(neardalMgr.dbus_data); + g_datalist_foreach(l, neardal_data_cb, array); + return *array ? g_strv_length((gchar **) *array) : 0; +} + +GVariant *neardal_data_insert(const char *name, const char *type, GVariant *in) +{ + GVariant *out = in; + GData **l = &(neardalMgr.dbus_data); + neardal_g_variant_add_parsed(&out, "{'NeardalType', <%s>}", type); + neardal_g_variant_add_parsed(&out, "{'Name', <%s>}", name); + g_datalist_set_data_full(l, name, g_variant_ref(out), + (GDestroyNotify) g_variant_unref); + return out; +} + +void neardal_data_remove(GVariant *data) +{ + GData **l = &(neardalMgr.dbus_data); + g_datalist_remove_data(l, neardal_g_variant_get(data, "Name", "&s")); +} + char *neardal_dirname(const char *path) { char *tmp = strrchr(path, '/'); diff --git a/lib/neardal_tools.h b/lib/neardal_tools.h index 6ac21d3..dc41686 100644 --- a/lib/neardal_tools.h +++ b/lib/neardal_tools.h @@ -68,6 +68,11 @@ errorCode_t neardal_tools_prv_add_dict_entry(GVariantBuilder *builder void neardal_g_variant_add_parsed(GVariant **v, const char *format, ...); void neardal_g_variant_dump(GVariant *data); void *neardal_g_variant_get(GVariant *data, const char *key, const char *fmt); +void *neardal_data_search(const char *name); +GVariant *neardal_data_insert(const char *name, const char *type, GVariant *in); +void neardal_data_remove(GVariant *data); +guint neardal_data_to_arrayv(void ***array); +void **neardal_arrayv_append(void **array, void *data); char *neardal_dirname(const char *path); static inline gpointer neardal_g_callback(GCallback gc) |