13a5071a9SPatrick Venture #include "sensordatahandler.hpp"
23a5071a9SPatrick Venture
33a5071a9SPatrick Venture #include "sensorhandler.hpp"
43a5071a9SPatrick Venture
533250240SVernon Mauery #include <ipmid/types.hpp>
66a98fe7fSVernon Mauery #include <ipmid/utils.hpp>
74c008028SWilliam A. Kennington III #include <sdbusplus/message/types.hpp>
83a5071a9SPatrick Venture #include <xyz/openbmc_project/Common/error.hpp>
93a5071a9SPatrick Venture
10fbc6c9d7SPatrick Williams #include <bitset>
11fbc6c9d7SPatrick Williams #include <filesystem>
12fbc6c9d7SPatrick Williams #include <optional>
13fbc6c9d7SPatrick Williams
14e0af7209SDhruvaraj Subhashchandran namespace ipmi
15e0af7209SDhruvaraj Subhashchandran {
16e0af7209SDhruvaraj Subhashchandran namespace sensor
17e0af7209SDhruvaraj Subhashchandran {
18e0af7209SDhruvaraj Subhashchandran
19e0af7209SDhruvaraj Subhashchandran using namespace phosphor::logging;
20e0af7209SDhruvaraj Subhashchandran using InternalFailure =
21523e2d1bSWilly Tu sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
22e0af7209SDhruvaraj Subhashchandran
getAssertionSet(const SetSensorReadingReq & cmdData)23e0af7209SDhruvaraj Subhashchandran AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData)
24e0af7209SDhruvaraj Subhashchandran {
25e0af7209SDhruvaraj Subhashchandran Assertion assertionStates =
26e0af7209SDhruvaraj Subhashchandran (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 |
27e0af7209SDhruvaraj Subhashchandran cmdData.assertOffset0_7;
28e0af7209SDhruvaraj Subhashchandran Deassertion deassertionStates =
29e0af7209SDhruvaraj Subhashchandran (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 |
30e0af7209SDhruvaraj Subhashchandran cmdData.deassertOffset0_7;
31e0af7209SDhruvaraj Subhashchandran return std::make_pair(assertionStates, deassertionStates);
32e0af7209SDhruvaraj Subhashchandran }
33e0af7209SDhruvaraj Subhashchandran
updateToDbus(IpmiUpdateData & msg)34e0af7209SDhruvaraj Subhashchandran ipmi_ret_t updateToDbus(IpmiUpdateData& msg)
35e0af7209SDhruvaraj Subhashchandran {
365d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
37e0af7209SDhruvaraj Subhashchandran try
38e0af7209SDhruvaraj Subhashchandran {
39e0af7209SDhruvaraj Subhashchandran auto serviceResponseMsg = bus.call(msg);
40e0af7209SDhruvaraj Subhashchandran }
41a2ad2da8SPatrick Williams catch (const InternalFailure& e)
42e0af7209SDhruvaraj Subhashchandran {
439b745a81SGeorge Liu lg2::error("Error in D-Bus call: {ERROR}", "ERROR", e);
44e0af7209SDhruvaraj Subhashchandran commit<InternalFailure>();
45e0af7209SDhruvaraj Subhashchandran return IPMI_CC_UNSPECIFIED_ERROR;
46e0af7209SDhruvaraj Subhashchandran }
47e0af7209SDhruvaraj Subhashchandran return IPMI_CC_OK;
48e0af7209SDhruvaraj Subhashchandran }
49e0af7209SDhruvaraj Subhashchandran
50816e92b5STom Joseph namespace get
51816e92b5STom Joseph {
52816e92b5STom Joseph
nameParentLeaf(const Info & sensorInfo)53b0adbcddSTom Joseph SensorName nameParentLeaf(const Info& sensorInfo)
54b0adbcddSTom Joseph {
55b0adbcddSTom Joseph const auto pos = sensorInfo.sensorPath.find_last_of('/');
56b0adbcddSTom Joseph const auto leaf = sensorInfo.sensorPath.substr(pos + 1);
57b0adbcddSTom Joseph
58b0adbcddSTom Joseph const auto remaining = sensorInfo.sensorPath.substr(0, pos);
59b0adbcddSTom Joseph
60b0adbcddSTom Joseph const auto parentPos = remaining.find_last_of('/');
61b0adbcddSTom Joseph auto parent = remaining.substr(parentPos + 1);
62b0adbcddSTom Joseph
63b0adbcddSTom Joseph parent += "_" + leaf;
64b0adbcddSTom Joseph return parent;
65b0adbcddSTom Joseph }
66b0adbcddSTom Joseph
mapDbusToAssertion(const Info & sensorInfo,const InstancePath & path,const DbusInterface & interface)67816e92b5STom Joseph GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
68816e92b5STom Joseph const InstancePath& path,
69816e92b5STom Joseph const DbusInterface& interface)
70816e92b5STom Joseph {
715d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
72816e92b5STom Joseph GetSensorResponse response{};
73816e92b5STom Joseph
743dc35589SJeremy Kerr enableScanning(&response);
753dc35589SJeremy Kerr
76816e92b5STom Joseph auto service = ipmi::getService(bus, interface, path);
77816e92b5STom Joseph
78816e92b5STom Joseph const auto& interfaceList = sensorInfo.propertyInterfaces;
79816e92b5STom Joseph
80816e92b5STom Joseph for (const auto& interface : interfaceList)
81816e92b5STom Joseph {
82816e92b5STom Joseph for (const auto& property : interface.second)
83816e92b5STom Joseph {
840b02be92SPatrick Venture auto propValue = ipmi::getDbusProperty(
850b02be92SPatrick Venture bus, service, path, interface.first, property.first);
86816e92b5STom Joseph
87e245e4e9SDhruvaraj Subhashchandran for (const auto& value : std::get<OffsetValueMap>(property.second))
88816e92b5STom Joseph {
89816e92b5STom Joseph if (propValue == value.second.assert)
90816e92b5STom Joseph {
914cc42556SSui Chen setOffset(value.first, &response);
92816e92b5STom Joseph break;
93816e92b5STom Joseph }
94816e92b5STom Joseph }
95816e92b5STom Joseph }
96816e92b5STom Joseph }
97816e92b5STom Joseph
98816e92b5STom Joseph return response;
99816e92b5STom Joseph }
100816e92b5STom Joseph
mapDbusToEventdata2(const Info & sensorInfo)101a8dc09b2SLei YU GetSensorResponse mapDbusToEventdata2(const Info& sensorInfo)
102e4014fcaSTom Joseph {
1035d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
104e4014fcaSTom Joseph GetSensorResponse response{};
105e4014fcaSTom Joseph
1063dc35589SJeremy Kerr enableScanning(&response);
1073dc35589SJeremy Kerr
1080b02be92SPatrick Venture auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
109e4014fcaSTom Joseph sensorInfo.sensorPath);
110e4014fcaSTom Joseph
111e4014fcaSTom Joseph const auto& interfaceList = sensorInfo.propertyInterfaces;
112e4014fcaSTom Joseph
113e4014fcaSTom Joseph for (const auto& interface : interfaceList)
114e4014fcaSTom Joseph {
115e4014fcaSTom Joseph for (const auto& property : interface.second)
116e4014fcaSTom Joseph {
1170b02be92SPatrick Venture auto propValue =
1180b02be92SPatrick Venture ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath,
1190b02be92SPatrick Venture interface.first, property.first);
120e4014fcaSTom Joseph
121e245e4e9SDhruvaraj Subhashchandran for (const auto& value : std::get<OffsetValueMap>(property.second))
122e4014fcaSTom Joseph {
123e4014fcaSTom Joseph if (propValue == value.second.assert)
124e4014fcaSTom Joseph {
1254cc42556SSui Chen setReading(value.first, &response);
126e4014fcaSTom Joseph break;
127e4014fcaSTom Joseph }
128e4014fcaSTom Joseph }
129e4014fcaSTom Joseph }
130e4014fcaSTom Joseph }
131e4014fcaSTom Joseph
132e4014fcaSTom Joseph return response;
133e4014fcaSTom Joseph }
134a8dc09b2SLei YU
135a8dc09b2SLei YU #ifndef FEATURE_SENSORS_CACHE
assertion(const Info & sensorInfo)136a8dc09b2SLei YU GetSensorResponse assertion(const Info& sensorInfo)
137a8dc09b2SLei YU {
138a8dc09b2SLei YU return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
139a8dc09b2SLei YU sensorInfo.sensorInterface);
140a8dc09b2SLei YU }
141a8dc09b2SLei YU
eventdata2(const Info & sensorInfo)142a8dc09b2SLei YU GetSensorResponse eventdata2(const Info& sensorInfo)
143a8dc09b2SLei YU {
144a8dc09b2SLei YU return mapDbusToEventdata2(sensorInfo);
145a8dc09b2SLei YU }
1468c2c048eSLei YU #else
assertion(uint8_t id,const Info & sensorInfo,const PropertyMap &)1478c2c048eSLei YU std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
1488e8152c5SLei YU const PropertyMap& /*properties*/)
1498c2c048eSLei YU {
150ef960c03SLei YU // The assertion may contain multiple properties
151ef960c03SLei YU // So we have to get the properties from DBus anyway
152ef960c03SLei YU auto response = mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
153ef960c03SLei YU sensorInfo.sensorInterface);
154ef960c03SLei YU
155ef960c03SLei YU if (!sensorCacheMap[id].has_value())
156ef960c03SLei YU {
157ef960c03SLei YU sensorCacheMap[id] = SensorData{};
158ef960c03SLei YU }
159ef960c03SLei YU sensorCacheMap[id]->response = response;
160ef960c03SLei YU return response;
161ef960c03SLei YU }
1628c2c048eSLei YU
eventdata2(uint8_t id,const Info & sensorInfo,const PropertyMap &)1638c2c048eSLei YU std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo,
1648e8152c5SLei YU const PropertyMap& /*properties*/)
1658c2c048eSLei YU {
166a8dc09b2SLei YU // The eventdata2 may contain multiple properties
167a8dc09b2SLei YU // So we have to get the properties from DBus anyway
168a8dc09b2SLei YU auto response = mapDbusToEventdata2(sensorInfo);
169a8dc09b2SLei YU
170a8dc09b2SLei YU if (!sensorCacheMap[id].has_value())
171a8dc09b2SLei YU {
172a8dc09b2SLei YU sensorCacheMap[id] = SensorData{};
173a8dc09b2SLei YU }
174a8dc09b2SLei YU sensorCacheMap[id]->response = response;
175a8dc09b2SLei YU return response;
176a8dc09b2SLei YU }
1778c2c048eSLei YU
1788c2c048eSLei YU #endif // FEATURE_SENSORS_CACHE
179e4014fcaSTom Joseph
180816e92b5STom Joseph } // namespace get
181816e92b5STom Joseph
182e0af7209SDhruvaraj Subhashchandran namespace set
183e0af7209SDhruvaraj Subhashchandran {
184e0af7209SDhruvaraj Subhashchandran
makeDbusMsg(const std::string & updateInterface,const std::string & sensorPath,const std::string & command,const std::string & sensorInterface)185e0af7209SDhruvaraj Subhashchandran IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
186e0af7209SDhruvaraj Subhashchandran const std::string& sensorPath,
187e0af7209SDhruvaraj Subhashchandran const std::string& command,
188e0af7209SDhruvaraj Subhashchandran const std::string& sensorInterface)
189e0af7209SDhruvaraj Subhashchandran {
1905d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
191e0af7209SDhruvaraj Subhashchandran using namespace std::string_literals;
192e0af7209SDhruvaraj Subhashchandran
1930b02be92SPatrick Venture auto dbusService = getService(bus, sensorInterface, sensorPath);
194c6a571a4STom Joseph
1950b02be92SPatrick Venture return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(),
1960b02be92SPatrick Venture updateInterface.c_str(), command.c_str());
197e0af7209SDhruvaraj Subhashchandran }
198e0af7209SDhruvaraj Subhashchandran
eventdata(const SetSensorReadingReq &,const Info & sensorInfo,uint8_t data)19911d68897SWilly Tu ipmi_ret_t eventdata(const SetSensorReadingReq&, const Info& sensorInfo,
200e0af7209SDhruvaraj Subhashchandran uint8_t data)
201e0af7209SDhruvaraj Subhashchandran {
202*1318a5edSPatrick Williams auto msg =
203*1318a5edSPatrick Williams makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath,
204*1318a5edSPatrick Williams "Set", sensorInfo.sensorInterface);
2051bb0d387SDeepak Kodihalli
2061bb0d387SDeepak Kodihalli const auto& interface = sensorInfo.propertyInterfaces.begin();
207e0af7209SDhruvaraj Subhashchandran msg.append(interface->first);
208e0af7209SDhruvaraj Subhashchandran for (const auto& property : interface->second)
209e0af7209SDhruvaraj Subhashchandran {
210e0af7209SDhruvaraj Subhashchandran msg.append(property.first);
211e245e4e9SDhruvaraj Subhashchandran const auto& iter = std::get<OffsetValueMap>(property.second).find(data);
212e245e4e9SDhruvaraj Subhashchandran if (iter == std::get<OffsetValueMap>(property.second).end())
213e0af7209SDhruvaraj Subhashchandran {
2149b745a81SGeorge Liu lg2::error("Invalid event data");
215e0af7209SDhruvaraj Subhashchandran return IPMI_CC_PARM_OUT_OF_RANGE;
216e0af7209SDhruvaraj Subhashchandran }
217e0af7209SDhruvaraj Subhashchandran msg.append(iter->second.assert);
218e0af7209SDhruvaraj Subhashchandran }
2191bb0d387SDeepak Kodihalli return updateToDbus(msg);
220e0af7209SDhruvaraj Subhashchandran }
221e0af7209SDhruvaraj Subhashchandran
assertion(const SetSensorReadingReq & cmdData,const Info & sensorInfo)2220b02be92SPatrick Venture ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
223e0af7209SDhruvaraj Subhashchandran {
22406a0abffSBrad Bishop std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
22506a0abffSBrad Bishop std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
22606a0abffSBrad Bishop auto bothSet = assertionSet ^ deassertionSet;
22706a0abffSBrad Bishop
22806a0abffSBrad Bishop const auto& interface = sensorInfo.propertyInterfaces.begin();
22906a0abffSBrad Bishop
23006a0abffSBrad Bishop for (const auto& property : interface->second)
23106a0abffSBrad Bishop {
2324c008028SWilliam A. Kennington III std::optional<Value> tmp;
23306a0abffSBrad Bishop for (const auto& value : std::get<OffsetValueMap>(property.second))
23406a0abffSBrad Bishop {
23506a0abffSBrad Bishop if (bothSet.size() <= value.first || !bothSet.test(value.first))
23606a0abffSBrad Bishop {
23706a0abffSBrad Bishop // A BIOS shouldn't do this but ignore if they do.
23806a0abffSBrad Bishop continue;
23906a0abffSBrad Bishop }
24006a0abffSBrad Bishop
24106a0abffSBrad Bishop if (assertionSet.test(value.first))
24206a0abffSBrad Bishop {
24306a0abffSBrad Bishop tmp = value.second.assert;
24406a0abffSBrad Bishop break;
24506a0abffSBrad Bishop }
24606a0abffSBrad Bishop if (deassertionSet.test(value.first))
24706a0abffSBrad Bishop {
24806a0abffSBrad Bishop tmp = value.second.deassert;
24906a0abffSBrad Bishop break;
25006a0abffSBrad Bishop }
25106a0abffSBrad Bishop }
25206a0abffSBrad Bishop
2534c008028SWilliam A. Kennington III if (tmp)
25406a0abffSBrad Bishop {
2550b02be92SPatrick Venture auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
2560b02be92SPatrick Venture sensorInfo.sensorPath, "Set",
2571bb0d387SDeepak Kodihalli sensorInfo.sensorInterface);
258e0af7209SDhruvaraj Subhashchandran msg.append(interface->first);
259e0af7209SDhruvaraj Subhashchandran msg.append(property.first);
2604c008028SWilliam A. Kennington III msg.append(*tmp);
26106a0abffSBrad Bishop
26206a0abffSBrad Bishop auto rc = updateToDbus(msg);
26306a0abffSBrad Bishop if (rc)
264e0af7209SDhruvaraj Subhashchandran {
26506a0abffSBrad Bishop return rc;
266e0af7209SDhruvaraj Subhashchandran }
267e0af7209SDhruvaraj Subhashchandran }
268e0af7209SDhruvaraj Subhashchandran }
26906a0abffSBrad Bishop
27006a0abffSBrad Bishop return IPMI_CC_OK;
271e0af7209SDhruvaraj Subhashchandran }
2721bb0d387SDeepak Kodihalli
273e0af7209SDhruvaraj Subhashchandran } // namespace set
274e0af7209SDhruvaraj Subhashchandran
275e0af7209SDhruvaraj Subhashchandran namespace notify
276e0af7209SDhruvaraj Subhashchandran {
277e0af7209SDhruvaraj Subhashchandran
makeDbusMsg(const std::string & updateInterface,const std::string &,const std::string & command,const std::string &)278e0af7209SDhruvaraj Subhashchandran IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
27911d68897SWilly Tu const std::string&, const std::string& command,
28011d68897SWilly Tu const std::string&)
281e0af7209SDhruvaraj Subhashchandran {
2825d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
283e0af7209SDhruvaraj Subhashchandran using namespace std::string_literals;
284e0af7209SDhruvaraj Subhashchandran
285f915f850SDhruvaraj Subhashchandran static const auto dbusPath = "/xyz/openbmc_project/inventory"s;
286f915f850SDhruvaraj Subhashchandran std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath);
287e0af7209SDhruvaraj Subhashchandran
2880b02be92SPatrick Venture return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(),
2890b02be92SPatrick Venture updateInterface.c_str(), command.c_str());
290e0af7209SDhruvaraj Subhashchandran }
291e0af7209SDhruvaraj Subhashchandran
assertion(const SetSensorReadingReq & cmdData,const Info & sensorInfo)2920b02be92SPatrick Venture ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
293e0af7209SDhruvaraj Subhashchandran {
2940b02be92SPatrick Venture auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath,
2950b02be92SPatrick Venture "Notify", sensorInfo.sensorInterface);
2961bb0d387SDeepak Kodihalli
297e0af7209SDhruvaraj Subhashchandran std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
298e0af7209SDhruvaraj Subhashchandran std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
299e0af7209SDhruvaraj Subhashchandran ipmi::sensor::ObjectMap objects;
300e0af7209SDhruvaraj Subhashchandran ipmi::sensor::InterfaceMap interfaces;
3011bb0d387SDeepak Kodihalli for (const auto& interface : sensorInfo.propertyInterfaces)
302e0af7209SDhruvaraj Subhashchandran {
303bbf8bd6cSSantosh Puranik // An interface with no properties - It is possible that the sensor
304bbf8bd6cSSantosh Puranik // object on DBUS implements a DBUS interface with no properties.
305bbf8bd6cSSantosh Puranik // Make sure we add the interface to the list if interfaces on the
306bbf8bd6cSSantosh Puranik // object with an empty property map.
307bbf8bd6cSSantosh Puranik if (interface.second.empty())
308bbf8bd6cSSantosh Puranik {
309bbf8bd6cSSantosh Puranik interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{});
310bbf8bd6cSSantosh Puranik continue;
311bbf8bd6cSSantosh Puranik }
312e245e4e9SDhruvaraj Subhashchandran // For a property like functional state the result will be
313e245e4e9SDhruvaraj Subhashchandran // calculated based on the true value of all conditions.
314e0af7209SDhruvaraj Subhashchandran for (const auto& property : interface.second)
315e0af7209SDhruvaraj Subhashchandran {
316e0af7209SDhruvaraj Subhashchandran ipmi::sensor::PropertyMap props;
317e0af7209SDhruvaraj Subhashchandran bool valid = false;
318e245e4e9SDhruvaraj Subhashchandran auto result = true;
319e245e4e9SDhruvaraj Subhashchandran for (const auto& value : std::get<OffsetValueMap>(property.second))
320e0af7209SDhruvaraj Subhashchandran {
321e0af7209SDhruvaraj Subhashchandran if (assertionSet.test(value.first))
322e0af7209SDhruvaraj Subhashchandran {
323e84841ceSDhruvaraj Subhashchandran // Skip update if skipOn is ASSERT
324e84841ceSDhruvaraj Subhashchandran if (SkipAssertion::ASSERT == value.second.skip)
325e84841ceSDhruvaraj Subhashchandran {
326e84841ceSDhruvaraj Subhashchandran return IPMI_CC_OK;
327e84841ceSDhruvaraj Subhashchandran }
328f442e119SVernon Mauery result = result && std::get<bool>(value.second.assert);
329e0af7209SDhruvaraj Subhashchandran valid = true;
330e0af7209SDhruvaraj Subhashchandran }
331e0af7209SDhruvaraj Subhashchandran else if (deassertionSet.test(value.first))
332e0af7209SDhruvaraj Subhashchandran {
333e84841ceSDhruvaraj Subhashchandran // Skip update if skipOn is DEASSERT
334e84841ceSDhruvaraj Subhashchandran if (SkipAssertion::DEASSERT == value.second.skip)
335e84841ceSDhruvaraj Subhashchandran {
336e84841ceSDhruvaraj Subhashchandran return IPMI_CC_OK;
337e84841ceSDhruvaraj Subhashchandran }
338f442e119SVernon Mauery result = result && std::get<bool>(value.second.deassert);
339e0af7209SDhruvaraj Subhashchandran valid = true;
340e0af7209SDhruvaraj Subhashchandran }
341e0af7209SDhruvaraj Subhashchandran }
342e245e4e9SDhruvaraj Subhashchandran for (const auto& value :
343e245e4e9SDhruvaraj Subhashchandran std::get<PreReqOffsetValueMap>(property.second))
344e245e4e9SDhruvaraj Subhashchandran {
345e245e4e9SDhruvaraj Subhashchandran if (assertionSet.test(value.first))
346e245e4e9SDhruvaraj Subhashchandran {
347f442e119SVernon Mauery result = result && std::get<bool>(value.second.assert);
348e245e4e9SDhruvaraj Subhashchandran }
349e245e4e9SDhruvaraj Subhashchandran else if (deassertionSet.test(value.first))
350e245e4e9SDhruvaraj Subhashchandran {
351f442e119SVernon Mauery result = result && std::get<bool>(value.second.deassert);
352e245e4e9SDhruvaraj Subhashchandran }
353e245e4e9SDhruvaraj Subhashchandran }
354e0af7209SDhruvaraj Subhashchandran if (valid)
355e0af7209SDhruvaraj Subhashchandran {
356e245e4e9SDhruvaraj Subhashchandran props.emplace(property.first, result);
357e0af7209SDhruvaraj Subhashchandran interfaces.emplace(interface.first, std::move(props));
358e0af7209SDhruvaraj Subhashchandran }
359e0af7209SDhruvaraj Subhashchandran }
360e0af7209SDhruvaraj Subhashchandran }
361e84841ceSDhruvaraj Subhashchandran
3621bb0d387SDeepak Kodihalli objects.emplace(sensorInfo.sensorPath, std::move(interfaces));
363e0af7209SDhruvaraj Subhashchandran msg.append(std::move(objects));
3641bb0d387SDeepak Kodihalli return updateToDbus(msg);
365e0af7209SDhruvaraj Subhashchandran }
366816e92b5STom Joseph
367e0af7209SDhruvaraj Subhashchandran } // namespace notify
368816e92b5STom Joseph
369816e92b5STom Joseph namespace inventory
370816e92b5STom Joseph {
371816e92b5STom Joseph
372816e92b5STom Joseph namespace get
373816e92b5STom Joseph {
374816e92b5STom Joseph
375ff8c9b49SLei YU #ifndef FEATURE_SENSORS_CACHE
376ff8c9b49SLei YU
assertion(const Info & sensorInfo)377816e92b5STom Joseph GetSensorResponse assertion(const Info& sensorInfo)
378816e92b5STom Joseph {
379185b9f8bSVernon Mauery namespace fs = std::filesystem;
380816e92b5STom Joseph
381816e92b5STom Joseph fs::path path{ipmi::sensor::inventoryRoot};
382816e92b5STom Joseph path += sensorInfo.sensorPath;
383816e92b5STom Joseph
384816e92b5STom Joseph return ipmi::sensor::get::mapDbusToAssertion(
3850b02be92SPatrick Venture sensorInfo, path.string(),
386816e92b5STom Joseph sensorInfo.propertyInterfaces.begin()->first);
387816e92b5STom Joseph }
388816e92b5STom Joseph
389ff8c9b49SLei YU #else
390ff8c9b49SLei YU
391ff8c9b49SLei YU std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
3928e8152c5SLei YU const PropertyMap& /*properties*/)
393ff8c9b49SLei YU {
394ff8c9b49SLei YU // The assertion may contain multiple properties
395ff8c9b49SLei YU // So we have to get the properties from DBus anyway
396ff8c9b49SLei YU namespace fs = std::filesystem;
397ff8c9b49SLei YU
398ff8c9b49SLei YU fs::path path{ipmi::sensor::inventoryRoot};
399ff8c9b49SLei YU path += sensorInfo.sensorPath;
400ff8c9b49SLei YU
401ff8c9b49SLei YU auto response = ipmi::sensor::get::mapDbusToAssertion(
402ff8c9b49SLei YU sensorInfo, path.string(),
403ff8c9b49SLei YU sensorInfo.propertyInterfaces.begin()->first);
404ff8c9b49SLei YU
405ff8c9b49SLei YU if (!sensorCacheMap[id].has_value())
406ff8c9b49SLei YU {
407ff8c9b49SLei YU sensorCacheMap[id] = SensorData{};
408ff8c9b49SLei YU }
409ff8c9b49SLei YU sensorCacheMap[id]->response = response;
410ff8c9b49SLei YU return response;
411ff8c9b49SLei YU }
412ff8c9b49SLei YU
413ff8c9b49SLei YU #endif
414ff8c9b49SLei YU
415816e92b5STom Joseph } // namespace get
416816e92b5STom Joseph
417816e92b5STom Joseph } // namespace inventory
418e0af7209SDhruvaraj Subhashchandran } // namespace sensor
419e0af7209SDhruvaraj Subhashchandran } // namespace ipmi
420