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