dbus/tools dbus-viewer.c,1.4,1.5
Havoc Pennington
hp at freedesktop.org
Sat Jan 29 21:18:46 PST 2005
Update of /cvs/dbus/dbus/tools
In directory gabe:/tmp/cvs-serv13826/tools
Modified Files:
dbus-viewer.c
Log Message:
2005-01-30 Havoc Pennington <hp at redhat.com>
dbus-viewer introspected and displayed the bus driver
* dbus/dbus-object-tree.c
(object_tree_test_iteration): add tests for a handler registered on "/"
* dbus/dbus-object-tree.c
(_dbus_decompose_path): fix to handle path "/" properly
(run_decompose_tests): add tests for path decomposition
* glib/dbus-gutils.c (_dbus_gutils_split_path): fix to handle "/"
properly
* glib/dbus-gobject.c (handle_introspect): fix quotes
* test/glib/run-test.sh: support launching the bus, then running
dbus-viewer
* test/glib/test-service-glib.c (main): put in a trivial gobject
subclass and register it on the connection
* bus/driver.c (bus_driver_handle_introspect): implement
introspection of the bus driver service
* dbus/dbus-protocol.h: add #defines for the XML namespace,
identifiers, doctype decl
* bus/driver.c (bus_driver_handle_get_service_owner): handle
attempts to get owner of DBUS_SERVICE_ORG_FREEDESKTOP_DBUS by
returning the service unchanged.
(bus_driver_handle_message): remove old check for reply_serial in
method calls, now the message type deals with that
(bus_driver_handle_message): handle NULL interface
* glib/dbus-gproxy.c (dbus_g_proxy_get_bus_name): new function
* glib/dbus-gloader-expat.c (description_load_from_string): allow
-1 for len
* tools/dbus-viewer.c: add support for introspecting a service on
a bus
* glib/dbus-gproxy.c (dbus_g_pending_call_ref): add
(dbus_g_pending_call_unref): add
Index: dbus-viewer.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-viewer.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dbus-viewer.c 10 Aug 2004 03:07:01 -0000 1.4
+++ dbus-viewer.c 30 Jan 2005 05:18:44 -0000 1.5
@@ -29,6 +29,7 @@
#include "dbus-tree-view.h"
#include <glib/dbus-gparser.h>
#include <glib/dbus-gutils.h>
+#include <dbus/dbus-glib.h>
#include <libintl.h>
#define _(x) dgettext (GETTEXT_PACKAGE, x)
@@ -188,6 +189,133 @@
}
}
+static gboolean
+load_child_nodes (const char *service_name,
+ NodeInfo *parent,
+ GError **error)
+{
+ DBusGConnection *connection;
+ GSList *tmp;
+
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+ if (connection == NULL)
+ return FALSE;
+
+ tmp = node_info_get_nodes (parent);
+ while (tmp != NULL)
+ {
+ DBusGProxy *proxy;
+ DBusGPendingCall *call;
+ const char *data;
+ NodeInfo *child;
+ NodeInfo *complete_child;
+
+ complete_child = 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);
+
+ call = dbus_g_proxy_begin_call (proxy, "Introspect",
+ DBUS_TYPE_INVALID);
+
+ data = NULL;
+ if (!dbus_g_proxy_end_call (proxy, call, error, DBUS_TYPE_STRING, &data,
+ DBUS_TYPE_INVALID))
+ goto done;
+
+ complete_child = description_load_from_string (data, -1, error);
+ if (complete_child == NULL)
+ goto done;
+
+ done:
+ dbus_g_pending_call_unref (call);
+ g_object_unref (proxy);
+
+ if (complete_child == NULL)
+ return FALSE;
+
+ /* change complete_child's name to relative */
+ base_info_set_name ((BaseInfo*)complete_child,
+ base_info_get_name ((BaseInfo*)child));
+
+ /* Stitch in complete_child rather than child */
+ node_info_replace_node (parent, child, complete_child);
+ node_info_unref (complete_child); /* ref still held by parent */
+
+ /* Now recurse */
+ if (!load_child_nodes (service_name, complete_child, error))
+ return FALSE;
+
+ tmp = tmp->next;
+ }
+
+ return TRUE;
+}
+
+static NodeInfo*
+load_from_service (const char *service_name,
+ GError **error)
+{
+ DBusGConnection *connection;
+ DBusGProxy *root_proxy;
+ DBusGPendingCall *call;
+ const char *data;
+ NodeInfo *node;
+
+ node = NULL;
+ call = NULL;
+
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+ if (connection == NULL)
+ return NULL;
+
+ root_proxy = dbus_g_proxy_new_for_name_owner (connection,
+ service_name,
+ "/",
+ DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE,
+ error);
+ if (root_proxy == NULL)
+ return NULL;
+
+ call = dbus_g_proxy_begin_call (root_proxy, "Introspect",
+ DBUS_TYPE_INVALID);
+
+ data = NULL;
+ if (!dbus_g_proxy_end_call (root_proxy, call, error, DBUS_TYPE_STRING, &data,
+ DBUS_TYPE_INVALID))
+ goto out;
+
+ node = description_load_from_string (data, -1, error);
+
+ /* g_print ("%s\n", data); */
+
+ if (node == NULL)
+ goto out;
+
+ base_info_set_name ((BaseInfo*)node, "/");
+
+ if (!load_child_nodes (dbus_g_proxy_get_bus_name (root_proxy),
+ node, error))
+ {
+ node_info_unref (node);
+ node = NULL;
+ goto out;
+ }
+
+ out:
+ if (call)
+ dbus_g_pending_call_unref (call);
+
+ g_object_unref (root_proxy);
+ return node;
+}
+
static void
usage (int ecode)
{
@@ -214,6 +342,7 @@
GSList *files;
gboolean end_of_args;
GSList *tmp;
+ gboolean services;
bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -221,6 +350,7 @@
gtk_init (&argc, &argv);
+ services = FALSE;
end_of_args = FALSE;
files = NULL;
prev_arg = NULL;
@@ -237,6 +367,8 @@
usage (0);
else if (strcmp (arg, "--version") == 0)
version ();
+ else if (strcmp (arg, "--services") == 0)
+ services = TRUE;
else if (arg[0] == '-' &&
arg[1] == '-' &&
arg[2] == '\0')
@@ -270,8 +402,12 @@
filename = tmp->data;
error = NULL;
- node = description_load_from_file (filename,
- &error);
+ if (services)
+ node = load_from_service (filename, &error);
+ else
+ node = description_load_from_file (filename,
+ &error);
+
if (node == NULL)
{
g_assert (error != NULL);
@@ -313,8 +449,3 @@
return 0;
}
-
-
-
-
-
More information about the dbus-commit
mailing list