diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-05-30 12:39:22 -0400 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-06-19 16:26:48 -0400 |
commit | aabc54616fba1ad2c26acaf96ddf682ce3c263f0 (patch) | |
tree | 30481422db2149bb879a5bcde7b6ed329cce649a /src | |
parent | 605662db616fd1b7c8874e86186f7a39c3e63a39 (diff) | |
download | phosphor-dbus-monitor-aabc54616fba1ad2c26acaf96ddf682ce3c263f0.tar.gz phosphor-dbus-monitor-aabc54616fba1ad2c26acaf96ddf682ce3c263f0.zip |
Add SDEvent delegate
Add an sd-event interface abstraction to facilitate
mocking and unit test.
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: I5880617565fc6eab54335adc30033d4b132568f8
Diffstat (limited to 'src')
-rw-r--r-- | src/sdevent.hpp | 82 | ||||
-rw-r--r-- | src/templates/generated.mako.hpp | 1 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/sdevent.hpp b/src/sdevent.hpp new file mode 100644 index 0000000..be8b510 --- /dev/null +++ b/src/sdevent.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include "sdevent/event.hpp" +#include "sdevent/timer.hpp" + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +/** @class SDEvent + * @brief SDEventType access delegate implementation for sdevent. + */ +class SDEvent +{ + protected: + /** @brief Share a single event loop amongst users. */ + static auto& getEvent() + { + static auto event = sdevent::event::newDefault(); + return event; + } + + public: + /** @brief Wrapper for sd_event_now. */ + static auto now() + { + return getEvent().now(); + } +}; + +/** @class SDEventTimer + * @brief TimerType access delegate implementation for sdevent. + */ +class SDEventTimer : public SDEvent +{ + public: + SDEventTimer() = delete; + SDEventTimer(const SDEventTimer&) = default; + SDEventTimer(SDEventTimer&&) = default; + SDEventTimer& operator=(const SDEventTimer&) = default; + SDEventTimer& operator=(SDEventTimer&&) = default; + ~SDEventTimer() = default; + + explicit SDEventTimer( + const sdevent::event::timer::Timer::Callback& callback) + : timer(getEvent(), callback) {} + + /** @brief Update a timer expiration. */ + void update( + const std::chrono::steady_clock::time_point& expires) + { + timer.setTime(expires); + } + + /** @brief Query timer state. */ + auto enabled() + { + return timer.enabled() != SD_EVENT_OFF; + } + + /** @brief Enable a timer. */ + void enable() + { + timer.enable(SD_EVENT_ONESHOT); + } + + /** @brief Disable a timer. */ + void disable() + { + timer.enable(SD_EVENT_OFF); + } + + private: + sdevent::event::timer::Timer timer; +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor diff --git a/src/templates/generated.mako.hpp b/src/templates/generated.mako.hpp index 9e89983..914b065 100644 --- a/src/templates/generated.mako.hpp +++ b/src/templates/generated.mako.hpp @@ -10,6 +10,7 @@ #include "method.hpp" #include "propertywatchimpl.hpp" #include "sdbusplus.hpp" +#include "sdevent.hpp" using namespace std::string_literals; |