dbus/bus driver.c,1.78,1.79 driver.h,1.9,1.10 main.c,1.32,1.33

John Palmieri johnp at kemper.freedesktop.org
Wed Sep 6 14:16:14 PDT 2006


Update of /cvs/dbus/dbus/bus
In directory kemper:/tmp/cvs-serv20276/bus

Modified Files:
	driver.c driver.h main.c 
Log Message:
* bus/driver.c:
  (bus_driver_generate_introspect_string): New method for populating
  a DBusString with the introspect data
  (bus_driver_handle_introspect): Move introspect generation code to 
  bus_driver_generate_introspect_string

* bus/main.c:
  (introspect): New function which prints out the intropect data and
  exits
  (main): Add a --introspect switch


Index: driver.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/driver.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- driver.c	6 Sep 2006 00:14:06 -0000	1.78
+++ driver.c	6 Sep 2006 21:16:12 -0000	1.79
@@ -1493,125 +1493,134 @@
   return FALSE;
 }
 
-static dbus_bool_t
-bus_driver_handle_introspect (DBusConnection *connection,
-                              BusTransaction *transaction,
-                              DBusMessage    *message,
-                              DBusError      *error)
+dbus_bool_t
+bus_driver_generate_introspect_string (DBusString *xml)
 {
-  DBusString xml;
-  DBusMessage *reply;
-  const char *v_STRING;
   int i;
 
-  _dbus_verbose ("Introspect() on bus driver\n");
-  
-  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
-  reply = NULL;
-
-  if (! dbus_message_get_args (message, error,
-			       DBUS_TYPE_INVALID))
-    {
-      _DBUS_ASSERT_ERROR_IS_SET (error);
-      return FALSE;
-    }
-
-  if (!_dbus_string_init (&xml))
-    {
-      BUS_SET_OOM (error);
-      return FALSE;
-    }
-
-  if (!_dbus_string_append (&xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
-    goto oom;
-  if (!_dbus_string_append (&xml, "<node>\n"))
-    goto oom;
-  if (!_dbus_string_append_printf (&xml, "  <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
-    goto oom;
-  if (!_dbus_string_append (&xml, "    <method name=\"Introspect\">\n"))
-    goto oom;
-  if (!_dbus_string_append_printf (&xml, "      <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
-    goto oom;
-  if (!_dbus_string_append (&xml, "    </method>\n"))
-    goto oom;
-  if (!_dbus_string_append (&xml, "  </interface>\n"))
-    goto oom;
+  if (!_dbus_string_append (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
+    return FALSE;
+  if (!_dbus_string_append (xml, "<node>\n"))
+    return FALSE;
+  if (!_dbus_string_append_printf (xml, "  <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
+    return FALSE;
+  if (!_dbus_string_append (xml, "    <method name=\"Introspect\">\n"))
+    return FALSE;
+  if (!_dbus_string_append_printf (xml, "      <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
+    return FALSE;
+  if (!_dbus_string_append (xml, "    </method>\n"))
+    return FALSE;
+  if (!_dbus_string_append (xml, "  </interface>\n"))
+    return FALSE;
 
-  if (!_dbus_string_append_printf (&xml, "  <interface name=\"%s\">\n",
+  if (!_dbus_string_append_printf (xml, "  <interface name=\"%s\">\n",
                                    DBUS_INTERFACE_DBUS))
-    goto oom;
+    return FALSE;
 
   i = 0;
   while (i < _DBUS_N_ELEMENTS (message_handlers))
     {
 	  
-      if (!_dbus_string_append_printf (&xml, "    <method name=\"%s\">\n",
+      if (!_dbus_string_append_printf (xml, "    <method name=\"%s\">\n",
                                        message_handlers[i].name))
-        goto oom;
+        return FALSE;
 
-      if (!write_args_for_direction (&xml, message_handlers[i].in_args, TRUE))
-	goto oom;
+      if (!write_args_for_direction (xml, message_handlers[i].in_args, TRUE))
+	return FALSE;
 
-      if (!write_args_for_direction (&xml, message_handlers[i].out_args, FALSE))
-	goto oom;
+      if (!write_args_for_direction (xml, message_handlers[i].out_args, FALSE))
+	return FALSE;
 
-      if (!_dbus_string_append (&xml, "    </method>\n"))
-	goto oom;
+      if (!_dbus_string_append (xml, "    </method>\n"))
+	return FALSE;
       
       ++i;
     }
 
-  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameOwnerChanged\">\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "    <signal name=\"NameOwnerChanged\">\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "      <arg type=\"s\"/>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "      <arg type=\"s\"/>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "      <arg type=\"s\"/>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "    </signal>\n"))
+    return FALSE;
 
 
 
-  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameLost\">\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "    <signal name=\"NameLost\">\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "      <arg type=\"s\"/>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "    </signal>\n"))
+    return FALSE;
 
 
 
-  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameAcquired\">\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "    <signal name=\"NameAcquired\">\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
-    goto oom;
+  if (!_dbus_string_append_printf (xml, "      <arg type=\"s\"/>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
-    goto oom;
-
+  if (!_dbus_string_append_printf (xml, "    </signal>\n"))
+    return FALSE;
 
+  if (!_dbus_string_append (xml, "  </interface>\n"))
+    return FALSE;
   
-  if (!_dbus_string_append (&xml, "  </interface>\n"))
-    goto oom;
+  if (!_dbus_string_append (xml, "</node>\n"))
+    return FALSE;
+
+  return TRUE;
+}
+
+static dbus_bool_t
+bus_driver_handle_introspect (DBusConnection *connection,
+                              BusTransaction *transaction,
+                              DBusMessage    *message,
+                              DBusError      *error)
+{
+  DBusString xml;
+  DBusMessage *reply;
+  const char *v_STRING;
+
+  _dbus_verbose ("Introspect() on bus driver\n");
   
-  if (!_dbus_string_append (&xml, "</node>\n"))
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  reply = NULL;
+
+  if (! dbus_message_get_args (message, error,
+			       DBUS_TYPE_INVALID))
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      return FALSE;
+    }
+
+  if (!_dbus_string_init (&xml))
+    {
+      BUS_SET_OOM (error);
+      return FALSE;
+    }
+
+  if (!bus_driver_generate_introspect_string (&xml))
     goto oom;
 
+  v_STRING = _dbus_string_get_const_data (&xml);
+
   reply = dbus_message_new_method_return (message);
   if (reply == NULL)
     goto oom;
 
-  v_STRING = _dbus_string_get_const_data (&xml);
   if (! dbus_message_append_args (reply,
                                   DBUS_TYPE_STRING, &v_STRING,
                                   DBUS_TYPE_INVALID))

Index: driver.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/driver.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- driver.h	24 Sep 2004 10:43:35 -0000	1.9
+++ driver.h	6 Sep 2006 21:16:12 -0000	1.10
@@ -45,5 +45,8 @@
 						    const char     *new_owner,
 						    BusTransaction *transaction,
 						    DBusError      *error);
+dbus_bool_t bus_driver_generate_introspect_string  (DBusString *xml);
+
+
 
 #endif /* BUS_DRIVER_H */

Index: main.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/main.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- main.c	3 Aug 2006 20:34:36 -0000	1.32
+++ main.c	6 Sep 2006 21:16:12 -0000	1.33
@@ -21,6 +21,7 @@
  *
  */
 #include "bus.h"
+#include "driver.h"
 #include <dbus/dbus-internals.h>
 #include <dbus/dbus-watch.h>
 #include <stdio.h>
@@ -66,7 +67,7 @@
 static void
 usage (void)
 {
-  fprintf (stderr, DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork]\n");
+  fprintf (stderr, DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect]\n");
   exit (1);
 }
 
@@ -82,6 +83,30 @@
 }
 
 static void
+introspect (void)
+{
+  DBusString xml;
+  const char *v_STRING;  
+
+  if (!_dbus_string_init (&xml))
+    goto oom;
+
+  if (!bus_driver_generate_introspect_string (&xml))
+    {
+      _dbus_string_free (&xml);
+      goto oom;
+    }
+
+  v_STRING = _dbus_string_get_const_data (&xml);
+  printf ("%s\n", v_STRING); 
+
+  exit (0);
+ 
+ oom:
+  _dbus_warn ("Can not introspect - Out of memory\n");
+  exit (1);
+}
+static void
 check_two_config_files (const DBusString *config_file,
                         const char       *extra_arg)
 {
@@ -231,6 +256,8 @@
         usage ();
       else if (strcmp (arg, "--version") == 0)
         version ();
+      else if (strcmp (arg, "--introspect") == 0)
+        introspect ();
       else if (strcmp (arg, "--nofork") == 0)
         force_fork = FORK_NEVER;
       else if (strcmp (arg, "--fork") == 0)



More information about the dbus-commit mailing list