UpdateVirtualSensor uses information from signals
UpdateVirtualSensor uses information obtained from signals to avoid
extensive dbus queries.
Tested:
1:Execute DBus cmd to see if VirtualSensor can correctly obtain the
value of DbusSensor
busctl tree xyz.openbmc_project.VirtualSensor
busctl introspect xyz.openbmc_project.VirtualSensor xxx
2:Waiting for the value change of DbusSensor,Check if the value of
the virtual sensor has changed after the dbusSensor changes.
Fixes openbmc/phosphor-virtual-sensor#1
Change-Id: If11f9017b31ce5cf06f910a38c65637c55d74b24
Signed-off-by: Tao Lin <lintao.lc@ieisystem.com>
diff --git a/virtualSensor.hpp b/virtualSensor.hpp
index 01e3221..0667246 100644
--- a/virtualSensor.hpp
+++ b/virtualSensor.hpp
@@ -1,3 +1,5 @@
+#pragma once
+
#include "dbusSensor.hpp"
#include "exprtkTools.hpp"
#include "thresholds.hpp"
@@ -11,9 +13,7 @@
#include <map>
#include <string>
-namespace phosphor
-{
-namespace virtualSensor
+namespace phosphor::virtual_sensor
{
PHOSPHOR_LOG2_USING_WITH_FLAGS;
@@ -65,7 +65,8 @@
* @param[in] path - The Dbus path of sensor
* @param[in] ctx - sensor context for update
*/
- SensorParam(sdbusplus::bus_t& bus, const std::string& path, void* ctx) :
+ SensorParam(sdbusplus::bus_t& bus, const std::string& path,
+ VirtualSensor& ctx) :
dbusSensor(std::make_unique<DbusSensor>(bus, path, ctx)),
paramType(dbusParam)
{}
@@ -75,7 +76,9 @@
private:
std::unique_ptr<DbusSensor> dbusSensor = nullptr;
- double value = 0;
+
+ /** @brief virtual sensor value */
+ double value = std::numeric_limits<double>::quiet_NaN();
ParamType paramType;
};
@@ -122,8 +125,10 @@
/** @brief Set sensor value */
void setSensorValue(double value);
+
/** @brief Update sensor at regular intrval */
void updateVirtualSensor();
+
/** @brief Check if sensor value is in valid range */
bool sensorInRange(double value);
@@ -300,5 +305,4 @@
void setupMatches();
};
-} // namespace virtualSensor
-} // namespace phosphor
+} // namespace phosphor::virtual_sensor