]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: generalize helper for ID128 prpoerties
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Aug 2016 17:20:02 +0000 (19:20 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2016 18:14:38 +0000 (20:14 +0200)
This way, we can make use of this in other code, too.

src/machine/machine-dbus.c
src/shared/bus-util.c
src/shared/bus-util.h

index ba7ac04b569c20cd4dc0428fac8a1beae580a31e..5ca18ff87e88c16c07d5f99c6114b3ee297ad36f 100644 (file)
 #include "terminal-util.h"
 #include "user-util.h"
 
-static int property_get_id(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        Machine *m = userdata;
-
-        assert(bus);
-        assert(reply);
-        assert(m);
-
-        return sd_bus_message_append_array(reply, 'y', &m->id, 16);
-}
-
 static int property_get_state(
                 sd_bus *bus,
                 const char *path,
@@ -1311,7 +1293,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
 const sd_bus_vtable machine_vtable[] = {
         SD_BUS_VTABLE_START(0),
         SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Machine, name), SD_BUS_VTABLE_PROPERTY_CONST),
-        SD_BUS_PROPERTY("Id", "ay", property_get_id, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("Id", "ay", bus_property_get_id128, offsetof(Machine, id), SD_BUS_VTABLE_PROPERTY_CONST),
         BUS_PROPERTY_DUAL_TIMESTAMP("Timestamp", offsetof(Machine, timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("Service", "s", NULL, offsetof(Machine, service), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("Unit", "s", NULL, offsetof(Machine, unit), SD_BUS_VTABLE_PROPERTY_CONST),
index e2a216a5cc9c79e1574e4c15f9c0f76ea7f2a4e5..64fcf9295fef3b0624eb151b6305d1f0eed4e17a 100644 (file)
@@ -1324,6 +1324,23 @@ int bus_property_get_bool(
         return sd_bus_message_append_basic(reply, 'b', &b);
 }
 
+int bus_property_get_id128(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        sd_id128_t *id = userdata;
+
+        if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */
+                return sd_bus_message_append(reply, "ay", 0);
+        else
+                return sd_bus_message_append_array(reply, 'b', id->bytes, 16);
+}
+
 #if __SIZEOF_SIZE_T__ != 8
 int bus_property_get_size(
                 sd_bus *bus,
index db6b1acba23ba2bfe911ef90083a369b95ebdda4..934e0b5b77acffc6a5e2897a3d2180eaeeef03ff 100644 (file)
@@ -79,6 +79,7 @@ int bus_print_property(const char *name, sd_bus_message *property, bool value, b
 int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool value, bool all);
 
 int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
+int bus_property_get_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
 
 #define bus_property_get_usec ((sd_bus_property_get_t) NULL)
 #define bus_property_set_usec ((sd_bus_property_set_t) NULL)