blob: 6bb2bc71f62e1790c7ab6bec72b4fe2088c22a8b [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 Williams50f1dae2023-04-26 12:39:11 -050019 // Call the Multiply method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050020 auto _ = co_await c.multiply(7, 6);
Patrick Williams4a594c02023-04-25 16:29:21 -050021 std::cout << "Should be 42: " << _ << std::endl;
22 }
23
24 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050025 // Get the LastResult property.
Patrick Williams65e4d302023-04-26 12:30:10 -050026 auto _ = co_await c.lastResult();
Patrick Williams4a594c02023-04-25 16:29:21 -050027 std::cout << "Should be 42: " << _ << std::endl;
28 }
29
30 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050031 // Call the Clear method.
Patrick Williams3cd1c342023-04-26 11:25:23 -050032 co_await c.clear();
Patrick Williams4a594c02023-04-25 16:29:21 -050033 }
34
35 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050036 // Get the LastResult property.
Patrick Williams65e4d302023-04-26 12:30:10 -050037 auto _ = co_await c.lastResult();
Patrick Williams4a594c02023-04-25 16:29:21 -050038 std::cout << "Should be 0: " << _ << std::endl;
39 }
40
41 {
Patrick Williams50f1dae2023-04-26 12:39:11 -050042 // Set the LastResult property.
Patrick Williams65e4d302023-04-26 12:30:10 -050043 co_await c.lastResult(1234);
Patrick Williams50f1dae2023-04-26 12:39:11 -050044 // Get the LastResult property.
Patrick Williams65e4d302023-04-26 12:30:10 -050045 auto _ = co_await c.lastResult();
Patrick Williams4a594c02023-04-25 16:29:21 -050046 std::cout << "Should be 1234: " << _ << std::endl;
47 }
48
49 co_return;
50}
51
52int main()
53{
54 sdbusplus::async::context ctx;
55 ctx.spawn(startup(ctx));
56 ctx.spawn(
57 sdbusplus::async::execution::just() |
58 sdbusplus::async::execution::then([&ctx]() { ctx.request_stop(); }));
59 ctx.run();
60
61 return 0;
62}