summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-07 19:28:54 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-07 19:28:54 +0100
commit63be1989c77864c7f9845bee1fbd0a2946b0b1b6 (patch)
tree6ad906719349008188e57aec02d45a0fe70779fe /src/libsystemd-bus
parent1405bef3f1f204fdee001e1d002a8e91a56ef0d3 (diff)
bus: add APIs to easily query string and strv properties
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-convenience.c75
-rw-r--r--src/libsystemd-bus/libsystemd-bus.sym2
2 files changed, 77 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
index 0ccc259ea2..4dc65b9718 100644
--- a/src/libsystemd-bus/bus-convenience.c
+++ b/src/libsystemd-bus/bus-convenience.c
@@ -305,6 +305,81 @@ _public_ int sd_bus_get_property_trivial(
return 0;
}
+_public_ int sd_bus_get_property_string(
+ sd_bus *bus,
+ const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member,
+ sd_bus_error *error,
+ char **ret) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ const char *s;
+ char *n;
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
+ assert_return(member_name_is_valid(member), -EINVAL);
+ assert_return(ret, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_enter_container(reply, 'v', "s");
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_basic(reply, 's', &s);
+ if (r < 0)
+ return r;
+
+ n = strdup(s);
+ if (!n)
+ return -ENOMEM;
+
+ *ret = n;
+ return 0;
+}
+
+_public_ int sd_bus_get_property_strv(
+ sd_bus *bus,
+ const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member,
+ sd_bus_error *error,
+ char ***ret) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
+ assert_return(member_name_is_valid(member), -EINVAL);
+ assert_return(ret, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_enter_container(reply, 'v', NULL);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read_strv(reply, ret);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
_public_ int sd_bus_set_property(
sd_bus *bus,
const char *destination,
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 5eecfa1cf9..4924cf1652 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -142,6 +142,8 @@ global:
sd_bus_call_method;
sd_bus_get_property;
sd_bus_get_property_trivial;
+ sd_bus_get_property_string;
+ sd_bus_get_property_strv;
sd_bus_set_property;
sd_bus_reply_method_return;
sd_bus_reply_method_error;