summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/test-bus-chat.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-31 16:16:37 +0200
committerLennart Poettering <lennart@poettering.net>2013-03-31 16:16:37 +0200
commit392d5b378ceae5e1fd7c91ca545fcf4cd105744a (patch)
treee231fe77155323de76b535cd509ee5677f1bf28f /src/libsystemd-bus/test-bus-chat.c
parent11c4c2492083325531aeb3eeb9b041c929677890 (diff)
bus: parse matches locally and allow registration of callbacks for them
This includes code to parse and split up match strings which will also be useful to calculate bloom filter masks when the time comes.
Diffstat (limited to 'src/libsystemd-bus/test-bus-chat.c')
-rw-r--r--src/libsystemd-bus/test-bus-chat.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c
index 906a7e646c..2dd30912cf 100644
--- a/src/libsystemd-bus/test-bus-chat.c
+++ b/src/libsystemd-bus/test-bus-chat.c
@@ -32,6 +32,13 @@
#include "sd-bus.h"
#include "bus-message.h"
#include "bus-error.h"
+#include "bus-match.h"
+#include "bus-internal.h"
+
+static int match_callback(sd_bus *bus, int error, sd_bus_message *m, void *userdata) {
+ log_info("Match triggered! interface=%s member=%s", strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member(m)));
+ return 0;
+}
static int object_callback(sd_bus *bus, int error, sd_bus_message *m, void *userdata) {
int r;
@@ -106,6 +113,20 @@ static int server_init(sd_bus **_bus) {
goto fail;
}
+ r = sd_bus_add_match(bus, "type='signal',interface='foo.bar',member='Notify'", match_callback, NULL);
+ if (r < 0) {
+ log_error("Failed to add match: %s", strerror(-r));
+ goto fail;
+ }
+
+ r = sd_bus_add_match(bus, "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged'", match_callback, NULL);
+ if (r < 0) {
+ log_error("Failed to add match: %s", strerror(-r));
+ goto fail;
+ }
+
+ bus_match_dump(&bus->match_callbacks, 0);
+
*_bus = bus;
return 0;
@@ -424,6 +445,26 @@ static void* client2(void*p) {
sd_bus_message_unref(m);
m = NULL;
+ r = sd_bus_message_new_signal(
+ bus,
+ "/foobar",
+ "foo.bar",
+ "Notify",
+ &m);
+ if (r < 0) {
+ log_error("Failed to allocate signal: %s", strerror(-r));
+ goto finish;
+ }
+
+ r = sd_bus_send(bus, m, NULL);
+ if (r < 0) {
+ log_error("Failed to issue signal: %s", bus_error_message(&error, -r));
+ goto finish;
+ }
+
+ sd_bus_message_unref(m);
+ m = NULL;
+
r = sd_bus_message_new_method_call(
bus,
"org.freedesktop.systemd.test",