diff options
author | William A. Kennington III <wak@google.com> | 2018-10-18 19:20:01 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-10-26 14:24:57 +0000 |
commit | 0dd0c4d728757b78d07f57fe3f92193960ac7076 (patch) | |
tree | e84c45f247d5ddf6b013e0c951e707dc826d942b /timer.hpp | |
parent | ee73f5bdd1996ee9d4f65ddbc69804ea0b1b59e9 (diff) | |
download | phosphor-hwmon-0dd0c4d728757b78d07f57fe3f92193960ac7076.tar.gz phosphor-hwmon-0dd0c4d728757b78d07f57fe3f92193960ac7076.zip |
timer: Remove in favor of sdeventplus/timer
Lets use the new standard event loop timer utility that comes with
sdeventplus instead of the one copied from other projects.
Change-Id: Ie7c8f462f2c0e2e05ce14da58b30a1f91acbf75d
Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'timer.hpp')
-rw-r--r-- | timer.hpp | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/timer.hpp b/timer.hpp deleted file mode 100644 index 03f642d..0000000 --- a/timer.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once - -#include <systemd/sd-event.h> - -#include <chrono> -#include <functional> - -namespace phosphor -{ -namespace hwmon -{ -namespace timer -{ - -enum Action -{ - OFF = SD_EVENT_OFF, - ON = SD_EVENT_ON, - ONESHOT = SD_EVENT_ONESHOT -}; -} - -/** @class Timer - * @brief Provides a timer source and a mechanism to callback when the timer - * expires. - * - * The timer is armed upon construction. The constructor requires a timeout - * handler function, the timer expiry duration, and the timer state (one-shot, - * repetitive, disabled). - * It's possible to change the state of the timer after it's been armed via the - * state() API. - */ -class Timer -{ - public: - Timer() = delete; - Timer(const Timer&) = delete; - Timer& operator=(const Timer&) = delete; - Timer(Timer&&) = delete; - Timer& operator=(Timer&&) = delete; - - /** @brief Constructs timer object - * - * @param[in] events - sd_event pointer - * @param[in] callback - function callback for timer expiry - * @param[in] usec - timer duration, in micro seconds - * @param[in] action - controls the timer's lifetime - */ - Timer(sd_event* event, std::function<void()> userCallback, - std::chrono::microseconds usec, timer::Action action); - - ~Timer() - { - if (eventSource) - { - eventSource = sd_event_source_unref(eventSource); - } - } - - /** @brief Timer expiry handler - invokes callback - * - * @param[in] eventSource - Source of the event - * @param[in] usec - time in micro seconds - * @param[in] userData - User data pointer - * - */ - static int timeoutHandler(sd_event_source* eventSource, uint64_t usec, - void* userData); - - /** @brief Enables / disables the timer - * @param[in] action - controls the timer's lifetime - */ - int state(timer::Action action) - { - return sd_event_source_set_enabled(eventSource, action); - } - - timer::Action getAction() const - { - return action; - } - - std::chrono::microseconds getDuration() const - { - return duration; - } - - private: - /** @brief the sd_event structure */ - sd_event* event = nullptr; - - /** @brief Source of events */ - sd_event_source* eventSource = nullptr; - - /** @brief Optional function to call on timer expiration */ - std::function<void()> callback{}; - - /** @brief Duration of the timer */ - std::chrono::microseconds duration{}; - - /** @brief whether the timer is enabled/disabled/one-shot */ - timer::Action action = timer::OFF; -}; - -} // namespace hwmon -} // namespace phosphor |