summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--event.hpp41
-rw-r--r--monitor/fan.cpp2
-rw-r--r--monitor/fan.hpp3
-rw-r--r--monitor/main.cpp12
-rw-r--r--monitor/tach_sensor.cpp2
-rw-r--r--monitor/tach_sensor.hpp3
-rw-r--r--test/timertest.cpp13
-rw-r--r--timer.cpp2
-rw-r--r--timer.hpp19
9 files changed, 60 insertions, 37 deletions
diff --git a/event.hpp b/event.hpp
new file mode 100644
index 0000000..71ca6a6
--- /dev/null
+++ b/event.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <memory>
+#include <systemd/sd-event.h>
+
+namespace phosphor
+{
+namespace fan
+{
+namespace event
+{
+
+/**
+ * Custom deleter for sd_event_source
+ */
+struct EventSourceDeleter
+{
+ void operator()(sd_event_source* eventSource) const
+ {
+ sd_event_source_unref(eventSource);
+ }
+};
+
+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/fan.cpp b/monitor/fan.cpp
index 639d88e..17f5812 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -38,7 +38,7 @@ constexpr auto OPERATIONAL_STATUS_INTF =
Fan::Fan(sdbusplus::bus::bus& bus,
- std::shared_ptr<sd_event>& events,
+ phosphor::fan::event::EventPtr& events,
const FanDefinition& def) :
_bus(bus),
_name(std::get<fanNameField>(def)),
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 910b4eb..8e7f86f 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -3,6 +3,7 @@
#include <sdbusplus/bus.hpp>
#include <tuple>
#include <vector>
+#include "event.hpp"
#include "tach_sensor.hpp"
#include "types.hpp"
@@ -72,7 +73,7 @@ class Fan
* @param def - the fan definition structure
*/
Fan(sdbusplus::bus::bus& bus,
- std::shared_ptr<sd_event>& events,
+ phosphor::fan::event::EventPtr& events,
const FanDefinition& def);
/**
diff --git a/monitor/main.cpp b/monitor/main.cpp
index 6d51fbb..c10efb9 100644
--- a/monitor/main.cpp
+++ b/monitor/main.cpp
@@ -15,6 +15,7 @@
*/
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
+#include "event.hpp"
#include "fan.hpp"
#include "fan_defs.hpp"
@@ -22,16 +23,11 @@ using namespace phosphor::fan::monitor;
using namespace phosphor::logging;
-void EventDeleter(sd_event* event)
-{
- sd_event_unref(event);
-}
-
int main()
{
auto bus = sdbusplus::bus::new_default();
sd_event* events = nullptr;
- std::vector<std::unique_ptr<Fan>> fans;
+ std::vector<Fan> fans;
auto r = sd_event_default(&events);
if (r < 0)
@@ -41,7 +37,7 @@ int main()
return -1;
}
- std::shared_ptr<sd_event> eventPtr{events, EventDeleter};
+ 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.
@@ -49,7 +45,7 @@ int main()
for (const auto& fanDef : fanDefinitions)
{
- fans.emplace_back(std::make_unique<Fan>(bus, eventPtr, fanDef));
+ fans.emplace_back(bus, eventPtr, fanDef);
}
r = sd_event_loop(eventPtr.get());
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 806eed7..80eb974 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -85,7 +85,7 @@ TachSensor::TachSensor(sdbusplus::bus::bus& bus,
const std::string& id,
bool hasTarget,
size_t timeout,
- std::shared_ptr<sd_event>& events) :
+ phosphor::fan::event::EventPtr& events) :
_bus(bus),
_fan(fan),
_name(FAN_SENSOR_PATH + id),
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index 7a65b64..84e02fe 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -3,6 +3,7 @@
#include <chrono>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
+#include "event.hpp"
#include "timer.hpp"
namespace phosphor
@@ -54,7 +55,7 @@ class TachSensor
const std::string& id,
bool hasTarget,
size_t timeout,
- std::shared_ptr<sd_event>& events);
+ phosphor::fan::event::EventPtr& events);
/**
* @brief Returns the target speed value
diff --git a/test/timertest.cpp b/test/timertest.cpp
index 40b2ddf..9d05e55 100644
--- a/test/timertest.cpp
+++ b/test/timertest.cpp
@@ -16,6 +16,7 @@
#include <iostream>
#include <chrono>
#include <gtest/gtest.h>
+#include "event.hpp"
#include "timer.hpp"
/**
@@ -25,12 +26,6 @@
using namespace phosphor::fan::util;
using namespace std::chrono;
-void EventDeleter(sd_event* events)
-{
- sd_event_unref(events);
-}
-
-using EventPtr = std::shared_ptr<sd_event>;
/**
* Class to ensure sd_events are correctly
@@ -40,7 +35,7 @@ class TimerTest : public ::testing::Test
{
public:
// systemd event handler
- EventPtr events;
+ phosphor::fan::event::EventPtr events;
// Need this so that events can be initialized.
int rc;
@@ -52,7 +47,7 @@ class TimerTest : public ::testing::Test
auto rc = sd_event_default(&event);
EXPECT_GE(rc, 0);
- events.reset(event, EventDeleter);
+ events.reset(event);
}
};
@@ -96,7 +91,7 @@ class CallbackTester
class CallbackTesterWithTimer : public CallbackTester
{
public:
- CallbackTesterWithTimer(EventPtr events) :
+ CallbackTesterWithTimer(phosphor::fan::event::EventPtr& events) :
_timer(events,
std::bind(&CallbackTesterWithTimer::callbackFunction,
this))
diff --git a/timer.cpp b/timer.cpp
index 41a8138..d371c98 100644
--- a/timer.cpp
+++ b/timer.cpp
@@ -27,7 +27,7 @@ namespace util
using namespace phosphor::logging;
-Timer::Timer(EventPtr& events,
+Timer::Timer(phosphor::fan::event::EventPtr& events,
std::function<void()> callbackFunc) :
timeEvent(events),
callback(callbackFunc),
diff --git a/timer.hpp b/timer.hpp
index ea28176..979a1cc 100644
--- a/timer.hpp
+++ b/timer.hpp
@@ -3,7 +3,7 @@
#include <chrono>
#include <functional>
#include <memory>
-#include <systemd/sd-event.h>
+#include "event.hpp"
namespace phosphor
{
@@ -12,17 +12,6 @@ namespace fan
namespace util
{
-struct EventSourceDeleter
-{
- void operator()(sd_event_source* eventSource) const
- {
- sd_event_source_unref(eventSource);
- }
-};
-
-using EventSourcePtr = std::unique_ptr<sd_event_source, EventSourceDeleter>;
-
-using EventPtr = std::shared_ptr<sd_event>;
/**
* @class Timer
@@ -60,7 +49,7 @@ class Timer
* @param[in] events - sd_event pointer, previously created
* @param[in] callbackFunc - The function to call on timer expiration
*/
- Timer(EventPtr& events,
+ Timer(phosphor::fan::event::EventPtr& events,
std::function<void()> callbackFunc);
/**
@@ -148,12 +137,12 @@ class Timer
/**
* @brief The sd_event structure
*/
- EventPtr timeEvent;
+ phosphor::fan::event::EventPtr& timeEvent;
/**
* @brief Source of events
*/
- EventSourcePtr eventSource;
+ phosphor::fan::event::EventSourcePtr eventSource;
/**
* @brief Either 'repeating' or 'oneshot'
OpenPOWER on IntegriCloud