diff options
author | William A. Kennington III <wak@google.com> | 2018-10-30 19:49:29 -0700 |
---|---|---|
committer | Matthew Barth <msbarth@linux.ibm.com> | 2019-02-05 16:20:02 +0000 |
commit | 8fd879fb7bb9ed34fe69581dc714b4158046519f (patch) | |
tree | aa33e860d7d018fd9670599039e459a4bebc6324 /timer.hpp | |
parent | a1aef7a100a9b27d2133622a695bb8c09c2869bf (diff) | |
download | phosphor-fan-presence-8fd879fb7bb9ed34fe69581dc714b4158046519f.tar.gz phosphor-fan-presence-8fd879fb7bb9ed34fe69581dc714b4158046519f.zip |
Remove timer in favor of sdeventplus/utility/timer
This removes the custom timer implementation and moves to the
sdeventplus utility. Functionally this should make no change
Tested:
Built and run through the unit test suite.
Change-Id: Ib7ee90d489d5db72496aaaca91c3cf5490ad47d6
Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'timer.hpp')
-rw-r--r-- | timer.hpp | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/timer.hpp b/timer.hpp deleted file mode 100644 index 3b7783b..0000000 --- a/timer.hpp +++ /dev/null @@ -1,163 +0,0 @@ -#pragma once - -#include <chrono> -#include <functional> -#include <memory> -#include <sdeventplus/event.hpp> -#include "event.hpp" - -namespace phosphor -{ -namespace fan -{ -namespace util -{ - - -/** - * @class Timer - * - * This class implements a simple timer that runs an arbitrary - * function on expiration. The timeout value is set in microseconds. - * It can be stopped while it is running, and queried to see if it is - * running. - * - * If started with the 'repeating' argument, it will keep calling the - * callback function every <timeout> microseconds. If started with the - * 'oneshot' argument, it will just call the callback function one time. - * - * It needs an sd_event loop to function. - */ -class Timer -{ - public: - - enum class TimerType - { - oneshot, - repeating - }; - - Timer() = delete; - Timer(const Timer&) = delete; - Timer& operator=(const Timer&) = delete; - Timer(Timer&&) = default; - Timer& operator=(Timer&&) = default; - - /** - * @brief Constructs timer object - * - * @param[in] event - Event loop reference, previously created - * @param[in] callbackFunc - The function to call on timer expiration - */ - Timer(const sdeventplus::Event& event, - std::function<void()> callbackFunc); - - /** - * @brief Destructor - */ - ~Timer(); - - /** - * @brief Starts the timer - * - * The input is an offset from the current steady clock. - * - * @param[in] usec - the timeout value in microseconds - * @param[in] type - either a oneshot, or repeating - */ - void start(std::chrono::microseconds usec, - TimerType type = TimerType::oneshot); - - /** - * @brief Stop the timer - */ - void stop(); - - /** - * @brief Returns true if the timer is running - */ - bool running(); - - /** - * @brief Returns the timeout value - * - * @return - the last value sent in via start(). - * - * Could be used to restart the timer with the same - * timeout. i.e. start(getTimeout()); - */ - inline auto getTimeout() const - { - return timeout; - } - - /** - * @brief Returns the timer type - */ - inline auto getType() const - { - return type; - } - - private: - - /** - * @brief Callback function when timer goes off - * - * Calls the callback function passed in by the user. - * - * @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 Gets the current time from the steady clock - */ - std::chrono::microseconds getTime(); - - /** - * @brief Wrapper around sd_event_source_set_enabled - * - * @param[in] action - either SD_EVENT_OFF, SD_EVENT_ON, - * or SD_EVENT_ONESHOT - */ - void setTimer(int action); - - - /** - * @brief Sets the expiration time for the timer - * - * Sets it to timeout microseconds in the future - */ - void setTimeout(); - - /** - * @brief Source of events - */ - phosphor::fan::event::EventSourcePtr eventSource; - - /** - * @brief Either 'repeating' or 'oneshot' - */ - TimerType type = TimerType::oneshot; - - /** - * @brief The function to call when the timer expires - */ - std::function<void()> callback; - - /** - * @brief What the timer was set to run for - * - * Not cleared on timer expiration - */ - std::chrono::microseconds timeout; -}; - -} -} -} |