22
33#include " common/utils.hpp"
44#include " requester/handler.hpp"
5+ #include " sensor_manager.hpp"
56
67#include < libpldm/platform.h>
78
@@ -15,6 +16,26 @@ namespace pldm
1516namespace platform_mc
1617{
1718
19+ double SensorValue::value () const
20+ {
21+ if (this ->nSensor .sensorManager && nSensor.isReady && !nSensor.pollPending )
22+ {
23+ nSensor.pollPending = true ;
24+
25+ nSensor.scope .spawn (
26+ [](SensorManager* manager, NumericSensor* sensor) -> exec::task<void > {
27+ auto sPtr = std::shared_ptr<NumericSensor>(sensor, [](auto ) {});
28+ co_await manager->getSensorReading (sPtr );
29+ sensor->pollPending = false ;
30+ co_return ;
31+ }(nSensor.sensorManager , const_cast <NumericSensor*>(&nSensor))
32+ );
33+ }
34+
35+ auto value = ValueIntf::value ();
36+ return value;
37+ }
38+
1839inline bool NumericSensor::createInventoryPath (
1940 const std::string& associationPath, const std::string& sensorName,
2041 const uint16_t entityType, const uint16_t entityInstanceNum,
@@ -163,7 +184,9 @@ void NumericSensor::setSensorUnit(uint8_t baseUnit)
163184NumericSensor::NumericSensor (
164185 const pldm_tid_t tid, const bool sensorDisabled,
165186 std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr, std::string& sensorName,
166- std::string& associationPath) : tid(tid), sensorName(sensorName)
187+ std::string& associationPath, SensorManager* sensorManager,
188+ exec::async_scope& scoperef) :
189+ tid (tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
167190{
168191 if (!pdr)
169192 {
@@ -289,7 +312,7 @@ NumericSensor::NumericSensor(
289312 {
290313 try
291314 {
292- valueIntf = std::make_unique<ValueIntf >(bus, path.c_str ());
315+ valueIntf = std::make_unique<SensorValue >(bus, path.c_str (), * this );
293316 }
294317 catch (const sdbusplus::exception_t & e)
295318 {
@@ -419,8 +442,9 @@ NumericSensor::NumericSensor(
419442NumericSensor::NumericSensor (
420443 const pldm_tid_t tid, const bool sensorDisabled,
421444 std::shared_ptr<pldm_compact_numeric_sensor_pdr> pdr,
422- std::string& sensorName, std::string& associationPath) :
423- tid (tid), sensorName(sensorName)
445+ std::string& sensorName, std::string& associationPath, SensorManager* sensorManager,
446+ exec::async_scope& scoperef) :
447+ tid (tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
424448{
425449 if (!pdr)
426450 {
@@ -532,7 +556,7 @@ NumericSensor::NumericSensor(
532556 {
533557 try
534558 {
535- valueIntf = std::make_unique<ValueIntf >(bus, path.c_str ());
559+ valueIntf = std::make_unique<SensorValue >(bus, path.c_str (), * this );
536560 }
537561 catch (const sdbusplus::exception_t & e)
538562 {
@@ -698,7 +722,7 @@ void NumericSensor::updateReading(bool available, bool functional, double value)
698722 double curValue = 0 ;
699723 if (!useMetricInterface)
700724 {
701- curValue = valueIntf->value ();
725+ curValue = valueIntf->ValueIntf :: value ();
702726 }
703727 else
704728 {
0 commit comments