mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-30 23:21:08 +03:00
bus: add convenience functions for constructing and sending method calls/signals in one call
This commit is contained in:
parent
7286037fd4
commit
917b5dc707
@ -743,7 +743,7 @@ static int request_handler_file(
|
||||
}
|
||||
|
||||
static int get_virtualization(char **v) {
|
||||
_cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
|
||||
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
|
||||
_cleanup_bus_unref_ sd_bus *bus = NULL;
|
||||
const char *t;
|
||||
char *b;
|
||||
@ -753,21 +753,17 @@ static int get_virtualization(char **v) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_new_method_call(
|
||||
r = sd_bus_call_method(
|
||||
bus,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Get",
|
||||
&m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(m, "ss", "org.freedesktop.systemd1.Manager", "Virtualization");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
|
||||
NULL,
|
||||
&reply,
|
||||
"ss",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"Virtualization");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -145,6 +145,11 @@ int sd_bus_message_exit_container(sd_bus_message *m);
|
||||
int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents);
|
||||
int sd_bus_message_rewind(sd_bus_message *m, int complete);
|
||||
|
||||
/* Convenience calls */
|
||||
|
||||
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, ...);
|
||||
|
||||
/* Bus management */
|
||||
|
||||
int sd_bus_get_unique_name(sd_bus *bus, const char **unique);
|
||||
|
Loading…
Reference in New Issue
Block a user