diff options
author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-10-24 12:49:30 -0700 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-11-09 08:37:04 -0800 |
commit | b108806f78fbcf51da3a449c690a617939e204de (patch) | |
tree | 25a612be5a4f7ea8cc6c48fb31a953162adc5508 /timer.cpp | |
parent | 36baa14b1d3dae811d46fd6b137a4ad7990a92b5 (diff) | |
download | phosphor-net-ipmid-b108806f78fbcf51da3a449c690a617939e204de.tar.gz phosphor-net-ipmid-b108806f78fbcf51da3a449c690a617939e204de.zip |
netipmid: Remove local timer class
Remove the local timer class, migrating to the sdbusplus/timer.hpp class
for now. As the project moves toward the single ipmi execution queue the
timers will all go away anyway in preference to the asio timers.
Tested-by: making changes to the network via rmcp+ with ipmitool. This
should make use of the networkTimer variable that was
changed from the internal timer class to the sdbusplus timer
class.
Change-Id: I4a86e3b9c1f3cfefee1e112229dcb63aa5119f2f
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'timer.cpp')
-rw-r--r-- | timer.cpp | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/timer.cpp b/timer.cpp deleted file mode 100644 index f1887fd..0000000 --- a/timer.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "timer.hpp" - -#include <chrono> -#include <phosphor-logging/log.hpp> -namespace phosphor -{ -namespace ipmi -{ - -using namespace phosphor::logging; - -// Initializes the timer object -void Timer::initialize() -{ - // This can not be called more than once. - if (eventSource) - { - throw std::runtime_error("Timer already initialized"); - } - - // Add infinite expiration time - auto r = sd_event_add_time(timeEvent, &eventSource, - CLOCK_MONOTONIC, // Time base - UINT64_MAX, // Expire time - way long time - 0, // Use default event accuracy - timeoutHandler, // Callback handler on timeout - this); // User data - if (r < 0) - { - log<level::ERR>("Failure to set initial expiration time value", - entry("ERROR=%s", strerror(-r))); - - throw std::runtime_error("Timer initialization failed"); - } - - // Disable the timer for now - r = setTimer(SD_EVENT_OFF); - if (r < 0) - { - log<level::ERR>("Failure to disable timer", - entry("ERROR=%s", strerror(-r))); - - throw std::runtime_error("Disabling the timer failed"); - } - return; -} - -/** @brief callback handler on timeout */ -int Timer::timeoutHandler(sd_event_source* eventSource, uint64_t usec, - void* userData) -{ - auto timer = static_cast<Timer*>(userData); - timer->expired = true; - - log<level::INFO>("Timer expired"); - // Call optional user call back function if available - if (timer->userCallBack) - { - timer->userCallBack(); - } - - sd_event_source_set_enabled(eventSource, SD_EVENT_OFF); - return 0; -} - -// Gets the time from steady_clock -std::chrono::microseconds Timer::getTime() -{ - using namespace std::chrono; - auto usec = steady_clock::now().time_since_epoch(); - return duration_cast<microseconds>(usec); -} - -// Enables or disables the timer -int Timer::setTimer(int action) -{ - return sd_event_source_set_enabled(eventSource, action); -} - -// Sets the time and arms the timer -int Timer::startTimer(std::chrono::microseconds timeValue) -{ - // Disable the timer - setTimer(SD_EVENT_OFF); - expired = false; - - // Get the current MONOTONIC time and add the delta - auto expireTime = getTime() + timeValue; - - // Set the time - auto r = sd_event_source_set_time(eventSource, expireTime.count()); - if (r < 0) - { - log<level::ERR>("Failure to set timer", - entry("ERROR=%s", strerror(-r))); - return r; - } - - // A ONESHOT timer means that when the timer goes off, - // its moves to disabled state. - r = setTimer(SD_EVENT_ONESHOT); - if (r < 0) - { - log<level::ERR>("Failure to start timer", - entry("ERROR=%s", strerror(-r))); - } - return r; -} - -} // namespace ipmi -} // namespace phosphor |