From 1cfc2f11b13412a15f8478cebc35e50e6feb13a2 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 19 Oct 2018 17:29:46 -0700 Subject: Switch sd_event loops to sdeventplus This change is mostly focused around plumbing the sdeventplus::Event object everywhere and using the member functions provided for the event. No migration to the timer utility is performed yet. Change-Id: I912ab82bc081239d3b7c3cf7c5caca6742ef9c87 Signed-off-by: William A. Kennington III --- monitor/Makefile.am | 2 ++ monitor/fan.cpp | 4 ++-- monitor/fan.hpp | 6 +++--- monitor/main.cpp | 30 +++++------------------------- monitor/tach_sensor.cpp | 4 ++-- monitor/tach_sensor.hpp | 6 +++--- 6 files changed, 17 insertions(+), 35 deletions(-) (limited to 'monitor') 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, const FanDefinition& def) : _bus(bus), @@ -58,7 +58,7 @@ Fan::Fan(Mode mode, std::get(s), std::get(s), std::get(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 +#include #include #include -#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, 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 #include -#include +#include #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> 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("Failed call to sd_event_default()", - entry("ERROR=%s", strerror(-r))); - return 1; - } - std::unique_ptr trust = std::make_unique(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( - 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("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 #include #include -#include "event.hpp" +#include #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 -- cgit v1.2.1