blob: 2db6ae262bd4327d4e662405458ecd2a8837a430 [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{
8 constexpr auto service = "net.poettering.Calculator";
9 constexpr auto path = "/net/poettering/calculator";
10
Patrick Williams3cd1c342023-04-26 11:25:23 -050011 auto c = sdbusplus::client::net::poettering::Calculator(ctx)
12 .service(service)
13 .path(path);
Patrick Williams4a594c02023-04-25 16:29:21 -050014
15 // Alternatively, sdbusplus::async::client_t<Calculator, ...>() could have
16 // been used to combine multiple interfaces into a single client-proxy.
Patrick Williams384943b2023-05-05 06:45:35 -050017 auto alternative_c [[maybe_unused]] =
18 sdbusplus::async::client_t<
19 sdbusplus::client::net::poettering::Calculator>(ctx)
20 .service(service)
21 .path(path);
Patrick Williams4a594c02023-04-25 16:29:21 -050022
23 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050024 // Call the Multiply method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050025 auto _ = co_await c.multiply(7, 6);
Patrick Williams4a594c02023-04-25 16:29:21 -050026 std::cout << "Should be 42: " << _ << std::endl;
27 }
28
29 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050030 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050031 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050032 std::cout << "Should be 42: " << _ << std::endl;
33 }
34
35 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050036 // Call the Clear method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050037 co_await c.clear();
Patrick Williams4a594c02023-04-25 16:29:21 -050038 }
39
40 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050041 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050042 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050043 std::cout << "Should be 0: " << _ << std::endl;
44 }
45
46 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050047 // Set the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050048 co_await c.last_result(1234);
Patrick Williams50f1dae2023-04-26 12:39:11 -050049 // Get the LastResult property.
Patrick Williamsb736e072023-08-24 14:42:58 -050050 auto _ = co_await c.last_result();
Patrick Williams4a594c02023-04-25 16:29:21 -050051 std::cout << "Should be 1234: " << _ << std::endl;
52 }
53
54 co_return;
55}
56
57int 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}