diff options
author | Robert McQueen <robot101@debian.org> | 2006-01-27 15:40:36 +0000 |
---|---|---|
committer | Robert McQueen <robot101@debian.org> | 2006-01-27 15:40:36 +0000 |
commit | 8e00b10d134e4fb844cdc961e5c3230edf194b57 (patch) | |
tree | 916ef4ae22231cf4cd6d320fc23a97137ac2a2d6 /test/glib/test-service-glib.c | |
parent | ce13b5dff7208beade01ac06235c263872201c80 (diff) |
2006-01-27 Robert McQueen <robot101@debian.org>
* glib/dbus-gtype-specialized.[ch], glib/dbus-gvalue-utils.c: Patch
by me and Rob Taylor to add a simple_free function to D-Bus map
and collection types, which allows those types which can be freed
with a GDestroyNotify (such as GHashTables and GArrays, but not
GPtrArrays) to be stored as the values in hashtables.
* test/glib/test-dbus-glib.c, test/glib/test-service-glib.{c,xml}:
Patch by Rob Taylor to add nested dicts to the glib tests to check
the above code works, and appears not to leak when called repeatedly.
Diffstat (limited to 'test/glib/test-service-glib.c')
-rw-r--r-- | test/glib/test-service-glib.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/glib/test-service-glib.c b/test/glib/test-service-glib.c index 6d10b937..829cb57d 100644 --- a/test/glib/test-service-glib.c +++ b/test/glib/test-service-glib.c @@ -101,6 +101,8 @@ gboolean my_object_echo_variant (MyObject *obj, GValue *variant, GValue *ret, GE gboolean my_object_process_variant_of_array_of_ints123 (MyObject *obj, GValue *variant, GError **error); +gboolean my_object_dict_of_dicts (MyObject *obj, GHashTable *dict, GHashTable **ret, GError **error); + gboolean my_object_terminate (MyObject *obj, GError **error); void my_object_async_increment (MyObject *obj, gint32 x, DBusGMethodInvocation *context); @@ -706,6 +708,51 @@ error: return FALSE; } + +typedef struct _HashAndString HashAndString; + +struct _HashAndString +{ + GHashTable *hash; + gchar* string; +}; + +static void +hash_foreach_prepend_string (gpointer key, gpointer val, gpointer user_data) +{ + HashAndString *data = (HashAndString*) user_data; + gchar *in = (gchar*) val; + g_hash_table_insert (data->hash, g_strdup ((gchar*) key), + g_strjoin (" ", data->string, in, NULL)); +} + + +static void +hash_foreach_mangle_dict_of_strings (gpointer key, gpointer val, gpointer user_data) +{ + GHashTable *out = (GHashTable*) user_data; + GHashTable *in_dict = (GHashTable *) val; + HashAndString *data = g_new0 (HashAndString, 1); + + data->string = (gchar*) key; + data->hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_free); + g_hash_table_foreach (in_dict, hash_foreach_prepend_string, data); + + g_hash_table_insert(out, g_strdup ((gchar*) key), data->hash); +} + +gboolean +my_object_dict_of_dicts (MyObject *obj, GHashTable *in, + GHashTable **out, GError **error) +{ + *out = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_hash_table_destroy); + g_hash_table_foreach (in, hash_foreach_mangle_dict_of_strings, *out); + return TRUE; +} + gboolean my_object_emit_frobnicate (MyObject *obj, GError **error) { |