Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 1 | #include <net/poettering/Calculator/aserver.hpp> |
| 2 | #include <sdbusplus/async.hpp> |
| 3 | |
| 4 | class 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 Williams | f84f111 | 2023-08-20 19:03:08 -0500 | [diff] [blame] | 16 | auto get_property(last_result_t) const |
| 17 | { |
Patrick Williams | f07cad9 | 2023-08-21 14:41:19 -0500 | [diff] [blame^] | 18 | return _last_result; |
Patrick Williams | f84f111 | 2023-08-20 19:03:08 -0500 | [diff] [blame] | 19 | } |
| 20 | |
Patrick Williams | f07cad9 | 2023-08-21 14:41:19 -0500 | [diff] [blame^] | 21 | bool set_property(last_result_t, int64_t v) |
Patrick Williams | 72f7116 | 2023-08-20 21:36:14 -0500 | [diff] [blame] | 22 | { |
Patrick Williams | f07cad9 | 2023-08-21 14:41:19 -0500 | [diff] [blame^] | 23 | if (v % 2 == 0) |
| 24 | { |
| 25 | std::swap(_last_result, v); |
| 26 | return v != _last_result; |
| 27 | } |
Patrick Williams | 72f7116 | 2023-08-20 21:36:14 -0500 | [diff] [blame] | 28 | return false; |
| 29 | } |
| 30 | |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 31 | private: |
| 32 | auto startup() -> sdbusplus::async::task<> |
| 33 | { |
Patrick Williams | f07cad9 | 2023-08-21 14:41:19 -0500 | [diff] [blame^] | 34 | last_result(123); |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 35 | ctx.get_bus().request_name("net.poettering.Calculator"); |
| 36 | |
Patrick Williams | 72f7116 | 2023-08-20 21:36:14 -0500 | [diff] [blame] | 37 | status(State::Error); |
| 38 | |
Patrick Williams | bf0283a | 2023-08-19 07:18:04 -0500 | [diff] [blame] | 39 | 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 | |
| 52 | int main() |
| 53 | { |
| 54 | sdbusplus::async::context ctx; |
| 55 | [[maybe_unused]] Calculator c(ctx); |
| 56 | |
| 57 | ctx.run(); |
| 58 | |
| 59 | return 0; |
| 60 | } |