blob: e29cfac008f9bea981d0e96a4563bce4f6b99dbd [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
Vernon Mauery33250242019-03-12 16:49:26 -07005#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07006#include <ipmid/utils.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -07007#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -07008#include <xyz/openbmc_project/Common/error.hpp>
9
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050010#include <bitset>
11#include <filesystem>
12#include <optional>
13
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050014namespace ipmi
15{
16namespace sensor
17{
18
19using namespace phosphor::logging;
20using InternalFailure =
21 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
22
23static constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
24static constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
25static constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
26
27/** @brief get the D-Bus service and service path
28 * @param[in] bus - The Dbus bus object
29 * @param[in] interface - interface to the service
30 * @param[in] path - interested path in the list of objects
31 * @return pair of service path and service
32 */
Patrick Williams5d82f472022-07-22 19:26:53 -050033ServicePath getServiceAndPath(sdbusplus::bus_t& bus,
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050034 const std::string& interface,
35 const std::string& path)
36{
37 auto depth = 0;
Patrick Venture0b02be92018-08-31 11:55:55 -070038 auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
39 MAPPER_INTERFACE, "GetSubTree");
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050040 mapperCall.append("/");
41 mapperCall.append(depth);
42 mapperCall.append(std::vector<Interface>({interface}));
43
44 auto mapperResponseMsg = bus.call(mapperCall);
45 if (mapperResponseMsg.is_method_error())
46 {
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050047 log<level::ERR>("Mapper GetSubTree failed",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050048 entry("PATH=%s", path.c_str()),
49 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050050 elog<InternalFailure>();
51 }
52
53 MapperResponseType mapperResponse;
54 mapperResponseMsg.read(mapperResponse);
55 if (mapperResponse.empty())
56 {
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050057 log<level::ERR>("Invalid mapper response",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050058 entry("PATH=%s", path.c_str()),
59 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050060 elog<InternalFailure>();
61 }
62
63 if (path.empty())
64 {
Patrick Venture0b02be92018-08-31 11:55:55 -070065 // Get the first one if the path is not in list.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050066 return std::make_pair(mapperResponse.begin()->first,
67 mapperResponse.begin()->second.begin()->first);
68 }
69 const auto& iter = mapperResponse.find(path);
70 if (iter == mapperResponse.end())
71 {
Gunnar Millsc9fa69e2018-04-08 16:35:25 -050072 log<level::ERR>("Couldn't find D-Bus path",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050073 entry("PATH=%s", path.c_str()),
74 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050075 elog<InternalFailure>();
76 }
77 return std::make_pair(iter->first, iter->second.begin()->first);
78}
79
80AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData)
81{
82 Assertion assertionStates =
83 (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 |
84 cmdData.assertOffset0_7;
85 Deassertion deassertionStates =
86 (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 |
87 cmdData.deassertOffset0_7;
88 return std::make_pair(assertionStates, deassertionStates);
89}
90
91ipmi_ret_t updateToDbus(IpmiUpdateData& msg)
92{
Patrick Williams5d82f472022-07-22 19:26:53 -050093 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050094 try
95 {
96 auto serviceResponseMsg = bus.call(msg);
97 if (serviceResponseMsg.is_method_error())
98 {
99 log<level::ERR>("Error in D-Bus call");
100 return IPMI_CC_UNSPECIFIED_ERROR;
101 }
102 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500103 catch (const InternalFailure& e)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500104 {
105 commit<InternalFailure>();
106 return IPMI_CC_UNSPECIFIED_ERROR;
107 }
108 return IPMI_CC_OK;
109}
110
Tom Joseph816e92b2017-09-06 19:23:00 +0530111namespace get
112{
113
Tom Josephb0adbcd2018-01-24 11:51:29 +0530114SensorName nameParentLeaf(const Info& sensorInfo)
115{
116 const auto pos = sensorInfo.sensorPath.find_last_of('/');
117 const auto leaf = sensorInfo.sensorPath.substr(pos + 1);
118
119 const auto remaining = sensorInfo.sensorPath.substr(0, pos);
120
121 const auto parentPos = remaining.find_last_of('/');
122 auto parent = remaining.substr(parentPos + 1);
123
124 parent += "_" + leaf;
125 return parent;
126}
127
Tom Joseph816e92b2017-09-06 19:23:00 +0530128GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
129 const InstancePath& path,
130 const DbusInterface& interface)
131{
Patrick Williams5d82f472022-07-22 19:26:53 -0500132 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700133 GetSensorResponse response{};
Tom Joseph816e92b2017-09-06 19:23:00 +0530134
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800135 enableScanning(&response);
136
Tom Joseph816e92b2017-09-06 19:23:00 +0530137 auto service = ipmi::getService(bus, interface, path);
138
139 const auto& interfaceList = sensorInfo.propertyInterfaces;
140
141 for (const auto& interface : interfaceList)
142 {
143 for (const auto& property : interface.second)
144 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700145 auto propValue = ipmi::getDbusProperty(
146 bus, service, path, interface.first, property.first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530147
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500148 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Joseph816e92b2017-09-06 19:23:00 +0530149 {
150 if (propValue == value.second.assert)
151 {
Sui Chen4cc42552019-09-11 10:28:35 -0700152 setOffset(value.first, &response);
Tom Joseph816e92b2017-09-06 19:23:00 +0530153 break;
154 }
Tom Joseph816e92b2017-09-06 19:23:00 +0530155 }
156 }
157 }
158
159 return response;
160}
161
Lei YUa8dc09b2021-10-13 18:06:46 +0800162GetSensorResponse mapDbusToEventdata2(const Info& sensorInfo)
Tom Josephe4014fc2017-09-06 23:57:36 +0530163{
Patrick Williams5d82f472022-07-22 19:26:53 -0500164 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700165 GetSensorResponse response{};
Tom Josephe4014fc2017-09-06 23:57:36 +0530166
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800167 enableScanning(&response);
168
Patrick Venture0b02be92018-08-31 11:55:55 -0700169 auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
Tom Josephe4014fc2017-09-06 23:57:36 +0530170 sensorInfo.sensorPath);
171
172 const auto& interfaceList = sensorInfo.propertyInterfaces;
173
174 for (const auto& interface : interfaceList)
175 {
176 for (const auto& property : interface.second)
177 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700178 auto propValue =
179 ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath,
180 interface.first, property.first);
Tom Josephe4014fc2017-09-06 23:57:36 +0530181
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500182 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Josephe4014fc2017-09-06 23:57:36 +0530183 {
184 if (propValue == value.second.assert)
185 {
Sui Chen4cc42552019-09-11 10:28:35 -0700186 setReading(value.first, &response);
Tom Josephe4014fc2017-09-06 23:57:36 +0530187 break;
188 }
189 }
190 }
191 }
192
193 return response;
194}
Lei YUa8dc09b2021-10-13 18:06:46 +0800195
196#ifndef FEATURE_SENSORS_CACHE
197GetSensorResponse assertion(const Info& sensorInfo)
198{
199 return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
200 sensorInfo.sensorInterface);
201}
202
203GetSensorResponse eventdata2(const Info& sensorInfo)
204{
205 return mapDbusToEventdata2(sensorInfo);
206}
Lei YU8c2c0482021-09-16 17:28:28 +0800207#else
208std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800209 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800210{
Lei YUef960c02021-10-13 17:54:59 +0800211 // The assertion may contain multiple properties
212 // So we have to get the properties from DBus anyway
213 auto response = mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
214 sensorInfo.sensorInterface);
215
216 if (!sensorCacheMap[id].has_value())
217 {
218 sensorCacheMap[id] = SensorData{};
219 }
220 sensorCacheMap[id]->response = response;
221 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800222}
223
224std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800225 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800226{
Lei YUa8dc09b2021-10-13 18:06:46 +0800227 // The eventdata2 may contain multiple properties
228 // So we have to get the properties from DBus anyway
229 auto response = mapDbusToEventdata2(sensorInfo);
230
231 if (!sensorCacheMap[id].has_value())
232 {
233 sensorCacheMap[id] = SensorData{};
234 }
235 sensorCacheMap[id]->response = response;
236 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800237}
238
239#endif // FEATURE_SENSORS_CACHE
Tom Josephe4014fc2017-09-06 23:57:36 +0530240
Patrick Venture0b02be92018-08-31 11:55:55 -0700241} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530242
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500243namespace set
244{
245
246IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
247 const std::string& sensorPath,
248 const std::string& command,
249 const std::string& sensorInterface)
250{
Patrick Williams5d82f472022-07-22 19:26:53 -0500251 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500252 using namespace std::string_literals;
253
Patrick Venture0b02be92018-08-31 11:55:55 -0700254 auto dbusService = getService(bus, sensorInterface, sensorPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500255
Patrick Venture0b02be92018-08-31 11:55:55 -0700256 return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(),
257 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500258}
259
Willy Tu11d68892022-01-20 10:37:34 -0800260ipmi_ret_t eventdata(const SetSensorReadingReq&, const Info& sensorInfo,
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500261 uint8_t data)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500262{
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500263 auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
264 sensorInfo.sensorPath, "Set",
265 sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500266
267 const auto& interface = sensorInfo.propertyInterfaces.begin();
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500268 msg.append(interface->first);
269 for (const auto& property : interface->second)
270 {
271 msg.append(property.first);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500272 const auto& iter = std::get<OffsetValueMap>(property.second).find(data);
273 if (iter == std::get<OffsetValueMap>(property.second).end())
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500274 {
275 log<level::ERR>("Invalid event data");
276 return IPMI_CC_PARM_OUT_OF_RANGE;
277 }
278 msg.append(iter->second.assert);
279 }
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500280 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500281}
282
Patrick Venture0b02be92018-08-31 11:55:55 -0700283ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500284{
Brad Bishop06a0abf2018-02-26 20:46:00 -0500285 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
286 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
287 auto bothSet = assertionSet ^ deassertionSet;
288
289 const auto& interface = sensorInfo.propertyInterfaces.begin();
290
291 for (const auto& property : interface->second)
292 {
William A. Kennington III4c008022018-10-12 17:18:14 -0700293 std::optional<Value> tmp;
Brad Bishop06a0abf2018-02-26 20:46:00 -0500294 for (const auto& value : std::get<OffsetValueMap>(property.second))
295 {
296 if (bothSet.size() <= value.first || !bothSet.test(value.first))
297 {
298 // A BIOS shouldn't do this but ignore if they do.
299 continue;
300 }
301
302 if (assertionSet.test(value.first))
303 {
304 tmp = value.second.assert;
305 break;
306 }
307 if (deassertionSet.test(value.first))
308 {
309 tmp = value.second.deassert;
310 break;
311 }
312 }
313
William A. Kennington III4c008022018-10-12 17:18:14 -0700314 if (tmp)
Brad Bishop06a0abf2018-02-26 20:46:00 -0500315 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700316 auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
317 sensorInfo.sensorPath, "Set",
318 sensorInfo.sensorInterface);
Brad Bishop06a0abf2018-02-26 20:46:00 -0500319 msg.append(interface->first);
320 msg.append(property.first);
William A. Kennington III4c008022018-10-12 17:18:14 -0700321 msg.append(*tmp);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500322
Brad Bishop06a0abf2018-02-26 20:46:00 -0500323 auto rc = updateToDbus(msg);
324 if (rc)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500325 {
Brad Bishop06a0abf2018-02-26 20:46:00 -0500326 return rc;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500327 }
328 }
329 }
Brad Bishop06a0abf2018-02-26 20:46:00 -0500330
331 return IPMI_CC_OK;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500332}
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500333
Patrick Venture0b02be92018-08-31 11:55:55 -0700334} // namespace set
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500335
336namespace notify
337{
338
339IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
Willy Tu11d68892022-01-20 10:37:34 -0800340 const std::string&, const std::string& command,
341 const std::string&)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500342{
Patrick Williams5d82f472022-07-22 19:26:53 -0500343 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500344 using namespace std::string_literals;
345
Dhruvaraj Subhashchandranf915f852017-09-14 07:01:48 -0500346 static const auto dbusPath = "/xyz/openbmc_project/inventory"s;
347 std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500348
Patrick Venture0b02be92018-08-31 11:55:55 -0700349 return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(),
350 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500351}
352
Patrick Venture0b02be92018-08-31 11:55:55 -0700353ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500354{
Patrick Venture0b02be92018-08-31 11:55:55 -0700355 auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath,
356 "Notify", sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500357
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500358 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
359 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
360 ipmi::sensor::ObjectMap objects;
361 ipmi::sensor::InterfaceMap interfaces;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500362 for (const auto& interface : sensorInfo.propertyInterfaces)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500363 {
Santosh Puranikbbf8bd62019-05-01 19:02:52 +0530364 // An interface with no properties - It is possible that the sensor
365 // object on DBUS implements a DBUS interface with no properties.
366 // Make sure we add the interface to the list if interfaces on the
367 // object with an empty property map.
368 if (interface.second.empty())
369 {
370 interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{});
371 continue;
372 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700373 // For a property like functional state the result will be
374 // calculated based on the true value of all conditions.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500375 for (const auto& property : interface.second)
376 {
377 ipmi::sensor::PropertyMap props;
378 bool valid = false;
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500379 auto result = true;
380 for (const auto& value : std::get<OffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500381 {
382 if (assertionSet.test(value.first))
383 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700384 // Skip update if skipOn is ASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500385 if (SkipAssertion::ASSERT == value.second.skip)
386 {
387 return IPMI_CC_OK;
388 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700389 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500390 valid = true;
391 }
392 else if (deassertionSet.test(value.first))
393 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700394 // Skip update if skipOn is DEASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500395 if (SkipAssertion::DEASSERT == value.second.skip)
396 {
397 return IPMI_CC_OK;
398 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700399 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500400 valid = true;
401 }
402 }
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500403 for (const auto& value :
Patrick Venture0b02be92018-08-31 11:55:55 -0700404 std::get<PreReqOffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500405 {
406 if (assertionSet.test(value.first))
407 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700408 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500409 }
410 else if (deassertionSet.test(value.first))
411 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700412 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500413 }
414 }
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500415 if (valid)
416 {
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500417 props.emplace(property.first, result);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500418 interfaces.emplace(interface.first, std::move(props));
419 }
420 }
421 }
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500422
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500423 objects.emplace(sensorInfo.sensorPath, std::move(interfaces));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500424 msg.append(std::move(objects));
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500425 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500426}
Tom Joseph816e92b2017-09-06 19:23:00 +0530427
Patrick Venture0b02be92018-08-31 11:55:55 -0700428} // namespace notify
Tom Joseph816e92b2017-09-06 19:23:00 +0530429
430namespace inventory
431{
432
433namespace get
434{
435
Lei YUff8c9b42021-10-15 14:20:57 +0800436#ifndef FEATURE_SENSORS_CACHE
437
Tom Joseph816e92b2017-09-06 19:23:00 +0530438GetSensorResponse assertion(const Info& sensorInfo)
439{
Vernon Mauery185b9f82018-07-20 10:52:36 -0700440 namespace fs = std::filesystem;
Tom Joseph816e92b2017-09-06 19:23:00 +0530441
442 fs::path path{ipmi::sensor::inventoryRoot};
443 path += sensorInfo.sensorPath;
444
445 return ipmi::sensor::get::mapDbusToAssertion(
Patrick Venture0b02be92018-08-31 11:55:55 -0700446 sensorInfo, path.string(),
447 sensorInfo.propertyInterfaces.begin()->first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530448}
449
Lei YUff8c9b42021-10-15 14:20:57 +0800450#else
451
452std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800453 const PropertyMap& /*properties*/)
Lei YUff8c9b42021-10-15 14:20:57 +0800454{
Lei YUff8c9b42021-10-15 14:20:57 +0800455 // The assertion may contain multiple properties
456 // So we have to get the properties from DBus anyway
457 namespace fs = std::filesystem;
458
459 fs::path path{ipmi::sensor::inventoryRoot};
460 path += sensorInfo.sensorPath;
461
462 auto response = ipmi::sensor::get::mapDbusToAssertion(
463 sensorInfo, path.string(),
464 sensorInfo.propertyInterfaces.begin()->first);
465
466 if (!sensorCacheMap[id].has_value())
467 {
468 sensorCacheMap[id] = SensorData{};
469 }
470 sensorCacheMap[id]->response = response;
471 return response;
472}
473
474#endif
475
Patrick Venture0b02be92018-08-31 11:55:55 -0700476} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530477
478} // namespace inventory
Patrick Venture0b02be92018-08-31 11:55:55 -0700479} // namespace sensor
480} // namespace ipmi