Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 1 | #include <net/poettering/Calculator/client.hpp> |
| 2 | #include <sdbusplus/async.hpp> |
| 3 | |
| 4 | #include <iostream> |
| 5 | |
| 6 | auto startup(sdbusplus::async::context& ctx) -> sdbusplus::async::task<> |
| 7 | { |
| 8 | constexpr auto service = "net.poettering.Calculator"; |
| 9 | constexpr auto path = "/net/poettering/calculator"; |
| 10 | |
Patrick Williams | 3cd1c34 | 2023-04-26 11:25:23 -0500 | [diff] [blame] | 11 | auto c = sdbusplus::client::net::poettering::Calculator(ctx) |
| 12 | .service(service) |
| 13 | .path(path); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 14 | |
| 15 | // Alternatively, sdbusplus::async::client_t<Calculator, ...>() could have |
| 16 | // been used to combine multiple interfaces into a single client-proxy. |
| 17 | |
| 18 | { |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 19 | // Call the Multiply method. |
Patrick Williams | 3cd1c34 | 2023-04-26 11:25:23 -0500 | [diff] [blame] | 20 | auto _ = co_await c.multiply(7, 6); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 21 | std::cout << "Should be 42: " << _ << std::endl; |
| 22 | } |
| 23 | |
| 24 | { |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 25 | // Get the LastResult property. |
Patrick Williams | 65e4d30 | 2023-04-26 12:30:10 -0500 | [diff] [blame] | 26 | auto _ = co_await c.lastResult(); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 27 | std::cout << "Should be 42: " << _ << std::endl; |
| 28 | } |
| 29 | |
| 30 | { |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 31 | // Call the Clear method. |
Patrick Williams | 3cd1c34 | 2023-04-26 11:25:23 -0500 | [diff] [blame] | 32 | co_await c.clear(); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | { |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 36 | // Get the LastResult property. |
Patrick Williams | 65e4d30 | 2023-04-26 12:30:10 -0500 | [diff] [blame] | 37 | auto _ = co_await c.lastResult(); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 38 | std::cout << "Should be 0: " << _ << std::endl; |
| 39 | } |
| 40 | |
| 41 | { |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 42 | // Set the LastResult property. |
Patrick Williams | 65e4d30 | 2023-04-26 12:30:10 -0500 | [diff] [blame] | 43 | co_await c.lastResult(1234); |
Patrick Williams | 50f1dae | 2023-04-26 12:39:11 -0500 | [diff] [blame] | 44 | // Get the LastResult property. |
Patrick Williams | 65e4d30 | 2023-04-26 12:30:10 -0500 | [diff] [blame] | 45 | auto _ = co_await c.lastResult(); |
Patrick Williams | 4a594c0 | 2023-04-25 16:29:21 -0500 | [diff] [blame] | 46 | std::cout << "Should be 1234: " << _ << std::endl; |
| 47 | } |
| 48 | |
| 49 | co_return; |
| 50 | } |
| 51 | |
| 52 | int main() |
| 53 | { |
| 54 | sdbusplus::async::context ctx; |
| 55 | ctx.spawn(startup(ctx)); |
| 56 | ctx.spawn( |
| 57 | sdbusplus::async::execution::just() | |
| 58 | sdbusplus::async::execution::then([&ctx]() { ctx.request_stop(); })); |
| 59 | ctx.run(); |
| 60 | |
| 61 | return 0; |
| 62 | } |