aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dbus/dbus/dbus-monitor.patch
blob: c2f90c885b550013f9bf7954c1c6adcd260ad3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
diff -urN dbus-0.22.orig/tools/dbus-monitor.1 dbus-0.22/tools/dbus-monitor.1
--- dbus-0.22.orig/tools/dbus-monitor.1	2004-10-10 20:47:19.906823680 +1000
+++ dbus-0.22/tools/dbus-monitor.1	2004-10-10 20:47:27.791625008 +1000
@@ -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.
 
--- dbus-0.22-1ubuntu1/tools/dbus-monitor.c	2004-08-10 13:03:37.000000000 +1000
+++ dbus-0.22/tools/dbus-monitor.c	2004-10-10 21:38:08.532362152 +1000
@@ -45,7 +45,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);
 }
 
@@ -56,8 +56,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];
@@ -69,14 +69,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);
@@ -92,26 +102,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);