chiark / gitweb /
bus: add convenience calls for method replies, too
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Apr 2013 12:48:43 +0000 (14:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Apr 2013 12:56:48 +0000 (14:56 +0200)
src/libsystemd-bus/sd-bus.c
src/systemd/sd-bus.h

index fde39e0cac9dc12490d56d75987622200517a19b..8b8ce3c03e6a1df096e31a8974e6ef08434a0d8b 100644 (file)
@@ -2265,3 +2265,66 @@ int sd_bus_call_method(
 
         return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
 }
 
         return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
 }
+
+int sd_bus_reply_method_return(
+                sd_bus *bus,
+                sd_bus_message *call,
+                const char *types, ...) {
+
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+        va_list ap;
+        int r;
+
+        if (!bus)
+                return -EINVAL;
+        if (!call)
+                return -EINVAL;
+        if (!call->sealed)
+                return -EPERM;
+        if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
+                return -EINVAL;
+
+        if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
+                return 0;
+
+        r = sd_bus_message_new_method_return(bus, call, &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_reply_method_error(
+                sd_bus *bus,
+                sd_bus_message *call,
+                const sd_bus_error *e) {
+
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+        int r;
+
+        if (!bus)
+                return -EINVAL;
+        if (!call)
+                return -EINVAL;
+        if (!call->sealed)
+                return -EPERM;
+        if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
+                return -EINVAL;
+        if (!sd_bus_error_is_set(e))
+                return -EINVAL;
+
+        if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
+                return 0;
+
+        r = sd_bus_message_new_method_error(bus, call, e, &m);
+        if (r < 0)
+                return r;
+
+        return sd_bus_send(bus, m, NULL);
+}
index 27226a92ed9c2b4d942529cdb13da2972093ca70..5dcc5014cf188a0fc1762c1cd426095112e3c33e 100644 (file)
@@ -149,6 +149,8 @@ int sd_bus_message_rewind(sd_bus_message *m, int complete);
 
 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
 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, ...);
 
 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
 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, ...);
+int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
+int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);
 
 /* Bus management */
 
 
 /* Bus management */