chiark / gitweb /
bus: make it easy to serialize C99 bools and uids/gids/pids via vtable properties
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Nov 2013 23:50:34 +0000 (00:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Nov 2013 00:13:05 +0000 (01:13 +0100)
src/libsystemd-bus/bus-util.c
src/libsystemd-bus/bus-util.h

index bb5dd29..ad1cb1a 100644 (file)
@@ -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);
+}
index ddb9264..b05cac1 100644 (file)
@@ -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);