blob: 5e3a40e10b070f2de75589319f6c577768ca209c [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
Matt Spinler603acb82024-07-18 08:57:13 -050053 {
54 co_await c.owner("client");
55 }
56
57 {
58 auto _ = co_await c.owner();
59 std::cout << "Should be 'client': " << _ << std::endl;
60 }
61
Adin Scannell8aea1d82025-01-17 17:05:33 -080062 {
63 // Grab all the properties and print them.
64 auto _ = co_await c.properties();
65 std::cout << "Should be 1234: " << _.last_result << std::endl;
66 std::cout << "Should be 'client': " << _.owner << std::endl;
67 }
68
Patrick Williams4a594c02023-04-25 16:29:21 -050069 co_return;
70}
71
72int main()
73{
74 sdbusplus::async::context ctx;
75 ctx.spawn(startup(ctx));
76 ctx.spawn(
77 sdbusplus::async::execution::just() |
78 sdbusplus::async::execution::then([&ctx]() { ctx.request_stop(); }));
79 ctx.run();
80
81 return 0;
82}