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