]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: introduce bus_property_get_tristate()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Feb 2023 06:32:39 +0000 (15:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Feb 2023 06:09:13 +0000 (15:09 +0900)
This will be used in later commits.

src/shared/bus-get-properties.c
src/shared/bus-get-properties.h

index 8b4f66b22e91ccdcf7b1899f774754fa98158ed1..3d0887e6df72ea4b61bc8967c6f00d274676bc59 100644 (file)
@@ -38,6 +38,22 @@ int bus_property_set_bool(
         return 0;
 }
 
+int bus_property_get_tristate(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        /* Defaults to false. */
+
+        int b = (*(int*) userdata) > 0;
+
+        return sd_bus_message_append_basic(reply, 'b', &b);
+}
+
 int bus_property_get_id128(
                 sd_bus *bus,
                 const char *path,
index d048913877cc2ce4a5dc40e97eec756895492355..44cd584bdcb5a0fc6fc748fbe8387fe4b1c91546 100644 (file)
@@ -7,6 +7,7 @@
 
 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_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error);
+int bus_property_get_tristate(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)