diff options
author | Patrick Venture <venture@google.com> | 2018-08-31 10:10:53 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-08-31 12:42:31 -0700 |
commit | 043d32306e00484afc446a44789b61869ea14f84 (patch) | |
tree | 786a28de89a2a916ba5c2e4b73411516a10dc8af /timer.hpp | |
parent | 901f117733c828aa7519610eb23ce112b9d068a8 (diff) | |
download | phosphor-hwmon-043d32306e00484afc446a44789b61869ea14f84.tar.gz phosphor-hwmon-043d32306e00484afc446a44789b61869ea14f84.zip |
add .clang-format
Change-Id: I94ce26d595367e08d6fb3734535bcd855f1b1473
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'timer.hpp')
-rw-r--r-- | timer.hpp | 138 |
1 files changed, 68 insertions, 70 deletions
@@ -1,8 +1,9 @@ #pragma once +#include <systemd/sd-event.h> + #include <chrono> #include <functional> -#include <systemd/sd-event.h> namespace phosphor { @@ -17,7 +18,6 @@ enum Action ON = SD_EVENT_ON, ONESHOT = SD_EVENT_ONESHOT }; - } /** @class Timer @@ -32,76 +32,74 @@ enum Action */ 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 + 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) { - return action; + eventSource = sd_event_source_unref(eventSource); } - - 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; + } + + /** @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 |