summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--configure.ac2
-rw-r--r--control/Makefile.am2
-rw-r--r--control/actions.cpp2
-rw-r--r--control/main.cpp29
-rw-r--r--control/manager.cpp4
-rw-r--r--control/manager.hpp5
-rw-r--r--control/zone.cpp10
-rw-r--r--control/zone.hpp17
-rw-r--r--event.hpp13
-rw-r--r--monitor/Makefile.am2
-rw-r--r--monitor/fan.cpp4
-rw-r--r--monitor/fan.hpp6
-rw-r--r--monitor/main.cpp30
-rw-r--r--monitor/tach_sensor.cpp4
-rw-r--r--monitor/tach_sensor.hpp6
-rw-r--r--presence/Makefile.am2
-rw-r--r--presence/gpio.cpp18
-rw-r--r--presence/gpio.hpp11
-rw-r--r--presence/tach_detect.cpp14
-rw-r--r--test/Makefile.am2
-rw-r--r--test/timertest.cpp61
-rw-r--r--timer.cpp5
-rw-r--r--timer.hpp10
24 files changed, 99 insertions, 166 deletions
diff --git a/Makefile.am b/Makefile.am
index 67f49e9..a20fe8a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,11 +5,13 @@ libfan_la_LDFLAGS = -static
libfan_la_LIBADD = \
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
- $(SDBUSPLUS_LIBS)
+ $(SDBUSPLUS_LIBS) \
+ $(SDEVENTPLUS_LIBS)
libfan_la_CXXFLAGS = \
$(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS) \
- $(SDBUSPLUS_CFLAGS) -flto
+ $(SDBUSPLUS_CFLAGS) \
+ $(SDEVENTPLUS_CFLAGS) -flto
libfan_la_SOURCES = \
utility.cpp \
timer.cpp
diff --git a/configure.ac b/configure.ac
index 544b763..b60d032 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,8 @@ AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
# Checks for libraries.
PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], ,
[AC_MSG_ERROR([The openbmc/sdbusplus package is required])])
+PKG_CHECK_MODULES([SDEVENTPLUS], [sdeventplus], ,
+[AC_MSG_ERROR([The openbmc/sdeventplus package is required])])
PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging], ,
[AC_MSG_ERROR([The openbmc/phosphor-logging package is required])])
PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221], ,
diff --git a/control/Makefile.am b/control/Makefile.am
index 01ee9c9..e0b0865 100644
--- a/control/Makefile.am
+++ b/control/Makefile.am
@@ -18,11 +18,13 @@ nodist_phosphor_fan_control_SOURCES = \
phosphor_fan_control_LDADD = \
$(top_builddir)/libfan.la \
$(SDBUSPLUS_LIBS) \
+ $(SDEVENTPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
${PHOSPHOR_DBUS_INTERFACES_LIBS}
phosphor_fan_control_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
+ $(SDEVENTPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS) \
${PHOSPHOR_DBUS_INTERFACES_CFLAGS} \
-flto
diff --git a/control/actions.cpp b/control/actions.cpp
index b162602..71f7f72 100644
--- a/control/actions.cpp
+++ b/control/actions.cpp
@@ -43,7 +43,7 @@ Action call_actions_based_on_timer(Timer&& tConf, std::vector<Action>&& actions)
// Create/start timer and associate event data with it
std::unique_ptr<util::Timer> timer =
std::make_unique<util::Timer>(
- zone.getEventPtr(),
+ zone.getEventLoop(),
[&zone,
actions = &actions,
group = &group]()
diff --git a/control/main.cpp b/control/main.cpp
index 8c13cf9..4420488 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -14,10 +14,10 @@
* limitations under the License.
*/
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
#include <phosphor-logging/log.hpp>
#include "argument.hpp"
#include "manager.hpp"
-#include "event.hpp"
#include "sdbusplus.hpp"
using namespace phosphor::fan::control;
@@ -25,8 +25,8 @@ using namespace phosphor::logging;
int main(int argc, char* argv[])
{
+ auto event = sdeventplus::Event::get_default();
auto bus = sdbusplus::bus::new_default();
- sd_event* events = nullptr;
phosphor::fan::util::ArgumentParser args(argc, argv);
if (argc != 2)
@@ -51,23 +51,13 @@ int main(int argc, char* argv[])
return 1;
}
- auto r = sd_event_default(&events);
- if (r < 0)
- {
- log<level::ERR>("Failed call to sd_event_default()",
- entry("ERROR=%s", strerror(-r)));
- return 1;
- }
-
- phosphor::fan::event::EventPtr eventPtr{events};
-
//Attach the event object to the bus object so we can
//handle both sd_events (for the timers) and dbus signals.
- bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
+ bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
try
{
- Manager manager(bus, eventPtr, mode);
+ Manager manager(bus, event, mode);
//Init mode will just set fans to max and delay
if (mode == Mode::init)
@@ -75,15 +65,8 @@ int main(int argc, char* argv[])
manager.doInit();
return 0;
}
- else
- {
- r = sd_event_loop(eventPtr.get());
- if (r < 0)
- {
- log<level::ERR>("Failed call to sd_event_loop",
- entry("ERROR=%s", strerror(-r)));
- }
- }
+
+ return event.loop();
}
//Log the useful metadata on these exceptions and let the app
//return 1 so it is restarted without a core dump.
diff --git a/control/manager.cpp b/control/manager.cpp
index 1078473..bc6b18e 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -75,7 +75,7 @@ bool checkCondition(sdbusplus::bus::bus& bus, const auto& c)
//Note: Future code will check 'mode' before starting control algorithm
Manager::Manager(sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
Mode mode) :
_bus(bus)
{
@@ -99,7 +99,7 @@ Manager::Manager(sdbusplus::bus::bus& bus,
for (auto& z : zones)
{
_zones.emplace(std::get<zoneNumPos>(z),
- std::make_unique<Zone>(mode, _bus, events, z));
+ std::make_unique<Zone>(mode, _bus, event, z));
}
break;
diff --git a/control/manager.hpp b/control/manager.hpp
index d049323..5b748a2 100644
--- a/control/manager.hpp
+++ b/control/manager.hpp
@@ -3,6 +3,7 @@
#include <memory>
#include <vector>
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
#include "types.hpp"
#include "zone.hpp"
@@ -36,11 +37,11 @@ class Manager
* _zoneLayouts data.
*
* @param[in] bus - The dbus object
- * @param[in] events - The sd_event pointer
+ * @param[in] event - The event loop
* @param[in] mode - The control mode
*/
Manager(sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
Mode mode);
/**
diff --git a/control/zone.cpp b/control/zone.cpp
index f4c50d9..0050899 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -37,7 +37,7 @@ using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
Zone::Zone(Mode mode,
sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
const ZoneDefinition& def) :
_bus(bus),
_fullSpeed(std::get<fullSpeedPos>(def)),
@@ -46,9 +46,9 @@ Zone::Zone(Mode mode,
_defCeilingSpeed(std::get<fullSpeedPos>(def)),
_incDelay(std::get<incDelayPos>(def)),
_decInterval(std::get<decIntervalPos>(def)),
- _incTimer(events, [this](){ this->incTimerExpired(); }),
- _decTimer(events, [this](){ this->decTimerExpired(); }),
- _sdEvents(events)
+ _incTimer(event, [this](){ this->incTimerExpired(); }),
+ _decTimer(event, [this](){ this->decTimerExpired(); }),
+ _eventLoop(event)
{
auto& fanDefs = std::get<fanListPos>(def);
@@ -347,7 +347,7 @@ void Zone::initEvent(const SetSpeedEvent& event)
);
std::unique_ptr<util::Timer> timer =
std::make_unique<util::Timer>(
- _sdEvents,
+ _eventLoop,
[this,
action = &(std::get<actionsPos>(event)),
group = &(std::get<groupPos>(event))]()
diff --git a/control/zone.hpp b/control/zone.hpp
index cd7e5d6..e035a64 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -4,6 +4,7 @@
#include <cassert>
#include <algorithm>
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
#include "fan.hpp"
#include "types.hpp"
#include "timer.hpp"
@@ -48,12 +49,12 @@ class Zone
*
* @param[in] mode - mode of fan control
* @param[in] bus - the dbus object
- * @param[in] events - sd_event pointer
+ * @param[in] event - Event loop reference
* @param[in] def - the fan zone definition data
*/
Zone(Mode mode,
sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
const ZoneDefinition& def);
/**
@@ -332,13 +333,13 @@ class Zone
void decTimerExpired();
/**
- * @brief Get the event pointer used with this zone's timers
+ * @brief Get the event loop used with this zone's timers
*
- * @return - The Dbus event pointer for timers
+ * @return - The event loop for timers
*/
- inline auto& getEventPtr()
+ inline auto& getEventLoop()
{
- return _sdEvents;
+ return _eventLoop;
}
/**
@@ -514,9 +515,9 @@ class Zone
phosphor::fan::util::Timer _decTimer;
/**
- * Dbus event used on set speed event timers
+ * Event loop used on set speed event timers
*/
- phosphor::fan::event::EventPtr& _sdEvents;
+ sdeventplus::Event _eventLoop;
/**
* The vector of fans in this zone
diff --git a/event.hpp b/event.hpp
index 71ca6a6..a937d6d 100644
--- a/event.hpp
+++ b/event.hpp
@@ -23,19 +23,6 @@ struct EventSourceDeleter
using EventSourcePtr = std::unique_ptr<sd_event_source, EventSourceDeleter>;
-/**
- * Customer deleter for sd_event
- */
-struct EventDeleter
-{
- void operator()(sd_event* event) const
- {
- sd_event_unref(event);
- }
-};
-
-using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
-
}
}
}
diff --git a/monitor/Makefile.am b/monitor/Makefile.am
index cb9b8a4..e8d9bbd 100644
--- a/monitor/Makefile.am
+++ b/monitor/Makefile.am
@@ -19,12 +19,14 @@ BUILT_SOURCES = fan_monitor_defs.cpp
phosphor_fan_monitor_LDADD = \
$(top_builddir)/libfan.la \
$(SDBUSPLUS_LIBS) \
+ $(SDEVENTPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
${PHOSPHOR_DBUS_INTERFACES_LIBS} \
-lstdc++fs
phosphor_fan_monitor_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
+ $(SDEVENTPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS) \
${PHOSPHOR_DBUS_INTERFACES_CFLAGS} \
-flto
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 39b32bb..014080d 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -31,7 +31,7 @@ using namespace phosphor::logging;
Fan::Fan(Mode mode,
sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
std::unique_ptr<trust::Manager>& trust,
const FanDefinition& def) :
_bus(bus),
@@ -58,7 +58,7 @@ Fan::Fan(Mode mode,
std::get<factorField>(s),
std::get<offsetField>(s),
std::get<timeoutField>(def),
- events));
+ event));
_trustManager->registerSensor(_sensors.back());
}
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index fb87b66..663e27e 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -1,9 +1,9 @@
#pragma once
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
#include <tuple>
#include <vector>
-#include "event.hpp"
#include "tach_sensor.hpp"
#include "trust_manager.hpp"
#include "types.hpp"
@@ -78,13 +78,13 @@ class Fan
*
* @param mode - mode of fan monitor
* @param bus - the dbus object
- * @param events - pointer to sd_event object
+ * @param event - event loop reference
* @param trust - the tach trust manager
* @param def - the fan definition structure
*/
Fan(Mode mode,
sdbusplus::bus::bus& bus,
- phosphor::fan::event::EventPtr& events,
+ const sdeventplus::Event& event,
std::unique_ptr<trust::Manager>& trust,
const FanDefinition& def);
diff --git a/monitor/main.cpp b/monitor/main.cpp
index 512e3f7..cba3832 100644
--- a/monitor/main.cpp
+++ b/monitor/main.cpp
@@ -15,9 +15,8 @@
*/
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
-#include <systemd/sd-daemon.h>
+#include <sdeventplus/event.hpp>
#include "argument.hpp"
-#include "event.hpp"
#include "fan.hpp"
#include "fan_defs.hpp"
#include "trust_manager.hpp"
@@ -27,8 +26,8 @@ using namespace phosphor::logging;
int main(int argc, char* argv[])
{
+ auto event = sdeventplus::Event::get_default();
auto bus = sdbusplus::bus::new_default();
- sd_event* events = nullptr;
std::vector<std::unique_ptr<Fan>> fans;
phosphor::fan::util::ArgumentParser args(argc, argv);
@@ -53,22 +52,12 @@ int main(int argc, char* argv[])
return 1;
}
- auto r = sd_event_default(&events);
- if (r < 0)
- {
- log<level::ERR>("Failed call to sd_event_default()",
- entry("ERROR=%s", strerror(-r)));
- return 1;
- }
-
std::unique_ptr<phosphor::fan::trust::Manager> trust =
std::make_unique<phosphor::fan::trust::Manager>(trustGroups);
- phosphor::fan::event::EventPtr eventPtr{events};
-
//Attach the event object to the bus object so we can
//handle both sd_events (for the timers) and dbus signals.
- bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
+ bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
for (const auto& fanDef : fanDefinitions)
{
@@ -83,7 +72,7 @@ int main(int argc, char* argv[])
}
}
fans.emplace_back(std::make_unique<Fan>(
- mode, bus, eventPtr, trust, fanDef));
+ mode, bus, event, trust, fanDef));
}
if (mode == Mode::init)
@@ -91,15 +80,6 @@ int main(int argc, char* argv[])
// Fans were initialized to be functional, exit
return 0;
}
- else
- {
- r = sd_event_loop(eventPtr.get());
- if (r < 0)
- {
- log<level::ERR>("Failed call to sd_event_loop",
- entry("ERROR=%s", strerror(-r)));
- }
- }
- return 1;
+ return event.loop();
}
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 6789ed8..de1affb 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -76,7 +76,7 @@ TachSensor::TachSensor(Mode mode,
size_t factor,
size_t offset,
size_t timeout,
- phosphor::fan::event::EventPtr& events) :
+ const sdeventplus::Event& event) :
_bus(bus),
_fan(fan),
_name(FAN_SENSOR_PATH + id),
@@ -88,7 +88,7 @@ TachSensor::TachSensor(Mode mode,
_offset(offset),
_timeout(timeout),
_timerMode(TimerMode::func),
- _timer(events, [this, &fan](){ fan.timerExpired(*this); })
+ _timer(event, [this, &fan](){ fan.timerExpired(*this); })
{
// Start from a known state of functional
setFunctional(true);
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index f59f6f5..c46aa00 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -3,7 +3,7 @@
#include <chrono>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
-#include "event.hpp"
+#include <sdeventplus/event.hpp>
#include "timer.hpp"
namespace phosphor
@@ -78,7 +78,7 @@ class TachSensor
* @param[in] factor - the factor of the sensor target
* @param[in] offset - the offset of the sensor target
* @param[in] timeout - Normal timeout value to use
- * @param[in] events - sd_event pointer
+ * @param[in] event - Event loop reference
*/
TachSensor(Mode mode,
sdbusplus::bus::bus& bus,
@@ -90,7 +90,7 @@ class TachSensor
size_t factor,
size_t offset,
size_t timeout,
- phosphor::fan::event::EventPtr& events);
+ const sdeventplus::Event& event);
/**
* @brief Returns the target speed value
diff --git a/presence/Makefile.am b/presence/Makefile.am
index eb4dd6c..8fa0259 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -16,11 +16,13 @@ phosphor_fan_presence_tach_SOURCES = \
phosphor_fan_presence_tach_LDADD = \
$(top_builddir)/libfan.la \
$(SDBUSPLUS_LIBS) \
+ $(SDEVENTPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
${PHOSPHOR_DBUS_INTERFACES_LIBS} \
$(LIBEVDEV_LIBS)
phosphor_fan_presence_tach_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
+ $(SDEVENTPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS) \
${PHOSPHOR_DBUS_INTERFACES_CFLAGS} \
$(LIBEVDEV_CFLAGS) \
diff --git a/presence/gpio.cpp b/presence/gpio.cpp
index 2a0a4c0..19593c2 100644
--- a/presence/gpio.cpp
+++ b/presence/gpio.cpp
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <memory>
+#include <functional>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <sdeventplus/event.hpp>
#include <tuple>
#include <xyz/openbmc_project/Common/Callout/error.hpp>
#include "gpio.hpp"
#include "rpolicy.hpp"
-#include "sdevent.hpp"
namespace phosphor
{
@@ -37,25 +37,23 @@ Gpio::Gpio(
evdevfd(open(device.c_str(), O_RDONLY | O_NONBLOCK)),
evdev(evdevpp::evdev::newFromFD(evdevfd())),
phys(physDevice),
- pin(physPin),
- callback(nullptr)
+ pin(physPin)
{
}
bool Gpio::start()
{
- callback = std::make_unique<sdevent::event::io::IO>(
- util::SDEvent::getEvent(),
- evdevfd(),
- [this](auto& s){this->ioCallback(s);});
+ source.emplace(sdeventplus::Event::get_default(),
+ evdevfd(), EPOLLIN,
+ std::bind(&Gpio::ioCallback, this));
currentState = present();
return currentState;
}
void Gpio::stop()
{
- callback = nullptr;
+ source.reset();
}
bool Gpio::present()
@@ -75,7 +73,7 @@ void Gpio::fail()
GPIO::CALLOUT_DEVICE_PATH(phys.c_str()));
}
-void Gpio::ioCallback(sdevent::source::Source& source)
+void Gpio::ioCallback()
{
unsigned int type, code, value;
diff --git a/presence/gpio.hpp b/presence/gpio.hpp
index 978fdd9..2829bea 100644
--- a/presence/gpio.hpp
+++ b/presence/gpio.hpp
@@ -1,9 +1,8 @@
#pragma once
-#include <memory>
+#include <sdeventplus/source/io.hpp>
+#include <optional>
#include "evdevpp/evdev.hpp"
-#include "sdevent/io.hpp"
-#include "sdevent/source.hpp"
#include "psensor.hpp"
#include "utility.hpp"
@@ -85,7 +84,7 @@ class Gpio : public PresenceSensor
virtual RedundancyPolicy& getPolicy() = 0;
/** @brief sdevent io callback. */
- void ioCallback(sdevent::source::Source& source);
+ void ioCallback();
/** The current state of the sensor. */
bool currentState;
@@ -102,8 +101,8 @@ class Gpio : public PresenceSensor
/** Gpio pin number. */
unsigned int pin;
- /** sdevent io callback handle. */
- std::unique_ptr<sdevent::event::io::IO> callback;
+ /** sdevent io handle. */
+ std::optional<sdeventplus::source::IO> source;
};
} // namespace presence
diff --git a/presence/tach_detect.cpp b/presence/tach_detect.cpp
index da0f40f..9b23571 100644
--- a/presence/tach_detect.cpp
+++ b/presence/tach_detect.cpp
@@ -15,24 +15,20 @@
*/
#include "generated.hpp"
#include "sdbusplus.hpp"
-#include "sdevent.hpp"
-
+#include <sdeventplus/event.hpp>
int main(void)
{
using namespace phosphor::fan;
- auto& event = util::SDEvent::getEvent();
- event.attach(util::SDBusPlus::getBus());
+ auto event = sdeventplus::Event::get_default();
+ util::SDBusPlus::getBus().attach_event(
+ event.get(), SD_EVENT_PRIORITY_NORMAL);
for (auto& p: presence::ConfigPolicy::get())
{
p->monitor();
}
- event.loop();
-
- // The loop should never exit. Exit with
- // non zero status just in case.
- return 1;
+ return event.loop();
}
diff --git a/test/Makefile.am b/test/Makefile.am
index 13ff55e..c4cd77d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,6 +8,6 @@ check_PROGRAMS = timertest
timertest_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS)
timertest_CXXFLAGS = $(PTHREAD_CFLAGS) ${PHOSPHOR_DBUS_INTERFACES_CFLAGS}
timertest_LDFLAGS = -lgtest_main -lgtest $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS) \
- $(SYSTEMD_LIBS) ${SDBUSPLUS_LIBS} ${PHOSPHOR_DBUS_INTERFACES_LIBS}
+ $(SYSTEMD_LIBS) ${SDBUSPLUS_LIBS} $(SDEVENTPLUS_LIBS) ${PHOSPHOR_DBUS_INTERFACES_LIBS}
timertest_SOURCES = timertest.cpp
timertest_LDADD = $(top_builddir)/timer.o
diff --git a/test/timertest.cpp b/test/timertest.cpp
index 9d05e55..845a0e1 100644
--- a/test/timertest.cpp
+++ b/test/timertest.cpp
@@ -16,7 +16,7 @@
#include <iostream>
#include <chrono>
#include <gtest/gtest.h>
-#include "event.hpp"
+#include <sdeventplus/event.hpp>
#include "timer.hpp"
/**
@@ -34,21 +34,12 @@ using namespace std::chrono;
class TimerTest : public ::testing::Test
{
public:
- // systemd event handler
- phosphor::fan::event::EventPtr events;
-
- // Need this so that events can be initialized.
- int rc;
+ // event loop
+ sdeventplus::Event event;
// Gets called as part of each TEST_F construction
- TimerTest()
- {
- sd_event* event = nullptr;
- auto rc = sd_event_default(&event);
- EXPECT_GE(rc, 0);
-
- events.reset(event);
- }
+ TimerTest() : event(sdeventplus::Event::get_default())
+ { }
};
/**
@@ -91,8 +82,8 @@ class CallbackTester
class CallbackTesterWithTimer : public CallbackTester
{
public:
- CallbackTesterWithTimer(phosphor::fan::event::EventPtr& events) :
- _timer(events,
+ CallbackTesterWithTimer(const sdeventplus::Event& event) :
+ _timer(event,
std::bind(&CallbackTesterWithTimer::callbackFunction,
this))
{
@@ -135,7 +126,7 @@ TEST_F(TimerTest, timerExpiresAfter2seconds)
{
CallbackTester tester;
- Timer timer(events,
+ Timer timer(event,
std::bind(&CallbackTester::callbackFunction, &tester));
@@ -148,13 +139,12 @@ TEST_F(TimerTest, timerExpiresAfter2seconds)
EXPECT_EQ(true, timer.running());
int count = 0;
- auto sleepTime = duration_cast<microseconds>(seconds(1));
//Wait for 2 1s timeouts
while (count < 2)
{
// Returns 0 on timeout and positive number on dispatch
- if (sd_event_run(events.get(), sleepTime.count()) == 0)
+ if (event.run(seconds(1)) == 0)
{
count++;
}
@@ -172,7 +162,7 @@ TEST_F(TimerTest, timerRestart)
{
CallbackTester tester;
- Timer timer(events,
+ Timer timer(event,
std::bind(&CallbackTester::callbackFunction, &tester));
@@ -180,8 +170,7 @@ TEST_F(TimerTest, timerRestart)
timer.start(time, Timer::TimerType::oneshot);
//wait for a second
- auto sleepTime = duration_cast<microseconds>(seconds(1));
- auto rc = sd_event_run(events.get(), sleepTime.count());
+ auto rc = event.run(seconds(1));
//expect the timeout, not the dispatch
//and the timer should still be running
@@ -192,7 +181,7 @@ TEST_F(TimerTest, timerRestart)
timer.start(time, Timer::TimerType::oneshot);
//Wait just 1s, make sure not done
- rc = sd_event_run(events.get(), sleepTime.count());
+ rc = event.run(seconds(1));
EXPECT_EQ(0, rc);
EXPECT_EQ(true, timer.running());
EXPECT_EQ(false, tester.gotCallback());
@@ -202,7 +191,7 @@ TEST_F(TimerTest, timerRestart)
while (count < 1)
{
// Returns 0 on timeout and positive number on dispatch
- if (sd_event_run(events.get(), sleepTime.count()) == 0)
+ if (event.run(seconds(1)) == 0)
{
count++;
}
@@ -221,17 +210,15 @@ TEST_F(TimerTest, timerStop)
{
CallbackTester tester;
- Timer timer(events,
+ Timer timer(event,
std::bind(&CallbackTester::callbackFunction, &tester));
auto time = duration_cast<microseconds>(seconds(2));
timer.start(time, Timer::TimerType::oneshot);
- auto sleepTime = duration_cast<microseconds>(seconds(1));
-
//wait 1s
- auto rc = sd_event_run(events.get(), sleepTime.count());
+ auto rc = event.run(seconds(1));
//expect the timeout, not the dispatch
EXPECT_EQ(rc, 0);
@@ -243,8 +230,7 @@ TEST_F(TimerTest, timerStop)
EXPECT_EQ(false, tester.gotCallback());
//Wait another 2s, make sure no callbacks happened
- sleepTime = duration_cast<microseconds>(seconds(2));
- rc = sd_event_run(events.get(), sleepTime.count());
+ rc = event.run(seconds(2));
EXPECT_EQ(rc, 0);
EXPECT_EQ(false, timer.running());
@@ -258,7 +244,7 @@ TEST_F(TimerTest, timerStop)
*/
TEST_F(TimerTest, timerRestartFromCallback)
{
- CallbackTesterWithTimer tester(events);
+ CallbackTesterWithTimer tester(event);
auto& timer = tester.getTimer();
@@ -269,11 +255,10 @@ TEST_F(TimerTest, timerRestartFromCallback)
//for another 1s
int count = 0;
- auto sleepTime = duration_cast<microseconds>(seconds(1));
while (count < 3)
{
// Returns 0 on timeout and positive number on dispatch
- if (sd_event_run(events.get(), sleepTime.count()) == 0)
+ if (event.run(seconds(1)) == 0)
{
count++;
}
@@ -293,7 +278,7 @@ TEST_F(TimerTest, timerNoEventRun)
{
CallbackTester tester;
- Timer timer(events,
+ Timer timer(event,
std::bind(&CallbackTester::callbackFunction, &tester));
@@ -310,8 +295,7 @@ TEST_F(TimerTest, timerNoEventRun)
EXPECT_EQ(false, tester.gotCallback());
//Now process an event
- auto sleepTime = duration_cast<microseconds>(milliseconds(5));
- auto rc = sd_event_run(events.get(), sleepTime.count());
+ auto rc = event.run(milliseconds(5));
EXPECT_GT(rc, 0);
EXPECT_EQ(false, timer.running());
@@ -327,18 +311,17 @@ TEST_F(TimerTest, RepeatingTimer)
{
CallbackTester tester;
- Timer timer(events,
+ Timer timer(event,
std::bind(&CallbackTester::callbackFunction, &tester));
auto time = duration_cast<microseconds>(seconds(1));
timer.start(time, Timer::TimerType::repeating);
int count = 0;
- auto sleepTime = duration_cast<microseconds>(milliseconds(500));
while (count < 5)
{
- if (sd_event_run(events.get(), sleepTime.count()) == 0)
+ if (event.run(milliseconds(500)) == 0)
{
count++;
}
diff --git a/timer.cpp b/timer.cpp
index 6929717..36057ab 100644
--- a/timer.cpp
+++ b/timer.cpp
@@ -32,16 +32,15 @@ using namespace phosphor::logging;
using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
Error::InternalFailure;
-Timer::Timer(phosphor::fan::event::EventPtr& events,
+Timer::Timer(const sdeventplus::Event& event,
std::function<void()> callbackFunc) :
- timeEvent(events),
callback(callbackFunc),
timeout(0)
{
sd_event_source* source = nullptr;
// Start with an infinite expiration time
- auto r = sd_event_add_time(timeEvent.get(),
+ auto r = sd_event_add_time(event.get(),
&source,
CLOCK_MONOTONIC, // Time base
UINT64_MAX, // Expire time - way long time
diff --git a/timer.hpp b/timer.hpp
index 979a1cc..3b7783b 100644
--- a/timer.hpp
+++ b/timer.hpp
@@ -3,6 +3,7 @@
#include <chrono>
#include <functional>
#include <memory>
+#include <sdeventplus/event.hpp>
#include "event.hpp"
namespace phosphor
@@ -46,10 +47,10 @@ class Timer
/**
* @brief Constructs timer object
*
- * @param[in] events - sd_event pointer, previously created
+ * @param[in] event - Event loop reference, previously created
* @param[in] callbackFunc - The function to call on timer expiration
*/
- Timer(phosphor::fan::event::EventPtr& events,
+ Timer(const sdeventplus::Event& event,
std::function<void()> callbackFunc);
/**
@@ -135,11 +136,6 @@ class Timer
void setTimeout();
/**
- * @brief The sd_event structure
- */
- phosphor::fan::event::EventPtr& timeEvent;
-
- /**
* @brief Source of events
*/
phosphor::fan::event::EventSourcePtr eventSource;
OpenPOWER on IntegriCloud