| 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 |  | 
 | 11 |     auto c = | 
 | 12 |         sdbusplus::client::net::poettering::Calculator().service(service).path( | 
 | 13 |             path); | 
 | 14 |  | 
 | 15 |     // Alternatively, sdbusplus::async::client_t<Calculator, ...>() could have | 
 | 16 |     // been used to combine multiple interfaces into a single client-proxy. | 
 | 17 |  | 
 | 18 |     { | 
 | 19 |         auto _ = co_await c.call<int64_t>(ctx, "Multiply", int64_t(7), | 
 | 20 |                                           int64_t(6)); | 
 | 21 |         std::cout << "Should be 42: " << _ << std::endl; | 
 | 22 |     } | 
 | 23 |  | 
 | 24 |     { | 
 | 25 |         auto _ = co_await c.get_property<int64_t>(ctx, "LastResult"); | 
 | 26 |         std::cout << "Should be 42: " << _ << std::endl; | 
 | 27 |     } | 
 | 28 |  | 
 | 29 |     { | 
 | 30 |         co_await c.call<>(ctx, "Clear"); | 
 | 31 |     } | 
 | 32 |  | 
 | 33 |     { | 
 | 34 |         auto _ = co_await c.get_property<int64_t>(ctx, "LastResult"); | 
 | 35 |         std::cout << "Should be 0: " << _ << std::endl; | 
 | 36 |     } | 
 | 37 |  | 
 | 38 |     { | 
 | 39 |         co_await c.set_property<int64_t>(ctx, "LastResult", 1234); | 
 | 40 |         auto _ = co_await c.get_property<int64_t>(ctx, "LastResult"); | 
 | 41 |         std::cout << "Should be 1234: " << _ << std::endl; | 
 | 42 |     } | 
 | 43 |  | 
 | 44 |     co_return; | 
 | 45 | } | 
 | 46 |  | 
 | 47 | int main() | 
 | 48 | { | 
 | 49 |     sdbusplus::async::context ctx; | 
 | 50 |     ctx.spawn(startup(ctx)); | 
 | 51 |     ctx.spawn( | 
 | 52 |         sdbusplus::async::execution::just() | | 
 | 53 |         sdbusplus::async::execution::then([&ctx]() { ctx.request_stop(); })); | 
 | 54 |     ctx.run(); | 
 | 55 |  | 
 | 56 |     return 0; | 
 | 57 | } |