summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2018-10-24 12:49:30 -0700
committerVernon Mauery <vernon.mauery@linux.intel.com>2018-11-09 08:37:04 -0800
commitb108806f78fbcf51da3a449c690a617939e204de (patch)
tree25a612be5a4f7ea8cc6c48fb31a953162adc5508
parent36baa14b1d3dae811d46fd6b137a4ad7990a92b5 (diff)
downloadphosphor-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>
-rw-r--r--Makefile.am3
-rw-r--r--main.cpp4
-rw-r--r--timer.cpp111
-rw-r--r--timer.hpp101
4 files changed, 3 insertions, 216 deletions
diff --git a/Makefile.am b/Makefile.am
index fb419df..d1a6ec7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,8 +54,7 @@ netipmid_SOURCES = \
sol_module.hpp \
sol_module.cpp \
settings.hpp \
- settings.cpp \
- timer.cpp
+ settings.cpp
netipmid_CPPFLAGS = -DNET_IPMID_LIB_PATH=\"/usr/lib/net-ipmid/\"
diff --git a/main.cpp b/main.cpp
index 4aa0792..847c991 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,7 +8,6 @@
#include "provider_registration.hpp"
#include "socket_channel.hpp"
#include "sol_module.hpp"
-#include "timer.hpp"
#include <assert.h>
#include <dirent.h>
@@ -20,6 +19,7 @@
#include <unistd.h>
#include <iostream>
+#include <sdbusplus/timer.hpp>
#include <tuple>
// Tuple of Global Singletons
@@ -36,7 +36,7 @@ sd_bus* bus = nullptr;
sd_event* events = nullptr;
// Global timer for network changes
-std::unique_ptr<phosphor::ipmi::Timer> networkTimer = nullptr;
+std::unique_ptr<phosphor::Timer> networkTimer = nullptr;
FILE* ipmidbus = nullptr;
static unsigned short selReservationID = 0xFFFF;
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
diff --git a/timer.hpp b/timer.hpp
deleted file mode 100644
index ec432ba..0000000
--- a/timer.hpp
+++ /dev/null
@@ -1,101 +0,0 @@
-#pragma once
-
-#include <systemd/sd-event.h>
-
-#include <chrono>
-#include <functional>
-namespace phosphor
-{
-namespace ipmi
-{
-
-/** @class Timer
- * @brief Manages starting watchdog timers and handling timeouts
- */
-class Timer
-{
- public:
- /** @brief Only need the default Timer */
- 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] funcCallBack - optional function callback for timer
- * expirations
- */
- Timer(sd_event* events, std::function<void()> userCallBack = nullptr) :
- timeEvent(events), userCallBack(userCallBack)
- {
- // Initialize the timer
- initialize();
- }
-
- ~Timer()
- {
- if (eventSource)
- {
- eventSource = sd_event_source_unref(eventSource);
- }
- }
-
- inline auto isExpired() const
- {
- return expired;
- }
-
- /** @brief Starts the timer with specified expiration value.
- * input is an offset from the current steady_clock
- */
- int startTimer(std::chrono::microseconds usec);
-
- /** @brief Enables / disables the timer */
- int setTimer(int action);
-
- private:
- /** @brief the sd_event structure */
- sd_event* timeEvent = nullptr;
-
- /** @brief Source of events */
- sd_event_source* eventSource = nullptr;
-
- /** @brief Returns if the associated timer is expired
- *
- * This is set to true when the timeoutHandler is called into
- */
- bool expired = true;
-
- /** @brief Initializes the timer object with infinite
- * expiration time and sets up the callback handler
- *
- * @return None.
- *
- * @error std::runtime exception thrown
- */
- void initialize();
-
- /** @brief Callback function when timer goes off
- *
- * On getting the signal, initiate the hard power off request
- *
- * @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 steady clock */
- static std::chrono::microseconds getTime();
-
- /** @brief Optional function to call on timer expiration */
- std::function<void()> userCallBack;
-};
-
-} // namespace ipmi
-} // namespace phosphor
OpenPOWER on IntegriCloud