regs: Add an event timer for monitoring
Create and enable a repeating 1 second timer when monitoring is enabled.
Delete the timer when monitoring is disabled.
Tested:
Timer created when monitoring is enabled
Each timer expiration calls bound callback function
Timer stopped/deleted when monitoring is disabled
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I990124fb727bb0a0545ce06f9c878e81b572c7a5
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index 77c715a..d7743b7 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -18,6 +18,8 @@
#include <sdbusplus/bus.hpp>
+#include <chrono>
+
namespace phosphor
{
namespace power
@@ -25,8 +27,8 @@
namespace regulators
{
-Manager::Manager(sdbusplus::bus::bus& bus) :
- ManagerObject(bus, objPath, true), bus(bus)
+Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
+ ManagerObject(bus, objPath, true), bus(bus), eventLoop(event)
{
// TODO get property (IM keyword)
// call parse json function
@@ -48,14 +50,24 @@
{
if (enable)
{
- // TODO Enable timer event that will do the monitoring
+ Timer timer(eventLoop, std::bind(&Manager::timerExpired, this));
+ // Set timer as a repeating 1sec timer
+ timer.restart(std::chrono::milliseconds(1000));
+ timers.emplace_back(std::move(timer));
}
else
{
- // TODO Disable/delete timer event to stop monitoring
+ // Delete all timers to disable monitoring
+ timers.clear();
}
}
+void Manager::timerExpired()
+{
+ // TODO Analyze, refresh sensor status, and
+ // collect/update telemetry for each regulator
+}
+
} // namespace regulators
} // namespace power
} // namespace phosphor