From 0fe4cb34b5292a559693407ebc0b38645c6c19d6 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Thu, 18 Oct 2018 19:19:58 -0700 Subject: mainloop: Use sdeventplus Convert to using sdeventplus instead of sd_event directly. Change-Id: Ie8ee25c2d75ac4c56b88fb79f70eaa53c4f7b6e4 Signed-off-by: William A. Kennington III --- Makefile.am | 2 ++ configure.ac | 1 + mainloop.cpp | 16 +++++++--------- mainloop.hpp | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index c0a30ea..3d5f786 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,11 +9,13 @@ libhwmon_la_LDFLAGS = -static libhwmon_la_LIBADD = \ -lstdc++fs \ $(SDBUSPLUS_LIBS) \ + $(SDEVENTPLUS_LIBS) \ $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ $(PHOSPHOR_LOGGING_LIBS) \ $(GPIOPLUS_LIBS) libhwmon_la_CXXFLAGS = \ $(SDBUSPLUS_CFLAGS) \ + $(SDEVENTPLUS_CFLAGS) \ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ $(PHOSPHOR_LOGGING_CFLAGS) \ $(GPIOPLUS_CFLAGS) diff --git a/configure.ac b/configure.ac index 36d10ec..c3a92c7 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,7 @@ AC_PROG_MAKE_SET # Checks for libraries. PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], [], [AC_MSG_ERROR(["sdbusplus required and not found."])]) +PKG_CHECK_MODULES([SDEVENTPLUS], [sdeventplus], [], [AC_MSG_ERROR(["sdeventplus required and not found."])]) PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces], [], [AC_MSG_ERROR(["phosphor-dbus-interfaces required and not found."])]) PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging], [], [AC_MSG_ERROR(["phosphor-logging required and not found."])]) PKG_CHECK_MODULES([GPIOPLUS], [gpioplus],, [AC_MSG_ERROR([Could not find gpioplus...openbmc/gpioplus package required])]) diff --git a/mainloop.cpp b/mainloop.cpp index 7435ef3..3c6d232 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -243,7 +243,8 @@ MainLoop::MainLoop(sdbusplus::bus::bus&& bus, const std::string& param, const char* prefix, const char* root) : _bus(std::move(bus)), _manager(_bus, root), _pathParam(param), _hwmonRoot(), _instance(), - _devPath(devPath), _prefix(prefix), _root(root), state(), ioAccess(path) + _devPath(devPath), _prefix(prefix), _root(root), state(), ioAccess(path), + event(sdeventplus::Event::get_default()) { // Strip off any trailing slashes. std::string p = path; @@ -268,21 +269,18 @@ MainLoop::MainLoop(sdbusplus::bus::bus&& bus, const std::string& param, void MainLoop::shutdown() noexcept { timer->state(phosphor::hwmon::timer::OFF); - sd_event_exit(loop, 0); - loop = nullptr; + event.exit(0); } void MainLoop::run() { init(); - sd_event_default(&loop); - std::function callback(std::bind(&MainLoop::read, this)); try { timer = std::make_unique( - loop, callback, std::chrono::microseconds(_interval), + event.get(), callback, std::chrono::microseconds(_interval), phosphor::hwmon::timer::ON); // TODO: Issue#6 - Optionally look at polling interval sysfs entry. @@ -290,10 +288,10 @@ void MainLoop::run() // TODO: Issue#7 - Should probably periodically check the SensorSet // for new entries. - _bus.attach_event(loop, SD_EVENT_PRIORITY_IMPORTANT); - sd_event_loop(loop); + _bus.attach_event(event.get(), SD_EVENT_PRIORITY_IMPORTANT); + event.loop(); } - catch (const std::system_error& e) + catch (const std::exception& e) { log("Error in sysfs polling loop", entry("ERROR=%s", e.what())); diff --git a/mainloop.hpp b/mainloop.hpp index 9c50c78..87f6ed0 100644 --- a/mainloop.hpp +++ b/mainloop.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -99,8 +100,8 @@ class MainLoop hwmonio::HwmonIO ioAccess; /** @brief Timer */ std::unique_ptr timer; - /** @brief the sd_event structure */ - sd_event* loop = nullptr; + /** @brief the Event Loop structure */ + sdeventplus::Event event; /** @brief Store the specifications of sensor objects */ std::map> sensorObjects; -- cgit v1.2.1