blob: f22f40377828ed08c7f42c63e8a5667c692375a0 [file] [log] [blame]
Patrick Venture3a5071a2018-09-12 13:27:42 -07001#include "sensordatahandler.hpp"
2
3#include "sensorhandler.hpp"
Patrick Venture3a5071a2018-09-12 13:27:42 -07004
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -05005#include <bitset>
Vernon Mauerybdda8002019-02-26 10:18:51 -08006#include <filesystem>
Vernon Mauery33250242019-03-12 16:49:26 -07007#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07008#include <ipmid/utils.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -07009#include <optional>
William A. Kennington III4c008022018-10-12 17:18:14 -070010#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070011#include <xyz/openbmc_project/Common/error.hpp>
12
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050013namespace ipmi
14{
15namespace sensor
16{
17
18using namespace phosphor::logging;
19using InternalFailure =
20 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
21
22static constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
23static constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
24static constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
25
26/** @brief get the D-Bus service and service path
27 * @param[in] bus - The Dbus bus object
28 * @param[in] interface - interface to the service
29 * @param[in] path - interested path in the list of objects
30 * @return pair of service path and service
31 */
32ServicePath getServiceAndPath(sdbusplus::bus::bus& bus,
33 const std::string& interface,
34 const std::string& path)
35{
36 auto depth = 0;
Patrick Venture0b02be92018-08-31 11:55:55 -070037 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
38 MAPPER_INTERFACE, "GetSubTree");
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050039 mapperCall.append("/");
40 mapperCall.append(depth);
41 mapperCall.append(std::vector<Interface>({interface}));
42
43 auto mapperResponseMsg = bus.call(mapperCall);
44 if (mapperResponseMsg.is_method_error())
45 {
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050046 log<level::ERR>("Mapper GetSubTree failed",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050047 entry("PATH=%s", path.c_str()),
48 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050049 elog<InternalFailure>();
50 }
51
52 MapperResponseType mapperResponse;
53 mapperResponseMsg.read(mapperResponse);
54 if (mapperResponse.empty())
55 {
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050056 log<level::ERR>("Invalid mapper response",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050057 entry("PATH=%s", path.c_str()),
58 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050059 elog<InternalFailure>();
60 }
61
62 if (path.empty())
63 {
Patrick Venture0b02be92018-08-31 11:55:55 -070064 // Get the first one if the path is not in list.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050065 return std::make_pair(mapperResponse.begin()->first,
66 mapperResponse.begin()->second.begin()->first);
67 }
68 const auto& iter = mapperResponse.find(path);
69 if (iter == mapperResponse.end())
70 {
Gunnar Millsc9fa69e2018-04-08 16:35:25 -050071 log<level::ERR>("Couldn't find D-Bus path",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050072 entry("PATH=%s", path.c_str()),
73 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050074 elog<InternalFailure>();
75 }
76 return std::make_pair(iter->first, iter->second.begin()->first);
77}
78
79AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData)
80{
81 Assertion assertionStates =
82 (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 |
83 cmdData.assertOffset0_7;
84 Deassertion deassertionStates =
85 (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 |
86 cmdData.deassertOffset0_7;
87 return std::make_pair(assertionStates, deassertionStates);
88}
89
90ipmi_ret_t updateToDbus(IpmiUpdateData& msg)
91{
92 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
93 try
94 {
95 auto serviceResponseMsg = bus.call(msg);
96 if (serviceResponseMsg.is_method_error())
97 {
98 log<level::ERR>("Error in D-Bus call");
99 return IPMI_CC_UNSPECIFIED_ERROR;
100 }
101 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500102 catch (const InternalFailure& e)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500103 {
104 commit<InternalFailure>();
105 return IPMI_CC_UNSPECIFIED_ERROR;
106 }
107 return IPMI_CC_OK;
108}
109
Tom Joseph816e92b2017-09-06 19:23:00 +0530110namespace get
111{
112
Tom Josephb0adbcd2018-01-24 11:51:29 +0530113SensorName nameParentLeaf(const Info& sensorInfo)
114{
115 const auto pos = sensorInfo.sensorPath.find_last_of('/');
116 const auto leaf = sensorInfo.sensorPath.substr(pos + 1);
117
118 const auto remaining = sensorInfo.sensorPath.substr(0, pos);
119
120 const auto parentPos = remaining.find_last_of('/');
121 auto parent = remaining.substr(parentPos + 1);
122
123 parent += "_" + leaf;
124 return parent;
125}
126
Tom Joseph816e92b2017-09-06 19:23:00 +0530127GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
128 const InstancePath& path,
129 const DbusInterface& interface)
130{
131 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700132 GetSensorResponse response{};
Tom Joseph816e92b2017-09-06 19:23:00 +0530133
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800134 enableScanning(&response);
135
Tom Joseph816e92b2017-09-06 19:23:00 +0530136 auto service = ipmi::getService(bus, interface, path);
137
138 const auto& interfaceList = sensorInfo.propertyInterfaces;
139
140 for (const auto& interface : interfaceList)
141 {
142 for (const auto& property : interface.second)
143 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700144 auto propValue = ipmi::getDbusProperty(
145 bus, service, path, interface.first, property.first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530146
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500147 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Joseph816e92b2017-09-06 19:23:00 +0530148 {
149 if (propValue == value.second.assert)
150 {
Sui Chen4cc42552019-09-11 10:28:35 -0700151 setOffset(value.first, &response);
Tom Joseph816e92b2017-09-06 19:23:00 +0530152 break;
153 }
Tom Joseph816e92b2017-09-06 19:23:00 +0530154 }
155 }
156 }
157
158 return response;
159}
160
Lei YUa8dc09b2021-10-13 18:06:46 +0800161GetSensorResponse mapDbusToEventdata2(const Info& sensorInfo)
Tom Josephe4014fc2017-09-06 23:57:36 +0530162{
163 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700164 GetSensorResponse response{};
Tom Josephe4014fc2017-09-06 23:57:36 +0530165
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800166 enableScanning(&response);
167
Patrick Venture0b02be92018-08-31 11:55:55 -0700168 auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
Tom Josephe4014fc2017-09-06 23:57:36 +0530169 sensorInfo.sensorPath);
170
171 const auto& interfaceList = sensorInfo.propertyInterfaces;
172
173 for (const auto& interface : interfaceList)
174 {
175 for (const auto& property : interface.second)
176 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700177 auto propValue =
178 ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath,
179 interface.first, property.first);
Tom Josephe4014fc2017-09-06 23:57:36 +0530180
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500181 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Josephe4014fc2017-09-06 23:57:36 +0530182 {
183 if (propValue == value.second.assert)
184 {
Sui Chen4cc42552019-09-11 10:28:35 -0700185 setReading(value.first, &response);
Tom Josephe4014fc2017-09-06 23:57:36 +0530186 break;
187 }
188 }
189 }
190 }
191
192 return response;
193}
Lei YUa8dc09b2021-10-13 18:06:46 +0800194
195#ifndef FEATURE_SENSORS_CACHE
196GetSensorResponse assertion(const Info& sensorInfo)
197{
198 return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
199 sensorInfo.sensorInterface);
200}
201
202GetSensorResponse eventdata2(const Info& sensorInfo)
203{
204 return mapDbusToEventdata2(sensorInfo);
205}
Lei YU8c2c0482021-09-16 17:28:28 +0800206#else
207std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800208 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800209{
Lei YUef960c02021-10-13 17:54:59 +0800210 // The assertion may contain multiple properties
211 // So we have to get the properties from DBus anyway
212 auto response = mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
213 sensorInfo.sensorInterface);
214
215 if (!sensorCacheMap[id].has_value())
216 {
217 sensorCacheMap[id] = SensorData{};
218 }
219 sensorCacheMap[id]->response = response;
220 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800221}
222
223std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800224 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800225{
Lei YUa8dc09b2021-10-13 18:06:46 +0800226 // The eventdata2 may contain multiple properties
227 // So we have to get the properties from DBus anyway
228 auto response = mapDbusToEventdata2(sensorInfo);
229
230 if (!sensorCacheMap[id].has_value())
231 {
232 sensorCacheMap[id] = SensorData{};
233 }
234 sensorCacheMap[id]->response = response;
235 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800236}
237
238#endif // FEATURE_SENSORS_CACHE
Tom Josephe4014fc2017-09-06 23:57:36 +0530239
Patrick Venture0b02be92018-08-31 11:55:55 -0700240} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530241
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500242namespace set
243{
244
245IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
246 const std::string& sensorPath,
247 const std::string& command,
248 const std::string& sensorInterface)
249{
250 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
251 using namespace std::string_literals;
252
Patrick Venture0b02be92018-08-31 11:55:55 -0700253 auto dbusService = getService(bus, sensorInterface, sensorPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500254
Patrick Venture0b02be92018-08-31 11:55:55 -0700255 return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(),
256 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500257}
258
Willy Tu11d68892022-01-20 10:37:34 -0800259ipmi_ret_t eventdata(const SetSensorReadingReq&, const Info& sensorInfo,
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500260 uint8_t data)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500261{
Patrick Venture0b02be92018-08-31 11:55:55 -0700262 auto msg =
263 makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath,
264 "Set", sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500265
266 const auto& interface = sensorInfo.propertyInterfaces.begin();
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500267 msg.append(interface->first);
268 for (const auto& property : interface->second)
269 {
270 msg.append(property.first);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500271 const auto& iter = std::get<OffsetValueMap>(property.second).find(data);
272 if (iter == std::get<OffsetValueMap>(property.second).end())
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500273 {
274 log<level::ERR>("Invalid event data");
275 return IPMI_CC_PARM_OUT_OF_RANGE;
276 }
277 msg.append(iter->second.assert);
278 }
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500279 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500280}
281
Patrick Venture0b02be92018-08-31 11:55:55 -0700282ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500283{
Brad Bishop06a0abf2018-02-26 20:46:00 -0500284 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
285 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
286 auto bothSet = assertionSet ^ deassertionSet;
287
288 const auto& interface = sensorInfo.propertyInterfaces.begin();
289
290 for (const auto& property : interface->second)
291 {
William A. Kennington III4c008022018-10-12 17:18:14 -0700292 std::optional<Value> tmp;
Brad Bishop06a0abf2018-02-26 20:46:00 -0500293 for (const auto& value : std::get<OffsetValueMap>(property.second))
294 {
295 if (bothSet.size() <= value.first || !bothSet.test(value.first))
296 {
297 // A BIOS shouldn't do this but ignore if they do.
298 continue;
299 }
300
301 if (assertionSet.test(value.first))
302 {
303 tmp = value.second.assert;
304 break;
305 }
306 if (deassertionSet.test(value.first))
307 {
308 tmp = value.second.deassert;
309 break;
310 }
311 }
312
William A. Kennington III4c008022018-10-12 17:18:14 -0700313 if (tmp)
Brad Bishop06a0abf2018-02-26 20:46:00 -0500314 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700315 auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
316 sensorInfo.sensorPath, "Set",
317 sensorInfo.sensorInterface);
Brad Bishop06a0abf2018-02-26 20:46:00 -0500318 msg.append(interface->first);
319 msg.append(property.first);
William A. Kennington III4c008022018-10-12 17:18:14 -0700320 msg.append(*tmp);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500321
Brad Bishop06a0abf2018-02-26 20:46:00 -0500322 auto rc = updateToDbus(msg);
323 if (rc)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500324 {
Brad Bishop06a0abf2018-02-26 20:46:00 -0500325 return rc;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500326 }
327 }
328 }
Brad Bishop06a0abf2018-02-26 20:46:00 -0500329
330 return IPMI_CC_OK;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500331}
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500332
Patrick Venture0b02be92018-08-31 11:55:55 -0700333} // namespace set
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500334
335namespace notify
336{
337
338IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
Willy Tu11d68892022-01-20 10:37:34 -0800339 const std::string&, const std::string& command,
340 const std::string&)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500341{
342 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
343 using namespace std::string_literals;
344
Dhruvaraj Subhashchandranf915f852017-09-14 07:01:48 -0500345 static const auto dbusPath = "/xyz/openbmc_project/inventory"s;
346 std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500347
Patrick Venture0b02be92018-08-31 11:55:55 -0700348 return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(),
349 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500350}
351
Patrick Venture0b02be92018-08-31 11:55:55 -0700352ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500353{
Patrick Venture0b02be92018-08-31 11:55:55 -0700354 auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath,
355 "Notify", sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500356
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500357 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
358 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
359 ipmi::sensor::ObjectMap objects;
360 ipmi::sensor::InterfaceMap interfaces;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500361 for (const auto& interface : sensorInfo.propertyInterfaces)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500362 {
Santosh Puranikbbf8bd62019-05-01 19:02:52 +0530363 // An interface with no properties - It is possible that the sensor
364 // object on DBUS implements a DBUS interface with no properties.
365 // Make sure we add the interface to the list if interfaces on the
366 // object with an empty property map.
367 if (interface.second.empty())
368 {
369 interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{});
370 continue;
371 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700372 // For a property like functional state the result will be
373 // calculated based on the true value of all conditions.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500374 for (const auto& property : interface.second)
375 {
376 ipmi::sensor::PropertyMap props;
377 bool valid = false;
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500378 auto result = true;
379 for (const auto& value : std::get<OffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500380 {
381 if (assertionSet.test(value.first))
382 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700383 // Skip update if skipOn is ASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500384 if (SkipAssertion::ASSERT == value.second.skip)
385 {
386 return IPMI_CC_OK;
387 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700388 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500389 valid = true;
390 }
391 else if (deassertionSet.test(value.first))
392 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700393 // Skip update if skipOn is DEASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500394 if (SkipAssertion::DEASSERT == value.second.skip)
395 {
396 return IPMI_CC_OK;
397 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700398 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500399 valid = true;
400 }
401 }
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500402 for (const auto& value :
Patrick Venture0b02be92018-08-31 11:55:55 -0700403 std::get<PreReqOffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500404 {
405 if (assertionSet.test(value.first))
406 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700407 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500408 }
409 else if (deassertionSet.test(value.first))
410 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700411 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500412 }
413 }
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500414 if (valid)
415 {
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500416 props.emplace(property.first, result);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500417 interfaces.emplace(interface.first, std::move(props));
418 }
419 }
420 }
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500421
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500422 objects.emplace(sensorInfo.sensorPath, std::move(interfaces));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500423 msg.append(std::move(objects));
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500424 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500425}
Tom Joseph816e92b2017-09-06 19:23:00 +0530426
Patrick Venture0b02be92018-08-31 11:55:55 -0700427} // namespace notify
Tom Joseph816e92b2017-09-06 19:23:00 +0530428
429namespace inventory
430{
431
432namespace get
433{
434
Lei YUff8c9b42021-10-15 14:20:57 +0800435#ifndef FEATURE_SENSORS_CACHE
436
Tom Joseph816e92b2017-09-06 19:23:00 +0530437GetSensorResponse assertion(const Info& sensorInfo)
438{
Vernon Mauery185b9f82018-07-20 10:52:36 -0700439 namespace fs = std::filesystem;
Tom Joseph816e92b2017-09-06 19:23:00 +0530440
441 fs::path path{ipmi::sensor::inventoryRoot};
442 path += sensorInfo.sensorPath;
443
444 return ipmi::sensor::get::mapDbusToAssertion(
Patrick Venture0b02be92018-08-31 11:55:55 -0700445 sensorInfo, path.string(),
446 sensorInfo.propertyInterfaces.begin()->first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530447}
448
Lei YUff8c9b42021-10-15 14:20:57 +0800449#else
450
451std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800452 const PropertyMap& /*properties*/)
Lei YUff8c9b42021-10-15 14:20:57 +0800453{
Lei YUff8c9b42021-10-15 14:20:57 +0800454 // The assertion may contain multiple properties
455 // So we have to get the properties from DBus anyway
456 namespace fs = std::filesystem;
457
458 fs::path path{ipmi::sensor::inventoryRoot};
459 path += sensorInfo.sensorPath;
460
461 auto response = ipmi::sensor::get::mapDbusToAssertion(
462 sensorInfo, path.string(),
463 sensorInfo.propertyInterfaces.begin()->first);
464
465 if (!sensorCacheMap[id].has_value())
466 {
467 sensorCacheMap[id] = SensorData{};
468 }
469 sensorCacheMap[id]->response = response;
470 return response;
471}
472
473#endif
474
Patrick Venture0b02be92018-08-31 11:55:55 -0700475} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530476
477} // namespace inventory
Patrick Venture0b02be92018-08-31 11:55:55 -0700478} // namespace sensor
479} // namespace ipmi