summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-05 00:50:34 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-05 01:13:05 +0100
commite65040306900e36aaa84b52428be3490bf107850 (patch)
treeba307da8e7ae48768ad59ece123fe45393790520 /src/libsystemd-bus
parentc13c7de3bf419db3ae93a9acd2d95a5a19e408ed (diff)
bus: make it easy to serialize C99 bools and uids/gids/pids via vtable properties
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-util.c30
-rw-r--r--src/libsystemd-bus/bus-util.h6
2 files changed, 36 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index bb5dd29a57..ad1cb1a6d0 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -789,3 +789,33 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b
return r;
}
+
+int bus_property_get_bool(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ sd_bus_error *error,
+ void *userdata) {
+
+ int b = *(bool*) userdata;
+
+ return sd_bus_message_append_basic(reply, 'b', &b);
+}
+
+int bus_property_get_uid(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ sd_bus_error *error,
+ void *userdata) {
+
+ assert_cc(sizeof(uint32_t) == sizeof(uid_t));
+ assert_cc(sizeof(uint32_t) == sizeof(gid_t));
+ assert_cc(sizeof(uint32_t) == sizeof(pid_t));
+
+ return sd_bus_message_append_basic(reply, 'u', userdata);
+}
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index ddb926498f..b05cac11ff 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -62,6 +62,12 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b
int bus_generic_print_property(const char *name, sd_bus_message *property, bool all);
+int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+int bus_property_get_uid(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata);
+
+#define bus_property_get_gid bus_property_get_uid
+#define bus_property_get_pid bus_property_get_uid
+
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);