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,27 @@ namespace pldm
1516namespace platform_mc
1617{
1718
19+ double SensorValue::value () const
20+ {
21+ if (this ->nSensor .sensorManager && !nSensor.updateTime && nSensor.isReady && !nSensor.pollPending )
22+ {
23+ nSensor.pollPending = true ;
24+
25+ lg2::info (" Get reading for sensor Id: {ID}" , " ID" , nSensor.sensorId );
26+ nSensor.scope .spawn (
27+ [](SensorManager* manager, NumericSensor* sensor) -> exec::task<void > {
28+ auto sPtr = std::shared_ptr<NumericSensor>(sensor, [](auto ) {});
29+ co_await manager->getSensorReading (sPtr );
30+ sensor->pollPending = false ;
31+ co_return ;
32+ }(nSensor.sensorManager , const_cast <NumericSensor*>(&nSensor))
33+ );
34+ }
35+
36+ auto value = ValueIntf::value ();
37+ return value;
38+ }
39+
1840inline bool NumericSensor::createInventoryPath (
1941 const std::string& associationPath, const std::string& sensorName,
2042 const uint16_t entityType, const uint16_t entityInstanceNum,
@@ -163,7 +185,9 @@ void NumericSensor::setSensorUnit(uint8_t baseUnit)
163185NumericSensor::NumericSensor (
164186 const pldm_tid_t tid, const bool sensorDisabled,
165187 std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr, std::string& sensorName,
166- std::string& associationPath) : tid(tid), sensorName(sensorName)
188+ std::string& associationPath, SensorManager* sensorManager,
189+ exec::async_scope& scoperef) :
190+ tid (tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
167191{
168192 if (!pdr)
169193 {
@@ -289,7 +313,7 @@ NumericSensor::NumericSensor(
289313 {
290314 try
291315 {
292- valueIntf = std::make_unique<ValueIntf >(bus, path.c_str ());
316+ valueIntf = std::make_unique<SensorValue >(bus, path.c_str (), * this );
293317 }
294318 catch (const sdbusplus::exception_t & e)
295319 {
@@ -419,8 +443,9 @@ NumericSensor::NumericSensor(
419443NumericSensor::NumericSensor (
420444 const pldm_tid_t tid, const bool sensorDisabled,
421445 std::shared_ptr<pldm_compact_numeric_sensor_pdr> pdr,
422- std::string& sensorName, std::string& associationPath) :
423- tid (tid), sensorName(sensorName)
446+ std::string& sensorName, std::string& associationPath, SensorManager* sensorManager,
447+ exec::async_scope& scoperef) :
448+ tid (tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
424449{
425450 if (!pdr)
426451 {
@@ -532,7 +557,7 @@ NumericSensor::NumericSensor(
532557 {
533558 try
534559 {
535- valueIntf = std::make_unique<ValueIntf >(bus, path.c_str ());
560+ valueIntf = std::make_unique<SensorValue >(bus, path.c_str (), * this );
536561 }
537562 catch (const sdbusplus::exception_t & e)
538563 {
@@ -698,7 +723,7 @@ void NumericSensor::updateReading(bool available, bool functional, double value)
698723 double curValue = 0 ;
699724 if (!useMetricInterface)
700725 {
701- curValue = valueIntf->value ();
726+ curValue = valueIntf->ValueIntf :: value ();
702727 }
703728 else
704729 {
0 commit comments