mirror of
https://github.com/systemd/systemd.git
synced 2024-11-05 06:52:22 +03:00
bus: add convenience calls for method replies, too
This commit is contained in:
parent
88d331d537
commit
f10dda3b82
@ -2265,3 +2265,66 @@ int sd_bus_call_method(
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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_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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user