summaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2017-07-03 14:50:21 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-07-17 17:54:39 -0500
commite36cf85cb8bcef40e35c372516a9f8abeef30851 (patch)
treef38a08fcfebee83d18cb329ad7a8e77a595b9aaa /example
parent7bfb70aced5dd21e3da103af62b704ef2e152245 (diff)
downloadsdbusplus-e36cf85cb8bcef40e35c372516a9f8abeef30851.tar.gz
sdbusplus-e36cf85cb8bcef40e35c372516a9f8abeef30851.zip
example: add client API example
Create a small application which calls org.freedesktop.login1 to display a list of the active users. Change-Id: I8d7879d98f6b89a9315aa0c71b928c50490dfedb Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Diffstat (limited to 'example')
-rw-r--r--example/Makefile.am6
-rw-r--r--example/list-users.cpp30
2 files changed, 35 insertions, 1 deletions
diff --git a/example/Makefile.am b/example/Makefile.am
index 8d38538..ae5cdcb 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = calculator-server
+noinst_PROGRAMS = calculator-server list-users
calculator_server_generated_files = \
net/poettering/Calculator/server.hpp \
@@ -14,6 +14,10 @@ calculator_server_SOURCES = \
calculator_server_CXXFLAGS = $(SYSTEMD_CFLAGS)
calculator_server_LDADD = $(SYSTEMD_LIBS) ../libsdbusplus.la
+list_users_SOURCES = list-users.cpp
+list_users_CXXFLAGS = $(SYSTEMD_CFLAGS)
+list_users_LDADD = $(SYSTEMD_LIBS) ../libsdbusplus.la
+
BUILT_SOURCES = \
$(calculator_server_generated_files) \
$(calculator_markdown_generated_files)
diff --git a/example/list-users.cpp b/example/list-users.cpp
new file mode 100644
index 0000000..245bf63
--- /dev/null
+++ b/example/list-users.cpp
@@ -0,0 +1,30 @@
+#include <sdbusplus/bus.hpp>
+#include <iostream>
+#include <cstdint>
+
+/** An example dbus client application.
+ * Calls org.freedesktop.login1's ListUsers interface to find all active
+ * users in the system and displays their username.
+ */
+
+int main()
+{
+ using namespace sdbusplus;
+
+ auto b = bus::new_system();
+ auto m = b.new_method_call("org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "ListUsers");
+ auto reply = b.call(m);
+
+ std::vector<std::tuple<uint32_t, std::string, message::object_path>> users;
+ reply.read(users);
+
+ for(auto& user : users)
+ {
+ std::cout << std::get<std::string>(user) << "\n";
+ }
+
+ return 0;
+}
OpenPOWER on IntegriCloud