chiark / gitweb /
bus-util: generalize helper for ID128 prpoerties
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Aug 2016 17:20:02 +0000 (19:20 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 5 Jul 2017 06:50:53 +0000 (08:50 +0200)
This way, we can make use of this in other code, too.

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

index c8b070b53b8b9e8885cce2e5ef5c75fa192f3aa2..fde3c3119a02875ebd60f311a7e59954021d6a43 100644 (file)
@@ -1334,6 +1334,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 88c2804d66c81eb33b792c8d40f592beaedba406..802983766f680909d64d5c366bff8739c6c4c7e9 100644 (file)
@@ -91,6 +91,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)