summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-05 04:15:39 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-05 04:15:39 +0200
commit917b5dc7075a15bded4948efba8e686dba4509f8 (patch)
treeede8ff56bbd196da3c124f71a242d9bc5c31ce71 /src/libsystemd-bus
parent7286037fd438e93137571fa68a741cc894d8e549 (diff)
bus: add convenience functions for constructing and sending method calls/signals in one call
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-message.c12
-rw-r--r--src/libsystemd-bus/bus-message.h2
-rw-r--r--src/libsystemd-bus/sd-bus.c57
3 files changed, 65 insertions, 6 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 773a670119..7acab50979 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -1241,7 +1241,7 @@ int sd_bus_message_close_container(sd_bus_message *m) {
return 0;
}
-static int message_append_ap(
+int bus_message_append_ap(
sd_bus_message *m,
const char *types,
va_list ap) {
@@ -1327,7 +1327,7 @@ static int message_append_ap(
n = va_arg(ap, unsigned);
for (i = 0; i < n; i++) {
- r = message_append_ap(m, s, ap);
+ r = bus_message_append_ap(m, s, ap);
if (r < 0)
return r;
}
@@ -1349,7 +1349,7 @@ static int message_append_ap(
if (r < 0)
return r;
- r = message_append_ap(m, s, ap);
+ r = bus_message_append_ap(m, s, ap);
if (r < 0)
return r;
@@ -1377,7 +1377,7 @@ static int message_append_ap(
t += k - 1;
- r = message_append_ap(m, s, ap);
+ r = bus_message_append_ap(m, s, ap);
if (r < 0)
return r;
@@ -1407,10 +1407,10 @@ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
if (m->sealed)
return -EPERM;
if (!types)
- return -EINVAL;
+ return 0;
va_start(ap, types);
- r = message_append_ap(m, types, ap);
+ r = bus_message_append_ap(m, types, ap);
va_end(ap);
return r;
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index 91b1668f19..cc1e10d843 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -144,3 +144,5 @@ int bus_message_from_malloc(
sd_bus_message **ret);
const char* bus_message_get_arg(sd_bus_message *m, unsigned i);
+
+int bus_message_append_ap(sd_bus_message *m, const char *types, va_list ap);
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 943cd43cb1..8c5b9da91d 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2208,3 +2208,60 @@ int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t
return r;
return q;
}
+
+int sd_bus_emit_signal(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *member,
+ const char *types, ...) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ va_list ap;
+ int r;
+
+ if (!bus)
+ return -EINVAL;
+
+ r = sd_bus_message_new_signal(bus, path, interface, member, &m);
+ if (r < 0)
+ return r;
+
+ va_start(ap, types);
+ r = bus_message_append_ap(m, types, ap);
+ va_end(ap);
+ if (r < 0)
+ return r;
+
+ return sd_bus_send(bus, m, NULL);
+}
+
+int sd_bus_call_method(
+ sd_bus *bus,
+ const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member,
+ sd_bus_error *error,
+ sd_bus_message **reply,
+ const char *types, ...) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ va_list ap;
+ int r;
+
+ if (!bus)
+ return -EINVAL;
+
+ r = sd_bus_message_new_method_call(bus, destination, path, interface, member, &m);
+ if (r < 0)
+ return r;
+
+ va_start(ap, types);
+ r = bus_message_append_ap(m, types, ap);
+ va_end(ap);
+ if (r < 0)
+ return r;
+
+ return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+}