blob: 0ba1438c8af6f5050d1e9d277664061e3b1c2f25 [file] [log] [blame]
Patrick Williams4a594c02023-04-25 16:29:21 -05001#include <net/poettering/Calculator/client.hpp>
2#include <sdbusplus/async.hpp>
3
4#include <iostream>
5
6auto startup(sdbusplus::async::context& ctx) -> sdbusplus::async::task<>
7{
Patrick Williamsb4bae8f2023-09-01 10:13:19 -05008 using Calculator = sdbusplus::client::net::poettering::Calculator<>;
Patrick Williams4a594c02023-04-25 16:29:21 -05009
Patrick Williamsb4bae8f2023-09-01 10:13:19 -050010 auto c = Calculator(ctx)
11 .service(Calculator::default_service)
12 .path(Calculator::instance_path);
Patrick Williams4a594c02023-04-25 16:29:21 -050013
14 // Alternatively, sdbusplus::async::client_t<Calculator, ...>() could have
15 // been used to combine multiple interfaces into a single client-proxy.
Patrick Williams384943b2023-05-05 06:45:35 -050016 auto alternative_c [[maybe_unused]] =
17 sdbusplus::async::client_t<
18 sdbusplus::client::net::poettering::Calculator>(ctx)
Patrick Williamsb4bae8f2023-09-01 10:13:19 -050019 .service(Calculator::default_service)
20 .path(Calculator::instance_path);
Patrick Williams4a594c02023-04-25 16:29:21 -050021
22 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050023 // Call the Multiply method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050024 auto _ = co_await c.multiply(7, 6);
Patrick Williams4a594c02023-04-25 16:29:21 -050025 std::cout << "Should be 42: " << _ << std::endl;
26 }
27
28 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050029 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050030 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050031 std::cout << "Should be 42: " << _ << std::endl;
32 }
33
34 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050035 // Call the Clear method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050036 co_await c.clear();
Patrick Williams4a594c02023-04-25 16:29:21 -050037 }
38
39 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050040 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050041 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050042 std::cout << "Should be 0: " << _ << std::endl;
43 }
44
45 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050046 // Set the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050047 co_await c.last_result(1234);
Patrick Williams50f1dae2023-04-26 12:39:11 -050048 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050049 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050050 std::cout << "Should be 1234: " << _ << std::endl;
51 }
52
53 co_return;
54}
55
56int 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}