Patrick Williams | 127b8ab | 2020-05-21 15:24:19 -0500 | [diff] [blame] | 1 | #include <sdbusplus/bus.hpp> |
| 2 | |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 3 | #include <cstdint> |
Patrick Venture | 95269db | 2018-08-31 09:19:17 -0700 | [diff] [blame] | 4 | #include <iostream> |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 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 | |
Vernon Mauery | 8ca6025 | 2018-11-08 14:55:34 -0800 | [diff] [blame] | 15 | auto b = bus::new_default_system(); |
Patrick Williams | 1a25a10 | 2022-09-29 17:18:26 -0500 | [diff] [blame] | 16 | auto m = b.new_method_call("org.freedesktop.login1", |
| 17 | "/org/freedesktop/login1", |
| 18 | "org.freedesktop.login1.Manager", "ListUsers"); |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 19 | auto reply = b.call(m); |
| 20 | |
Patrick Williams | 9cde21f | 2022-08-29 10:33:27 -0500 | [diff] [blame] | 21 | using return_type = |
| 22 | std::vector<std::tuple<uint32_t, std::string, message::object_path>>; |
| 23 | auto users = reply.unpack<return_type>(); |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 24 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 25 | for (auto& user : users) |
Patrick Williams | e36cf85 | 2017-07-03 14:50:21 -0500 | [diff] [blame] | 26 | { |
| 27 | std::cout << std::get<std::string>(user) << "\n"; |
| 28 | } |
| 29 | |
| 30 | return 0; |
| 31 | } |