summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-10-18 19:19:58 -0700
committerWilliam A. Kennington III <wak@google.com>2018-10-18 19:19:58 -0700
commit0fe4cb34b5292a559693407ebc0b38645c6c19d6 (patch)
treec44e29c3ba94bd97bd74751b2d2c16e7ea01f993
parent4cbdfef205ba4011018a3a287dd238e00509a757 (diff)
downloadphosphor-hwmon-0fe4cb34b5292a559693407ebc0b38645c6c19d6.tar.gz
phosphor-hwmon-0fe4cb34b5292a559693407ebc0b38645c6c19d6.zip
mainloop: Use sdeventplus
Convert to using sdeventplus instead of sd_event directly. Change-Id: Ie8ee25c2d75ac4c56b88fb79f70eaa53c4f7b6e4 Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac1
-rw-r--r--mainloop.cpp16
-rw-r--r--mainloop.hpp5
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<void()> callback(std::bind(&MainLoop::read, this));
try
{
timer = std::make_unique<phosphor::hwmon::Timer>(
- 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<level::ERR>("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 <memory>
#include <optional>
#include <sdbusplus/server.hpp>
+#include <sdeventplus/event.hpp>
#include <string>
#include <vector>
@@ -99,8 +100,8 @@ class MainLoop
hwmonio::HwmonIO ioAccess;
/** @brief Timer */
std::unique_ptr<phosphor::hwmon::Timer> 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<SensorSet::key_type, std::unique_ptr<sensor::Sensor>>
sensorObjects;
OpenPOWER on IntegriCloud