dbus/test/glib run-test.sh,1.7,1.8 test-service-glib.c,1.5,1.6

Havoc Pennington hp at freedesktop.org
Sat Jan 29 23:44:11 PST 2005


Update of /cvs/dbus/dbus/test/glib
In directory gabe:/tmp/cvs-serv18909/test/glib

Modified Files:
	run-test.sh test-service-glib.c 
Log Message:
2005-01-30  Havoc Pennington  <hp at redhat.com>

	* glib/dbus-gobject.c (introspect_properties): fix the XML
	generated

	* dbus/dbus-message.c (dbus_message_unref): add an in_cache flag
	which effectively detects the use of freed messages

	* glib/dbus-gobject.c (handle_introspect): modify and return the
	reply message instead of the incoming message

	* dbus/dbus-object-tree.c (handle_default_introspect_unlocked):
	gee, maybe it should SEND THE XML instead of just making a string
	and freeing it again ;-)

	* tools/dbus-print-message.c (print_message): improve printing of
	messages

	* configure.in: add debug-glib.service to the output



Index: run-test.sh
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/run-test.sh,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- run-test.sh	30 Jan 2005 05:18:44 -0000	1.7
+++ run-test.sh	30 Jan 2005 07:44:08 -0000	1.8
@@ -67,9 +67,12 @@
   echo "Launching dbus-viewer"
   ARGS=
   if test x$DEBUG = x ; then
-      ARGS="--services org.freedesktop.DBus"
+      ARGS="--services org.freedesktop.DBus org.freedesktop.DBus.TestSuiteGLibService"
   fi
   libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/tools/dbus-viewer $ARGS || die "could not run dbus-viewer"
+elif test x$MODE = xwait ; then
+  echo "Waiting DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
+  sleep 86400
 else
   echo "running test-dbus-glib"
   libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-dbus-glib || die "test-dbus-glib failed"

Index: test-service-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-service-glib.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test-service-glib.c	30 Jan 2005 05:18:44 -0000	1.5
+++ test-service-glib.c	30 Jan 2005 07:44:08 -0000	1.6
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <glib/gi18n.h>
 
 typedef struct MyObject MyObject;
 typedef struct MyObjectClass MyObjectClass;
@@ -12,6 +13,7 @@
 struct MyObject
 {
   GObject parent;
+  char *this_is_a_string;
 };
 
 struct MyObjectClass
@@ -20,7 +22,7 @@
 };
 
 #define MY_TYPE_OBJECT              (my_object_get_type ())
-#define MY_OBJECT_OBJECT(object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), MY_TYPE_OBJECT, MyObject))
+#define MY_OBJECT(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), MY_TYPE_OBJECT, MyObject))
 #define MY_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_OBJECT, MyObjectClass))
 #define MY_IS_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), MY_TYPE_OBJECT))
 #define MY_IS_OBJECT_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_OBJECT))
@@ -28,6 +30,67 @@
 
 G_DEFINE_TYPE(MyObject, my_object, G_TYPE_OBJECT)
 
+/* Properties */
+enum
+{
+  PROP_0,
+  PROP_THIS_IS_A_STRING
+};
+
+static void
+my_object_finalize (GObject *object)
+{
+  MyObject *mobject = MY_OBJECT (object);
+
+  g_free (mobject->this_is_a_string);
+
+  (G_OBJECT_CLASS (my_object_parent_class)->finalize) (object);
+}
+
+static void
+my_object_set_property (GObject      *object,
+                        guint         prop_id,
+                        const GValue *value,
+                        GParamSpec   *pspec)
+{
+  MyObject *mobject;
+
+  mobject = MY_OBJECT (object);
+  
+  switch (prop_id)
+    {
+    case PROP_THIS_IS_A_STRING:
+      g_free (mobject->this_is_a_string);
+      mobject->this_is_a_string = g_value_dup_string (value);
+      break;
+      
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+my_object_get_property (GObject      *object,
+                        guint         prop_id,
+                        GValue       *value,
+                        GParamSpec   *pspec)
+{
+  MyObject *mobject;
+
+  mobject = MY_OBJECT (object);
+  
+  switch (prop_id)
+    {
+    case PROP_THIS_IS_A_STRING:
+      g_value_set_string (value, mobject->this_is_a_string);
+      break;
+      
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
 
 static void
 my_object_init (MyObject *obj)
@@ -36,9 +99,21 @@
 }
 
 static void
-my_object_class_init (MyObjectClass *obj_class)
+my_object_class_init (MyObjectClass *mobject_class)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (mobject_class);
+
+  gobject_class->finalize = my_object_finalize;
+  gobject_class->set_property = my_object_set_property;
+  gobject_class->get_property = my_object_get_property;
   
+  g_object_class_install_property (gobject_class,
+				   PROP_THIS_IS_A_STRING,
+				   g_param_spec_string ("this_is_a_string",
+                                                        _("Sample string"),
+                                                        _("Example of a string property"),
+                                                        "default value",
+                                                        G_PARAM_READWRITE));
 }
      
 static GMainLoop *loop;
@@ -49,6 +124,10 @@
   DBusGConnection *connection;
   GError *error;
   GObject *obj;
+  DBusGProxy *driver_proxy;
+  DBusGPendingCall *call;
+  const char *v_STRING;
+  guint32 v_UINT32;
   
   g_type_init ();
   
@@ -70,7 +149,40 @@
   dbus_g_connection_register_g_object (connection,
                                        "/org/freedesktop/my_test_object",
                                        obj);
-  
+
+  driver_proxy = dbus_g_proxy_new_for_name (connection,
+                                            DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
+                                            DBUS_PATH_ORG_FREEDESKTOP_DBUS,
+                                            DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS);
+
+  v_STRING = "org.freedesktop.DBus.TestSuiteGLibService";
+  v_UINT32 = 0;
+  call = dbus_g_proxy_begin_call (driver_proxy, "RequestName",
+                                  DBUS_TYPE_STRING,
+                                  &v_STRING,
+                                  DBUS_TYPE_UINT32,
+                                  &v_UINT32,
+                                  DBUS_TYPE_INVALID);
+  if (!dbus_g_proxy_end_call (driver_proxy, call,
+                              &error, DBUS_TYPE_UINT32, &v_UINT32,
+                              DBUS_TYPE_INVALID))
+    {
+      g_assert (error != NULL);
+      g_printerr ("Failed to get name: %s\n",
+                  error->message);
+      g_error_free (error);
+      exit (1);
+    }
+  g_assert (error == NULL);
+  dbus_g_pending_call_unref (call);
+
+  if (!(v_UINT32 == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER))
+    {
+      g_printerr ("Got result code %u from requesting name\n", v_UINT32);
+      exit (1);
+    }
+
+  g_print ("GLib test service has name '%s'\n", v_STRING);
   g_print ("GLib test service entering main loop\n");
 
   g_main_loop_run (loop);



More information about the dbus-commit mailing list