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.cpp b/virtualSensor.cpp
index e773433..e74ed4c 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -14,34 +14,7 @@
PHOSPHOR_LOG2_USING_WITH_FLAGS;
-int handleDbusSignal(sd_bus_message* msg, void* usrData, sd_bus_error*)
-{
- if (usrData == nullptr)
- {
- throw std::runtime_error("Invalid match");
- }
-
- auto sdbpMsg = sdbusplus::message_t(msg);
- std::string msgIfce;
- std::map<std::string, std::variant<int64_t, double, bool>> msgData;
-
- sdbpMsg.read(msgIfce, msgData);
-
- if (msgData.find("Value") != msgData.end())
- {
- using namespace phosphor::virtualSensor;
- VirtualSensor* obj = static_cast<VirtualSensor*>(usrData);
- // TODO(openbmc/phosphor-virtual-sensor#1): updateVirtualSensor should
- // be changed to take the information we got from the signal, to avoid
- // having to do numerous dbus queries.
- obj->updateVirtualSensor();
- }
- return 0;
-}
-
-namespace phosphor
-{
-namespace virtualSensor
+namespace phosphor::virtual_sensor
{
FuncMaxIgnoreNaN<double> VirtualSensor::funcMaxIgnoreNaN;
@@ -234,7 +207,7 @@
auto sensorObjPath = sensorDbusPath + sensorType + "/" + sensor;
auto paramPtr = std::make_unique<SensorParam>(bus, sensorObjPath,
- this);
+ *this);
symbols.create_variable(sensor);
paramMap.emplace(std::move(sensor), std::move(paramPtr));
}
@@ -357,7 +330,7 @@
auto path = sensorDbusPath + sensorType + "/" + name;
auto paramPtr = std::make_unique<SensorParam>(bus, path,
- this);
+ *this);
std::string paramName = j["ParamName"];
symbols.create_variable(paramName);
paramMap.emplace(std::move(paramName), std::move(paramPtr));
@@ -1057,8 +1030,7 @@
}
}
-} // namespace virtualSensor
-} // namespace phosphor
+} // namespace phosphor::virtual_sensor
/**
* @brief Main
@@ -1073,7 +1045,7 @@
"/xyz/openbmc_project/sensors");
// Create an virtual sensors object
- phosphor::virtualSensor::VirtualSensors virtualSensors(bus);
+ phosphor::virtual_sensor::VirtualSensors virtualSensors(bus);
// Request service bus name
bus.request_name("xyz.openbmc_project.VirtualSensor");