From a65587676f6791ff6a7c9ed98bbc53d740f51fa8 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 17 Mar 2005 17:48:29 +0000 Subject: 2005-03-17 Colin Walters * bus/print-introspect.c: Move to tools/. * bus/run-with-tmp-session-bus.sh: Ditto. * glib/Makefile.am (dbus-glib-bindings.h): Move generation to tools/Makefile.am. * test/glib/run-test.sh: Update to handle move of run-with-tmp-session-bus.sh. * test/glib/test-service-glib.c: Update to handle move of dbus-glib-bindings.h. * tools/print-introspect.c: Moved here from bus/, and ported to GLib bindings. * tools/run-with-tmp-session-bus.sh: Moved here from bus/. * tools/Makefile.am: Generate dbus-glib-bindings.h and dbus-bus-introspect.xml here. * tools/.cvsignore, glib/.cvsignore, bus/.cvsignore: Update. --- tools/print-introspect.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tools/print-introspect.c (limited to 'tools/print-introspect.c') diff --git a/tools/print-introspect.c b/tools/print-introspect.c new file mode 100644 index 00000000..9784af00 --- /dev/null +++ b/tools/print-introspect.c @@ -0,0 +1,83 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* gather-introspect.c Dump introspection data from service to stdout + * + * Copyright (C) 2005 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include + +#include + +static void +usage (char *name, int ecode) +{ + fprintf (stderr, "Usage: %s \n", name); + exit (ecode); +} + +int +main (int argc, char *argv[]) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + DBusGPendingCall *call; + GError *error; + const char *service; + const char *path; + const char *introspect_data; + + if (argc != 3) + usage (argv[0], 1); + + service = argv[1]; + path = argv[2]; + + g_type_init (); + + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (connection == NULL) + { + fprintf (stderr, "Failed to open connection to session bus: %s\n", + error->message); + g_clear_error (&error); + exit (1); + } + + proxy = dbus_g_proxy_new_for_name (connection, + service, path, + DBUS_INTERFACE_INTROSPECTABLE); + call = dbus_g_proxy_begin_call (proxy, "Introspect", DBUS_TYPE_INVALID); + if (!dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_STRING, + &introspect_data, DBUS_TYPE_INVALID)) + { + fprintf (stderr, "Failed to get introspection data: %s\n", + error->message); + g_clear_error (&error); + exit (1); + } + + printf ("%s", introspect_data); + + dbus_g_pending_call_unref (call); + g_object_unref (proxy); + + exit (0); +} -- cgit