blob: 149da86d90c9d4cadbd1bcb9cbf70d7fd82c82e5 [file] [log] [blame]
Patrick Williamsbf0283a2023-08-19 07:18:04 -05001#include <net/poettering/Calculator/aserver.hpp>
2#include <sdbusplus/async.hpp>
3
4class Calculator :
5 public sdbusplus::aserver::net::poettering::Calculator<Calculator>
6{
7 public:
8 explicit Calculator(sdbusplus::async::context& ctx) :
9 sdbusplus::aserver::net::poettering::Calculator<Calculator>(
10 ctx, "/net/poettering/calculator"),
11 manager(ctx, "/")
12 {
13 ctx.spawn(startup());
14 }
15
Patrick Williamsf84f1112023-08-20 19:03:08 -050016 auto get_property(last_result_t) const
17 {
Patrick Williamsf07cad92023-08-21 14:41:19 -050018 return _last_result;
Patrick Williamsf84f1112023-08-20 19:03:08 -050019 }
20
Patrick Williamsf07cad92023-08-21 14:41:19 -050021 bool set_property(last_result_t, int64_t v)
Patrick Williams72f71162023-08-20 21:36:14 -050022 {
Patrick Williamsf07cad92023-08-21 14:41:19 -050023 if (v % 2 == 0)
24 {
25 std::swap(_last_result, v);
26 return v != _last_result;
27 }
Patrick Williams72f71162023-08-20 21:36:14 -050028 return false;
29 }
30
Patrick Williamsbf0283a2023-08-19 07:18:04 -050031 private:
32 auto startup() -> sdbusplus::async::task<>
33 {
Patrick Williamsf07cad92023-08-21 14:41:19 -050034 last_result(123);
Patrick Williamsbf0283a2023-08-19 07:18:04 -050035 ctx.get_bus().request_name("net.poettering.Calculator");
36
Patrick Williams72f71162023-08-20 21:36:14 -050037 status(State::Error);
38
Patrick Williamsbf0283a2023-08-19 07:18:04 -050039 while (1)
40 {
41 using namespace std::literals;
42 co_await sdbusplus::async::sleep_for(ctx, 10s);
43
44 cleared(42);
45 }
46 co_return;
47 }
48
49 sdbusplus::server::manager_t manager;
50};
51
52int main()
53{
54 sdbusplus::async::context ctx;
55 [[maybe_unused]] Calculator c(ctx);
56
57 ctx.run();
58
59 return 0;
60}