Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 1 | #include <cstdint> |
Patrick Venture | 95269db | 2018-08-31 09:19:17 -0700 | [diff] [blame] | 2 | #include <iostream> |
| 3 | #include <sdbusplus/bus.hpp> |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 4 | |
| 5 | /** An example dbus client application. |
| 6 | * Calls org.freedesktop.login1's ListUsers interface to find all active |
| 7 | * users in the system and displays their username. |
| 8 | */ |
| 9 | |
| 10 | int main() |
| 11 | { |
| 12 | using namespace sdbusplus; |
| 13 | |
Vernon Mauery | 8ca6025 | 2018-11-08 14:55:34 -0800 | [diff] [blame] | 14 | auto b = bus::new_default_system(); |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 15 | auto m = |
| 16 | b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1", |
| 17 | "org.freedesktop.login1.Manager", "ListUsers"); |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 18 | auto reply = b.call(m); |
| 19 | |
| 20 | std::vector<std::tuple<uint32_t, std::string, message::object_path>> users; |
| 21 | reply.read(users); |
| 22 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 23 | for (auto& user : users) |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 24 | { |
| 25 | std::cout << std::get<std::string>(user) << "\n"; |
| 26 | } |
| 27 | |
| 28 | return 0; |
| 29 | } |