dbus/tools dbus-monitor.1,1.4,1.5 dbus-monitor.c,1.14,1.15
Robert McQueen
robot101 at freedesktop.org
Sat Oct 29 10:03:00 PDT 2005
Update of /cvs/dbus/dbus/tools
In directory gabe:/tmp/cvs-serv19982/tools
Modified Files:
dbus-monitor.1 dbus-monitor.c
Log Message:
2005-10-29 Robert McQueen <robot101 at debian.org>
* glib/Makefile.am, glib/examples/Makefile.am,
glib/examples/statemachine/Makefile.am: Merge patch from Ubuntu by
Daniel Stone to replace explicit calls to libtool with $(LIBTOOL).
* test/python/.cvsignore: Add run-with-tmp-session-bus.conf.
* tools/dbus-monitor.1, tools/dbus-monitor.c: Merge dbus-monitor patch
from Ubuntu by Daniel Silverstone to allow specifying match rules on
the command line.
Index: dbus-monitor.1
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-monitor.1,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dbus-monitor.1 21 Jun 2003 22:20:30 -0000 1.4
+++ dbus-monitor.1 29 Oct 2005 17:02:58 -0000 1.5
@@ -9,6 +9,7 @@
.PP
.B dbus-monitor
[\-\-system | \-\-session]
+[watch expressions]
.SH DESCRIPTION
@@ -25,6 +26,11 @@
monitor the system or session buses respectively. If neither is
specified, \fIdbus-monitor\fP monitors the session bus.
+.PP
+In order to get \fIdbus-monitor\fP to see the messages you are interested
+in, you should specify a set of watch expressions as you would expect to
+be passed to the \fIdbus_bus_add_watch\fP function.
+
.PP
The message bus configuration may keep \fIdbus-monitor\fP from seeing
all messages, especially if you run the monitor as a non-root user.
@@ -37,6 +43,15 @@
.I "--session"
Monitor the session message bus. (This is the default.)
+.SH EXAMPLE
+Here is an example of using dbus-monitor to watch for the gnome typing
+monitor to say things
+.nf
+
+ dbus-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
+
+.fi
+
.SH AUTHOR
dbus-monitor was written by Philip Blundell.
Index: dbus-monitor.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-monitor.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- dbus-monitor.c 6 Jul 2005 21:27:45 -0000 1.14
+++ dbus-monitor.c 29 Oct 2005 17:02:58 -0000 1.15
@@ -49,7 +49,7 @@
static void
usage (char *name, int ecode)
{
- fprintf (stderr, "Usage: %s [--system | --session]\n", name);
+ fprintf (stderr, "Usage: %s [--system | --session] [watch expressions]\n", name);
exit (ecode);
}
@@ -60,8 +60,8 @@
DBusError error;
DBusBusType type = DBUS_BUS_SESSION;
GMainLoop *loop;
- int i;
-
+ int i = 0, j = 0, numFilters = 0;
+ char **filters = NULL;
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
@@ -73,14 +73,18 @@
else if (!strcmp (arg, "--help"))
usage (argv[0], 0);
else if (!strcmp (arg, "--"))
- break;
+ continue;
else if (arg[0] == '-')
usage (argv[0], 1);
+ else {
+ numFilters++;
+ filters = (char **)realloc(filters, numFilters * sizeof(char *));
+ filters[j] = (char *)malloc((strlen(arg) + 1) * sizeof(char *));
+ snprintf(filters[j], strlen(arg) + 1, "%s", arg);
+ j++;
+ }
}
- if (argc > 2)
- usage (argv[0], 1);
-
loop = g_main_loop_new (NULL, FALSE);
dbus_error_init (&error);
@@ -96,26 +100,45 @@
dbus_connection_setup_with_g_main (connection, NULL);
- dbus_bus_add_match (connection,
- "type='signal'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='method_call'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='method_return'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='error'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
+ if (numFilters)
+ {
+ for (i = 0; i < j; i++)
+ {
+ dbus_bus_add_match (connection, filters[i], &error);
+ if (dbus_error_is_set (&error))
+ {
+ fprintf (stderr, "Failed to setup match \"%s\": %s\n",
+ filters[i], error.message);
+ dbus_error_free (&error);
+ exit (1);
+ }
+ free(filters[i]);
+ }
+ }
+ else
+ {
+ dbus_bus_add_match (connection,
+ "type='signal'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='method_call'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='method_return'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='error'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ }
+
if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) {
fprintf (stderr, "Couldn't add filter!\n");
exit (1);
More information about the dbus-commit
mailing list