xref: /openbmc/sdbusplus/example/list-users.cpp (revision 44c6013c)
1 #include <sdbusplus/bus.hpp>
2 
3 #include <cstdint>
4 #include <iostream>
5 
6 /** An example dbus client application.
7  *  Calls org.freedesktop.login1's ListUsers interface to find all active
8  *  users in the system and displays their username.
9  */
10 
11 int main()
12 {
13     using namespace sdbusplus;
14 
15     auto b = bus::new_default_system();
16     auto m = b.new_method_call("org.freedesktop.login1",
17                                "/org/freedesktop/login1",
18                                "org.freedesktop.login1.Manager", "ListUsers");
19     auto reply = b.call(m);
20 
21     using return_type =
22         std::vector<std::tuple<uint32_t, std::string, message::object_path>>;
23     auto users = reply.unpack<return_type>();
24 
25     for (auto& user : users)
26     {
27         std::cout << std::get<std::string>(user) << "\n";
28     }
29 
30     return 0;
31 }
32