summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2005-03-12 16:33:01 +0000
committerColin Walters <walters@verbum.org>2005-03-12 16:33:01 +0000
commit3dea5c183f65c3f924fb442bf606dfeb50f028a4 (patch)
tree0ac180fdc5c7766d003863717ef6cbeff8237806 /bus
parent3c1d2d65654f92f24d3e5c9c5b88d76a10f72822 (diff)
2005-03-11 Colin Walters <walters@verbum.org>
* glib/Makefile.am: Generate dbus-glib-bindings.h and install it. * bus/print-introspect.c: New file; prints introspection data for a given name and object path. * bus/run-with-tmp-session-bus.sh: New file, refactored from test/glib/run-test.sh. Creates a temporary session bus and runs another program. * test/glib/run-test.sh: Refactor to invoke run-with-tmp-session-bus.sh. * bus/driver.c (bus_driver_handle_introspect): Fix to print new introspection format. Also change to use DBUS_TYPE_x_AS_STRING macros instead of hardcoding. * glib/.cvsignore, bus/.cvsignore, test/glib/.cvsignore: Update.
Diffstat (limited to 'bus')
-rw-r--r--bus/.cvsignore3
-rw-r--r--bus/Makefile.am15
-rw-r--r--bus/driver.c16
-rw-r--r--bus/print-introspect.c104
-rwxr-xr-xbus/run-with-tmp-session-bus.sh65
5 files changed, 193 insertions, 10 deletions
diff --git a/bus/.cvsignore b/bus/.cvsignore
index e522ea23..2c6c9b7e 100644
--- a/bus/.cvsignore
+++ b/bus/.cvsignore
@@ -14,4 +14,7 @@ rc.messagebus
messagebus
session.conf
system.conf
+run-with-tmp-session-bus.conf
dbus-daemon.1
+print-introspect
+dbus-bus-introspect.xml
diff --git a/bus/Makefile.am b/bus/Makefile.am
index b6480856..f6e04ee7 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -77,7 +77,7 @@ endif
## we use noinst_PROGRAMS not check_PROGRAMS so that we build
## even when not doing "make check"
-noinst_PROGRAMS=$(TESTS)
+noinst_PROGRAMS=$(TESTS) print-introspect
bus_test_SOURCES= \
$(BUS_SOURCES) \
@@ -85,9 +85,20 @@ bus_test_SOURCES= \
bus_test_LDADD=$(top_builddir)/dbus/libdbus-convenience.la $(DBUS_BUS_LIBS)
+print_introspect_SOURCES = print-introspect.c
+print_introspect_LDADD = $(top_builddir)/dbus/libdbus-convenience.la $(DBUS_BUS_LIBS)
+
+run-with-tmp-session-bus.sh: dbus-daemon
+
+all-local: dbus-bus-introspect.xml
+
+dbus-bus-introspect.xml: $(srcdir)/run-with-tmp-session-bus.sh
+ DBUS_TOP_BUILDDIR=$(top_builddir) $(srcdir)/run-with-tmp-session-bus.sh ./print-introspect org.freedesktop.DBus /org/freedesktop/DBus > dbus-bus-introspect.xml.tmp && mv dbus-bus-introspect.xml.tmp dbus-bus-introspect.xml
+
## mop up the gcov files
clean-local:
/bin/rm *.bb *.bbg *.da *.gcov || true
+ /bin/rm -f run-with-tmp-session-bus.conf
install-data-hook:
$(mkinstalldirs) $(DESTDIR)/$(localstatedir)/run/dbus
@@ -125,4 +136,4 @@ man_MANS = dbus-daemon.1
#### Extra dist
-EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES) $(man_MANS) $(MAN_IN_FILES)
+EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES) $(man_MANS) $(MAN_IN_FILES) run-with-tmp-session-bus.sh
diff --git a/bus/driver.c b/bus/driver.c
index 25ce0f94..e647fbf3 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -1136,7 +1136,7 @@ bus_driver_handle_introspect (DBusConnection *connection,
goto oom;
if (!_dbus_string_append (&xml, " <method name=\"Introspect\">\n"))
goto oom;
- if (!_dbus_string_append (&xml, " <arg name=\"data\" direction=\"out\" type=\"string\"/>\n"))
+ 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;
@@ -1163,15 +1163,15 @@ bus_driver_handle_introspect (DBusConnection *connection,
else if (strcmp (message_handlers[i].in_args,
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING) == 0)
{
- if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"string\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
goto oom;
- if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"uint32\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_UINT32_AS_STRING))
goto oom;
}
else if (strcmp (message_handlers[i].in_args,
DBUS_TYPE_STRING_AS_STRING) == 0)
{
- if (!_dbus_string_append (&xml, " <arg direction=\"in\" type=\"string\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"in\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
goto oom;
}
else
@@ -1186,26 +1186,26 @@ bus_driver_handle_introspect (DBusConnection *connection,
else if (strcmp (message_handlers[i].out_args,
DBUS_TYPE_STRING_AS_STRING) == 0)
{
- if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"string\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
goto oom;
}
else if (strcmp (message_handlers[i].out_args,
DBUS_TYPE_BOOLEAN_AS_STRING) == 0)
{
- if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"boolean\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_BOOLEAN_AS_STRING))
goto oom;
}
else if (strcmp (message_handlers[i].out_args,
DBUS_TYPE_UINT32_AS_STRING) == 0)
{
- if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"uint32\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_UINT32_AS_STRING))
goto oom;
}
else if (strcmp (message_handlers[i].out_args,
DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING) == 0)
{
/* FIXME introspection format doesn't handle arrays yet */
- if (!_dbus_string_append (&xml, " <arg direction=\"out\" type=\"string\"/>\n"))
+ if (!_dbus_string_append_printf (&xml, " <arg direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
goto oom;
}
else
diff --git a/bus/print-introspect.c b/bus/print-introspect.c
new file mode 100644
index 00000000..c040af41
--- /dev/null
+++ b/bus/print-introspect.c
@@ -0,0 +1,104 @@
+/* -*- 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dbus/dbus.h>
+
+static void
+usage (char *name, int ecode)
+{
+ fprintf (stderr, "Usage: %s <service> <destination object path>\n", name);
+ exit (ecode);
+}
+
+int
+main (int argc, char *argv[])
+{
+ DBusConnection *connection;
+ DBusError error;
+ DBusMessage *message;
+ DBusMessage *reply;
+ const char *service;
+ const char *path;
+ const char *introspect_data;
+
+ if (argc != 3)
+ usage (argv[0], 1);
+
+ service = argv[1];
+ path = argv[2];
+
+ dbus_error_init (&error);
+ connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if (connection == NULL)
+ {
+ fprintf (stderr, "Failed to open connection to session bus: %s\n",
+ error.message);
+ dbus_error_free (&error);
+ exit (1);
+ }
+
+ message = dbus_message_new_method_call (NULL,
+ path,
+ DBUS_INTERFACE_INTROSPECTABLE,
+ "Introspect");
+ if (message == NULL)
+ {
+ fprintf (stderr, "Couldn't allocate D-BUS message\n");
+ exit (1);
+ }
+
+ if (!dbus_message_set_destination (message, service))
+ {
+ fprintf (stderr, "Not enough memory\n");
+ exit (1);
+ }
+
+ reply = dbus_connection_send_with_reply_and_block (connection,
+ message,
+ -1,
+ &error);
+ dbus_message_unref (message);
+ if (dbus_error_is_set (&error))
+ {
+ fprintf (stderr, "Error: %s\n", error.message);
+ exit (1);
+ }
+
+ if (!dbus_message_get_args (reply, &error,
+ DBUS_TYPE_STRING,
+ &introspect_data,
+ DBUS_TYPE_INVALID))
+ {
+ fprintf (stderr, "Error: %s\n", error.message);
+ exit (1);
+ }
+ printf ("%s", introspect_data);
+
+ dbus_message_unref (reply);
+
+ dbus_connection_disconnect (connection);
+
+ exit (0);
+}
diff --git a/bus/run-with-tmp-session-bus.sh b/bus/run-with-tmp-session-bus.sh
new file mode 100755
index 00000000..ce077d72
--- /dev/null
+++ b/bus/run-with-tmp-session-bus.sh
@@ -0,0 +1,65 @@
+#! /bin/bash
+
+SCRIPTNAME=$0
+WRAPPED_SCRIPT=$1
+shift
+
+function die()
+{
+ if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+ echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+ kill -9 $DBUS_SESSION_BUS_PID
+ fi
+ echo $SCRIPTNAME: $* >&2
+ exit 1
+}
+
+if test -z "$DBUS_TOP_BUILDDIR" ; then
+ die "Must set DBUS_TOP_BUILDDIR"
+fi
+
+## convenient to be able to ctrl+C without leaking the message bus process
+trap 'die "Received SIGINT"' SIGINT
+
+CONFIG_FILE=./run-with-tmp-session-bus.conf
+SERVICE_DIR="$DBUS_TOP_BUILDDIR/test/data/valid-service-files"
+ESCAPED_SERVICE_DIR=`echo $SERVICE_DIR | sed -e 's/\//\\\\\\//g'`
+echo "escaped service dir is: $ESCAPED_SERVICE_DIR" >&2
+
+## create a configuration file based on the standard session.conf
+cat $DBUS_TOP_BUILDDIR/bus/session.conf | \
+ sed -e 's/<servicedir>.*$/<servicedir>'$ESCAPED_SERVICE_DIR'<\/servicedir>/g' | \
+ sed -e 's/<include.*$//g' \
+ > $CONFIG_FILE
+
+echo "Created configuration file $CONFIG_FILE" >&2
+
+export PATH=$DBUS_TOP_BUILDDIR/bus:$PATH
+## the libtool script found by the path search should already do this, but
+export LD_LIBRARY_PATH=$DBUS_TOP_BUILDDIR/dbus/.libs:$LD_LIBRARY_PATH
+
+unset DBUS_SESSION_BUS_ADDRESS
+unset DBUS_SESSION_BUS_PID
+
+echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
+
+eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
+
+if test -z "$DBUS_SESSION_BUS_PID" ; then
+ die "Failed to launch message bus for introspection generation to run"
+fi
+
+echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
+
+# Execute wrapped script
+echo "Running $WRAPPED_SCRIPT $@" >&2
+$WRAPPED_SCRIPT "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
+
+kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
+
+sleep 2
+
+## be sure it really died
+kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
+
+exit 0