summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/test-bus-chat.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 05:58:47 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 15:46:49 +0100
commita652755d2e8c2ddb31eb281f4585a3edbb333338 (patch)
treefaa7e96e608b9f42e9bfd13b2c2c893d8b8c20c6 /src/libsystemd-bus/test-bus-chat.c
parent3cbb76ee3469998771b4e9c7ee85d8d7407a2f5a (diff)
bus: implement object handler registry
Diffstat (limited to 'src/libsystemd-bus/test-bus-chat.c')
-rw-r--r--src/libsystemd-bus/test-bus-chat.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c
index 23b00c7201..92fdd13faf 100644
--- a/src/libsystemd-bus/test-bus-chat.c
+++ b/src/libsystemd-bus/test-bus-chat.c
@@ -31,6 +31,37 @@
#include "bus-message.h"
#include "bus-error.h"
+static int object_callback(sd_bus *bus, int error, sd_bus_message *m, void *userdata) {
+ int r;
+
+ assert(bus);
+
+ if (error != 0)
+ return 0;
+
+ if (sd_bus_message_is_method_call(m, "org.object.test", "Foobar")) {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+
+ log_info("Invoked Foobar() on %s", sd_bus_message_get_path(m));
+
+ r = sd_bus_message_new_method_return(bus, m, &reply);
+ if (r < 0) {
+ log_error("Failed to allocate return: %s", strerror(-r));
+ return r;
+ }
+
+ r = sd_bus_send(bus, reply, NULL);
+ if (r < 0) {
+ log_error("Failed to send reply: %s", strerror(-r));
+ return r;
+ }
+
+ return 1;
+ }
+
+ return 0;
+}
+
static int server_init(sd_bus **_bus) {
sd_bus *bus = NULL;
sd_id128_t id;
@@ -67,6 +98,12 @@ static int server_init(sd_bus **_bus) {
goto fail;
}
+ r = sd_bus_add_fallback(bus, "/foo/bar", object_callback, NULL);
+ if (r < 0) {
+ log_error("Failed to add object: %s", strerror(-r));
+ goto fail;
+ }
+
*_bus = bus;
return 0;
@@ -297,6 +334,27 @@ static void* client2(void*p) {
r = sd_bus_message_new_method_call(
bus,
"org.freedesktop.systemd.test",
+ "/foo/bar/waldo/piep",
+ "org.object.test",
+ "Foobar",
+ &m);
+ if (r < 0) {
+ log_error("Failed to allocate method call: %s", strerror(-r));
+ goto finish;
+ }
+
+ r = sd_bus_send(bus, m, NULL);
+ if (r < 0) {
+ log_error("Failed to issue method call: %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",
"/",
"org.freedesktop.DBus.Peer",
"GetMachineId",