dbus/tools dbus-print-message.c,1.4,1.5 dbus-viewer.c,1.5,1.6

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


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

Modified Files:
	dbus-print-message.c dbus-viewer.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: dbus-print-message.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-print-message.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dbus-print-message.c	15 Jan 2005 07:15:38 -0000	1.4
+++ dbus-print-message.c	30 Jan 2005 07:44:08 -0000	1.5
@@ -44,43 +44,45 @@
 {
   DBusMessageIter iter;
   const char *sender;
+  const char *destination;
   int message_type;
+  int count;
 
   message_type = dbus_message_get_type (message);
-  sender = dbus_message_get_sender (message); 
+  sender = dbus_message_get_sender (message);
+  destination = dbus_message_get_destination (message);
 
+  printf ("%s sender=%s -> dest=%s",
+          type_to_name (message_type),
+          sender ? sender : "(null sender)",
+          destination ? destination : "(null destination)");
+         
   switch (message_type)
     {
     case DBUS_MESSAGE_TYPE_METHOD_CALL:
     case DBUS_MESSAGE_TYPE_SIGNAL:
-      printf ("%s interface=%s; member=%s; sender=%s\n",
-              type_to_name (message_type),
+      printf (" interface=%s; member=%s\n",
               dbus_message_get_interface (message),
-              dbus_message_get_member (message),
-              sender ? sender : "(no sender)");
+              dbus_message_get_member (message));
       break;
       
     case DBUS_MESSAGE_TYPE_METHOD_RETURN:
-      printf ("%s; sender=%s\n",
-              type_to_name (message_type),
-              sender ? sender : "(no sender)");
+      printf ("\n");
       break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
-      printf ("%s name=%s; sender=%s\n",
-              type_to_name (message_type),
-              dbus_message_get_error_name (message),
-              sender ? sender : "(no sender)");
+      printf (" error_name=%s\n",
+              dbus_message_get_error_name (message));
       break;
 
     default:
-      printf ("Message of unknown type %d received\n",
-              message_type);
+      printf ("\n");
       break;
     }
-      
-  dbus_message_iter_init (message, &iter);
 
+  dbus_message_iter_init (message, &iter);
+  count = 0;
+  
   do
     {
       int type = dbus_message_iter_get_arg_type (&iter);
@@ -98,38 +100,40 @@
 	{
 	case DBUS_TYPE_STRING:
           dbus_message_iter_get_basic (&iter, &str);
-	  printf ("string:%s\n", str);
+	  printf (" %d string \"%s\"\n", count, str);
 	  break;
 
 	case DBUS_TYPE_INT32:
           dbus_message_iter_get_basic (&iter, &int32);
-	  printf ("int32:%d\n", int32);
+	  printf (" %d int32 %d\n", count, int32);
 	  break;
 
 	case DBUS_TYPE_UINT32:
           dbus_message_iter_get_basic (&iter, &uint32);
-	  printf ("int32:%u\n", uint32);
+	  printf (" %d uint32 %u\n", count, uint32);
 	  break;
 
 	case DBUS_TYPE_DOUBLE:
 	  dbus_message_iter_get_basic (&iter, &d);
-	  printf ("double:%f\n", d);
+	  printf (" %d double %g\n", count, d);
 	  break;
 
 	case DBUS_TYPE_BYTE:
 	  dbus_message_iter_get_basic (&iter, &byte);
-	  printf ("byte:%d\n", byte);
+	  printf (" %d byte %d\n", count, byte);
 	  break;
 
 	case DBUS_TYPE_BOOLEAN:
           dbus_message_iter_get_basic (&iter, &boolean);
-	  printf ("boolean:%s\n", boolean ? "true" : "false");
+	  printf (" %d boolean %s\n", count, boolean ? "true" : "false");
 	  break;
 
 	default:
-	  printf ("(unknown arg type %d)\n", type);
+	  printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
 	  break;
 	}
+      
+      count += 1;
     } while (dbus_message_iter_next (&iter));
 }
 

