summaryrefslogtreecommitdiffstats
path: root/presence
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-10-19 17:29:46 -0700
committerWilliam A. Kennington III <wak@google.com>2018-10-29 15:59:03 -0700
commit1cfc2f11b13412a15f8478cebc35e50e6feb13a2 (patch)
tree05986154355a3d6c0667368c12cf34d7ad97d4cd /presence
parent5882e0c0593edaf464eea960f1ab7b2f5cd10240 (diff)
downloadphosphor-fan-presence-1cfc2f11b13412a15f8478cebc35e50e6feb13a2.tar.gz
phosphor-fan-presence-1cfc2f11b13412a15f8478cebc35e50e6feb13a2.zip
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 <wak@google.com>
Diffstat (limited to 'presence')
-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
4 files changed, 20 insertions, 25 deletions
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();
}
OpenPOWER on IntegriCloud