Add sensor reading timer
Added timer for reading sensor at regular interval defined for each
sensor in configuration file.
Tested: Verified this by running following busctrl command and checked
value as it is changing regularly.
busctl introspect --no-page xyz.openbmc_project.HealthMon
/xyz/openbmc_project/sensors/utilization/CPU
busctl introspect --no-page xyz.openbmc_project.HealthMon
/xyz/openbmc_project/sensors/utilization/Memory
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: I7da085e24b68c0b9f9bf1c13c567024c69f65d70
diff --git a/healthMonitor.hpp b/healthMonitor.hpp
index e8230fa..09f5539 100644
--- a/healthMonitor.hpp
+++ b/healthMonitor.hpp
@@ -1,6 +1,8 @@
#include <nlohmann/json.hpp>
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
#include <xyz/openbmc_project/Sensor/Value/server.hpp>
@@ -58,7 +60,9 @@
HealthSensor(sdbusplus::bus::bus& bus, const char* objPath,
HealthConfig& sensorConfig) :
healthIfaces(bus, objPath),
- bus(bus), sensorConfig(sensorConfig)
+ bus(bus), sensorConfig(sensorConfig),
+ timerEvent(sdeventplus::Event::get_default()),
+ readTimer(timerEvent, std::bind(&HealthSensor::readHealthSensor, this))
{
initHealthSensor();
}
@@ -73,8 +77,17 @@
void setSensorThreshold(double criticalHigh, double warningHigh);
private:
+ /** @brief sdbusplus bus client connection. */
sdbusplus::bus::bus& bus;
+ /** @brief Sensor config from config file */
HealthConfig& sensorConfig;
+ /** @brief the Event Loop structure */
+ sdeventplus::Event timerEvent;
+ /** @brief Sensor Read Timer */
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> readTimer;
+
+ /** @brief Read sensor at regular intrval */
+ void readHealthSensor();
};
class HealthMon