dbus/glib/examples example-service.c, 1.2, 1.3 example-client.c, 1.1, 1.2

Colin Walters walters at freedesktop.org
Tue Jul 12 02:12:51 EST 2005


Update of /cvs/dbus/dbus/glib/examples
In directory gabe:/tmp/cvs-serv19235/glib/examples

Modified Files:
	example-service.c example-client.c 
Log Message:
2005-07-11  Colin Walters  <walters at verbum.org>

	* glib/dbus-gvalue.c (struct _DBusGValue): Delete.
	(dbus_g_value_types_init): Remove assertion.
	(dbus_g_value_get_g_type, dbus_g_value_open)
	(dbus_g_value_iterator_get_values, dbus_g_value_get_signature)
	(dbus_g_value_copy, dbus_g_value_free): Delete unimplemented
	functions related to DBusGValue.  Now we marshal/demarshal
	structures as GValueArray.
	(dbus_gtype_from_signature_iter): Return G_TYPE_VALUE_ARRAY for
	structures.
	(signature_iter_to_g_type_array): Don't call
	signature_iter_to_g_type_struct.
	(signature_iter_to_g_type_struct): Delete.
	(dbus_gvalue_to_signature): Delete.
	(dbus_gvalue_to_signature): New function with same name as other
	one; we can convert structures to signatures.
	(demarshal_valuearray): New function.
	(get_type_demarshaller): Use it.
	(demarshal_recurse): Delete.
	(marshal_proxy): New function.
	(marshal_map): Warn if we can't determine signature from type.
	(marshal_collection_ptrarray): Ditto.
	(marshal_collection_array): Ditto.
	(get_type_marshaller): Use marshal_valuearray.
	(marshal_recurse): Delete.
	(_dbus_gvalue_test): Add some tests.

	* dbus/dbus-glib.h (struct _DBusGValueIterator): 
	(dbus_g_value_get_g_type, DBUS_TYPE_G_VALUE)
	(dbus_g_value_open, dbus_g_value_iterator_get_value)
	(dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse)
	(dbus_g_value_free): Remove prototypes.

	* glib/dbus-binding-tool-glib.c (dbus_g_type_get_lookup_function): Handle
	G_TYPE_VALUE_ARRAY.

	* glib/examples/example-service.c:
	* glib/examples/example-client.c: Implement GetTuple.

	* test/glib/test-dbus-glib.c:
	* test/glib/test-service-glib.c:
	* test/glib/test-service-glib.xml: Add structure tests.


Index: example-service.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/examples/example-service.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- example-service.c	8 Jul 2005 16:25:34 -0000	1.2
+++ example-service.c	11 Jul 2005 16:12:49 -0000	1.3
@@ -51,7 +51,7 @@
 G_DEFINE_TYPE(SomeObject, some_object, G_TYPE_OBJECT)
 
 gboolean some_object_hello_world (SomeObject *obj, const char *hello_message, char ***ret, GError **error);
-gboolean some_object_get_tuple (SomeObject *obj, DBusGValue **ret, GError **error);
+gboolean some_object_get_tuple (SomeObject *obj, GValueArray **ret, GError **error);
 gboolean some_object_get_dict (SomeObject *obj, GHashTable **ret, GError **error);
 
 #include "example-service-glue.h"
@@ -79,9 +79,16 @@
 }
 
 gboolean
-some_object_get_tuple (SomeObject *obj, DBusGValue **ret, GError **error)
+some_object_get_tuple (SomeObject *obj, GValueArray **ret, GError **error)
 {
-  /* FIXME */
+  *ret = g_value_array_new (6);
+  g_value_array_prepend (*ret, NULL);
+  g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_STRING);
+  g_value_set_string (g_value_array_get_nth (*ret, 0), "hello");
+  g_value_array_prepend (*ret, NULL);
+  g_value_init (g_value_array_get_nth (*ret, 0), G_TYPE_UINT);
+  g_value_set_uint (g_value_array_get_nth (*ret, 0), 42);
+  
   return TRUE;
 }
 
@@ -105,6 +112,14 @@
   guint request_name_result;
 
   g_type_init ();
+
+  {
+    GLogLevelFlags fatal_mask;
+    
+    fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+    fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+    g_log_set_always_fatal (fatal_mask);
+  }
   
   dbus_g_object_type_install_info (SOME_TYPE_OBJECT, &dbus_glib_some_object_object_info);
 

Index: example-client.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/examples/example-client.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- example-client.c	21 Jun 2005 01:18:25 -0000	1.1
+++ example-client.c	11 Jul 2005 16:12:49 -0000	1.2
@@ -41,12 +41,21 @@
   GError *error = NULL;
   char **reply_list;
   char **reply_ptr;
-  DBusGValue *hello_reply_struct;
+  GValueArray *hello_reply_struct;
   GHashTable *hello_reply_dict;
   char *introspect_data;
+  guint i;
 
   g_type_init ();
 
+  {
+    GLogLevelFlags fatal_mask;
+    
+    fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+    fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+    g_log_set_always_fatal (fatal_mask);
+  }
+
   bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
   if (!bus)
     lose_gerror ("Couldn't connect to session bus", error);
@@ -62,12 +71,10 @@
     lose_gerror ("Failed to complete HelloWorld", error);
 
   
-  /* FIXME - we don't support recursive values yet */
-#if 0  
   if (!dbus_g_proxy_call (remote_object, "GetTuple", &error,
-			  DBUS_TYPE_G_VALUE, &hello_reply_struct, G_TYPE_INVALID))
+			  G_TYPE_INVALID,
+			  G_TYPE_VALUE_ARRAY, &hello_reply_struct, G_TYPE_INVALID))
     lose_gerror ("Failed to complete GetTuple", error);
-#endif  
   
   if (!dbus_g_proxy_call (remote_object, "GetDict", &error,
 			  G_TYPE_INVALID,
@@ -80,11 +87,18 @@
   printf ("\n");
   g_strfreev (reply_list);
 
-  /* FIXME; do something with hello_reply_struct */
-#if 0
-  dbus_g_value_free (hello_reply_struct);
+  for (i = 0; i < hello_reply_struct->n_values; i++)
+    {
+      GValue strval = { 0, };
+
+      g_value_init (&strval, G_TYPE_STRING);
+      if (!g_value_transform (g_value_array_get_nth (hello_reply_struct, i), &strval))
+	g_value_set_static_string (&strval, "(couldn't transform to string)");
+      g_print ("%s: %s\n", g_type_name (G_VALUE_TYPE (g_value_array_get_nth (hello_reply_struct, i))),
+	       g_value_get_string (&strval));
+    }
+  g_value_array_free (hello_reply_struct);
   printf ("\n");
-#endif
 
   g_hash_table_foreach (hello_reply_dict, print_hash_value, NULL);
   g_hash_table_destroy (hello_reply_dict);



More information about the dbus-commit mailing list