Index: dbus-viewer.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-viewer.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dbus-viewer.c	30 Jan 2005 05:18:44 -0000	1.5
+++ dbus-viewer.c	30 Jan 2005 07:44:08 -0000	1.6
@@ -192,6 +192,7 @@
 static gboolean
 load_child_nodes (const char *service_name,
                   NodeInfo   *parent,
+                  GString    *path,
                   GError    **error)
 {
   DBusGConnection *connection;
@@ -200,7 +201,7 @@
   connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
   if (connection == NULL)
     return FALSE;
-
+  
   tmp = node_info_get_nodes (parent);
   while (tmp != NULL)
     {
@@ -209,17 +210,37 @@
       const char *data;
       NodeInfo *child;
       NodeInfo *complete_child;
+      int save_len;
 
       complete_child = NULL;
+      call = NULL;
       
       child = tmp->data;
 
-      g_assert (*service_name == ':'); /* so we don't need new_for_name_owner */
-      proxy = dbus_g_proxy_new_for_name (connection,
-                                         service_name,
-                                         "/",
-                                         DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE);
-      g_assert (proxy != NULL);
+      save_len = path->len;
+
+      if (save_len > 1)
+        g_string_append (path, "/");
+      g_string_append (path, base_info_get_name ((BaseInfo*)child));
+
+      if (*service_name == ':')
+        {
+          proxy = dbus_g_proxy_new_for_name (connection,
+                                             service_name,
+                                             path->str,
+                                             DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE);
+          g_assert (proxy != NULL);
+        }
+      else
+        {
+          proxy = dbus_g_proxy_new_for_name_owner (connection,
+                                                   service_name,
+                                                   path->str,
+                                                   DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE,
+                                                   error);
+          if (proxy == NULL)
+            goto done;
+        }
   
       call = dbus_g_proxy_begin_call (proxy, "Introspect",
                                       DBUS_TYPE_INVALID);
@@ -231,10 +252,14 @@
       
       complete_child = description_load_from_string (data, -1, error);
       if (complete_child == NULL)
-        goto done;
+        {
+          g_printerr ("%s\n", data);
+          goto done;
+        }
       
     done:
-      dbus_g_pending_call_unref (call);
+      if (call)
+        dbus_g_pending_call_unref (call);
       g_object_unref (proxy);
 
       if (complete_child == NULL)
@@ -249,8 +274,11 @@
       node_info_unref (complete_child); /* ref still held by parent */
       
       /* Now recurse */
-      if (!load_child_nodes (service_name, complete_child, error))
+      if (!load_child_nodes (service_name, complete_child, path, error))
         return FALSE;
+
+      /* restore path */
+      g_string_set_size (path, save_len);
       
       tmp = tmp->next;
     }
@@ -267,21 +295,36 @@
   DBusGPendingCall *call;
   const char *data;
   NodeInfo *node;
+  GString *path;
 
   node = NULL;
   call = NULL;
+  path = NULL;
   
   connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
   if (connection == NULL)
     return NULL;
 
+#if 1
+  /* this will end up autolaunching the service when we introspect it */
+  root_proxy = dbus_g_proxy_new_for_name (connection,
+                                          service_name,
+                                          "/",
+                                          DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE);
+  g_assert (root_proxy != NULL);
+#else
+  /* this will be an error if the service doesn't exist */
   root_proxy = dbus_g_proxy_new_for_name_owner (connection,
                                                 service_name,
                                                 "/",
                                                 DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE,
                                                 error);
   if (root_proxy == NULL)
-    return NULL;
+    {
+      g_printerr ("Failed to get owner of '%s'\n", service_name);
+      return NULL;
+    }
+#endif
   
   call = dbus_g_proxy_begin_call (root_proxy, "Introspect",
                                   DBUS_TYPE_INVALID);
@@ -289,7 +332,11 @@
   data = NULL;
   if (!dbus_g_proxy_end_call (root_proxy, call, error, DBUS_TYPE_STRING, &data,
                               DBUS_TYPE_INVALID))
-    goto out;
+    {
+      g_printerr ("Failed to Introspect() %s\n",
+                  dbus_g_proxy_get_bus_name (root_proxy));
+      goto out;
+    }
 
   node = description_load_from_string (data, -1, error);
 
@@ -299,9 +346,11 @@
     goto out;
 
   base_info_set_name ((BaseInfo*)node, "/");
+
+  path = g_string_new ("/");
   
   if (!load_child_nodes (dbus_g_proxy_get_bus_name (root_proxy),
-                         node, error))
+                         node, path, error))
     {
       node_info_unref (node);
       node = NULL;
@@ -313,6 +362,10 @@
     dbus_g_pending_call_unref (call);
     
   g_object_unref (root_proxy);
+
+  if (path)
+    g_string_free (path, TRUE);
+  
   return node;
 }
 



More information about the dbus-commit mailing list