summaryrefslogtreecommitdiff
path: root/src/sd_bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sd_bus.c')
-rw-r--r--src/sd_bus.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/sd_bus.c b/src/sd_bus.c
new file mode 100644
index 0000000..3dc3eb0
--- /dev/null
+++ b/src/sd_bus.c
@@ -0,0 +1,118 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include <systemd/sd-bus.h>
+
+#include <utils.h>
+#include <sd_bus.h>
+
+
+int dbus_set_property_string(const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member, const char* value)
+{
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+
+ int r;
+
+ /* Connect to the system bus */
+ r = sd_bus_open_system(&bus);
+ if (r >= 0)
+ {
+
+ r = sd_bus_set_property(
+ bus,
+ destination,
+ path,
+ interface,
+ member,
+ &error,
+ "s",
+ value);
+
+ }
+ if (r < 0)
+ {
+ fprintf(stderr, "Failed to issue dbus call: %d %s\n", r, error.message);
+ }
+
+ return (r>0?(0):(r));
+}
+
+const char* dbus_get_property_string(const char *destination,
+ const char *path,
+ const char *interface,
+ const char *member)
+{
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+ const char *state = NULL;
+ int r;
+
+ /* Connect to the system bus */
+ r = sd_bus_open_system(&bus);
+ if (r >= 0)
+ {
+
+ r = sd_bus_get_property_string(
+ bus,
+ destination,
+ path,
+ interface,
+ member,
+ &error,
+ &state);
+ if (r >= 0)
+ {
+ printf("Result: %s\n", state);
+ }
+ /* Issue the method call and store the respons message in m */
+ }
+ if (r < 0)
+ {
+ fprintf(stderr, "Failed to issue dbus call: %d %s\n", r, error.message);
+ }
+
+ return (r>=0?(state):(NULL));
+}
+
+int cmd_get_string()
+{
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+ _cleanup_free_ char *state = NULL;
+ int r;
+
+ /* Connect to the system bus */
+ r = sd_bus_open_system(&bus);
+ if (r >= 0)
+ {
+
+ r = sd_bus_get_property_string(
+ bus,
+ "org.bluez",
+ "/org/bluez/hci0",
+ "org.bluez.Adapter1",
+ "Alias",
+ &error,
+ &state);
+ if (r >= 0)
+ {
+ printf("Result: %s\n", state);
+ }
+ /* Issue the method call and store the respons message in m */
+ }
+ if (r < 0)
+ {
+ fprintf(stderr, "Failed to issue dbus call: %d %s\n", r, error.message);
+ }
+
+ return (r>0?(0):(r));
+}