blob: 56e9fb46c0f97f715e5bafa5ec049e52a339328d [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.
17
18 {
Patrick Williams3cd1c342023-04-26 11:25:23 -050019 auto _ = co_await c.multiply(7, 6);
Patrick Williams4a594c02023-04-25 16:29:21 -050020 std::cout << "Should be 42: " << _ << std::endl;
21 }
22
23 {
Patrick Williams3cd1c342023-04-26 11:25:23 -050024 auto _ = co_await c.get_property<int64_t>("LastResult");
Patrick Williams4a594c02023-04-25 16:29:21 -050025 std::cout << "Should be 42: " << _ << std::endl;
26 }
27
28 {
Patrick Williams3cd1c342023-04-26 11:25:23 -050029 co_await c.clear();
Patrick Williams4a594c02023-04-25 16:29:21 -050030 }
31
32 {
Patrick Williams3cd1c342023-04-26 11:25:23 -050033 auto _ = co_await c.get_property<int64_t>("LastResult");
Patrick Williams4a594c02023-04-25 16:29:21 -050034 std::cout << "Should be 0: " << _ << std::endl;
35 }
36
37 {
Patrick Williams3cd1c342023-04-26 11:25:23 -050038 co_await c.set_property<int64_t>("LastResult", 1234);
39 auto _ = co_await c.get_property<int64_t>("LastResult");
Patrick Williams4a594c02023-04-25 16:29:21 -050040 std::cout << "Should be 1234: " << _ << std::endl;
41 }
42
43 co_return;
44}
45
46int main()
47{
48 sdbusplus::async::context ctx;
49 ctx.spawn(startup(ctx));
50 ctx.spawn(
51 sdbusplus::async::execution::just() |
52 sdbusplus::async::execution::then([&ctx]() { ctx.request_stop(); }));
53 ctx.run();
54
55 return 0;
56}