blob: 1e196dc552ce545d29c46290c65bc7097d3171dc [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 =
Willy Tu523e2d12023-09-05 11:36:48 -070021 sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050022
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
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050044 MapperResponseType mapperResponse;
George Liu3e3cc352023-07-26 15:59:31 +080045 try
46 {
47 auto mapperResponseMsg = bus.call(mapperCall);
48 mapperResponseMsg.read(mapperResponse);
49 }
50 catch (const std::exception& e)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050051 {
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050052 log<level::ERR>("Invalid mapper response",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050053 entry("PATH=%s", path.c_str()),
George Liu3e3cc352023-07-26 15:59:31 +080054 entry("INTERFACE=%s", interface.c_str()),
55 entry("ERROR=%s", e.what()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050056 elog<InternalFailure>();
57 }
58
59 if (path.empty())
60 {
Patrick Venture0b02be92018-08-31 11:55:55 -070061 // Get the first one if the path is not in list.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050062 return std::make_pair(mapperResponse.begin()->first,
63 mapperResponse.begin()->second.begin()->first);
64 }
65 const auto& iter = mapperResponse.find(path);
66 if (iter == mapperResponse.end())
67 {
Gunnar Millsc9fa69e2018-04-08 16:35:25 -050068 log<level::ERR>("Couldn't find D-Bus path",
Joseph Reynolds510eb9c2018-05-30 11:51:28 -050069 entry("PATH=%s", path.c_str()),
70 entry("INTERFACE=%s", interface.c_str()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050071 elog<InternalFailure>();
72 }
73 return std::make_pair(iter->first, iter->second.begin()->first);
74}
75
76AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData)
77{
78 Assertion assertionStates =
79 (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 |
80 cmdData.assertOffset0_7;
81 Deassertion deassertionStates =
82 (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 |
83 cmdData.deassertOffset0_7;
84 return std::make_pair(assertionStates, deassertionStates);
85}
86
87ipmi_ret_t updateToDbus(IpmiUpdateData& msg)
88{
Patrick Williams5d82f472022-07-22 19:26:53 -050089 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050090 try
91 {
92 auto serviceResponseMsg = bus.call(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050093 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -050094 catch (const InternalFailure& e)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050095 {
George Liu3e3cc352023-07-26 15:59:31 +080096 log<level::ERR>("Error in D-Bus call", entry("ERROR=%s", e.what()));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050097 commit<InternalFailure>();
98 return IPMI_CC_UNSPECIFIED_ERROR;
99 }
100 return IPMI_CC_OK;
101}
102
Tom Joseph816e92b2017-09-06 19:23:00 +0530103namespace get
104{
105
Tom Josephb0adbcd2018-01-24 11:51:29 +0530106SensorName nameParentLeaf(const Info& sensorInfo)
107{
108 const auto pos = sensorInfo.sensorPath.find_last_of('/');
109 const auto leaf = sensorInfo.sensorPath.substr(pos + 1);
110
111 const auto remaining = sensorInfo.sensorPath.substr(0, pos);
112
113 const auto parentPos = remaining.find_last_of('/');
114 auto parent = remaining.substr(parentPos + 1);
115
116 parent += "_" + leaf;
117 return parent;
118}
119
Tom Joseph816e92b2017-09-06 19:23:00 +0530120GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
121 const InstancePath& path,
122 const DbusInterface& interface)
123{
Patrick Williams5d82f472022-07-22 19:26:53 -0500124 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700125 GetSensorResponse response{};
Tom Joseph816e92b2017-09-06 19:23:00 +0530126
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800127 enableScanning(&response);
128
Tom Joseph816e92b2017-09-06 19:23:00 +0530129 auto service = ipmi::getService(bus, interface, path);
130
131 const auto& interfaceList = sensorInfo.propertyInterfaces;
132
133 for (const auto& interface : interfaceList)
134 {
135 for (const auto& property : interface.second)
136 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700137 auto propValue = ipmi::getDbusProperty(
138 bus, service, path, interface.first, property.first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530139
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500140 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Joseph816e92b2017-09-06 19:23:00 +0530141 {
142 if (propValue == value.second.assert)
143 {
Sui Chen4cc42552019-09-11 10:28:35 -0700144 setOffset(value.first, &response);
Tom Joseph816e92b2017-09-06 19:23:00 +0530145 break;
146 }
Tom Joseph816e92b2017-09-06 19:23:00 +0530147 }
148 }
149 }
150
151 return response;
152}
153
Lei YUa8dc09b2021-10-13 18:06:46 +0800154GetSensorResponse mapDbusToEventdata2(const Info& sensorInfo)
Tom Josephe4014fc2017-09-06 23:57:36 +0530155{
Patrick Williams5d82f472022-07-22 19:26:53 -0500156 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700157 GetSensorResponse response{};
Tom Josephe4014fc2017-09-06 23:57:36 +0530158
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800159 enableScanning(&response);
160
Patrick Venture0b02be92018-08-31 11:55:55 -0700161 auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
Tom Josephe4014fc2017-09-06 23:57:36 +0530162 sensorInfo.sensorPath);
163
164 const auto& interfaceList = sensorInfo.propertyInterfaces;
165
166 for (const auto& interface : interfaceList)
167 {
168 for (const auto& property : interface.second)
169 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700170 auto propValue =
171 ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath,
172 interface.first, property.first);
Tom Josephe4014fc2017-09-06 23:57:36 +0530173
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500174 for (const auto& value : std::get<OffsetValueMap>(property.second))
Tom Josephe4014fc2017-09-06 23:57:36 +0530175 {
176 if (propValue == value.second.assert)
177 {
Sui Chen4cc42552019-09-11 10:28:35 -0700178 setReading(value.first, &response);
Tom Josephe4014fc2017-09-06 23:57:36 +0530179 break;
180 }
181 }
182 }
183 }
184
185 return response;
186}
Lei YUa8dc09b2021-10-13 18:06:46 +0800187
188#ifndef FEATURE_SENSORS_CACHE
189GetSensorResponse assertion(const Info& sensorInfo)
190{
191 return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
192 sensorInfo.sensorInterface);
193}
194
195GetSensorResponse eventdata2(const Info& sensorInfo)
196{
197 return mapDbusToEventdata2(sensorInfo);
198}
Lei YU8c2c0482021-09-16 17:28:28 +0800199#else
200std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800201 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800202{
Lei YUef960c02021-10-13 17:54:59 +0800203 // The assertion may contain multiple properties
204 // So we have to get the properties from DBus anyway
205 auto response = mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath,
206 sensorInfo.sensorInterface);
207
208 if (!sensorCacheMap[id].has_value())
209 {
210 sensorCacheMap[id] = SensorData{};
211 }
212 sensorCacheMap[id]->response = response;
213 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800214}
215
216std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800217 const PropertyMap& /*properties*/)
Lei YU8c2c0482021-09-16 17:28:28 +0800218{
Lei YUa8dc09b2021-10-13 18:06:46 +0800219 // The eventdata2 may contain multiple properties
220 // So we have to get the properties from DBus anyway
221 auto response = mapDbusToEventdata2(sensorInfo);
222
223 if (!sensorCacheMap[id].has_value())
224 {
225 sensorCacheMap[id] = SensorData{};
226 }
227 sensorCacheMap[id]->response = response;
228 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800229}
230
231#endif // FEATURE_SENSORS_CACHE
Tom Josephe4014fc2017-09-06 23:57:36 +0530232
Patrick Venture0b02be92018-08-31 11:55:55 -0700233} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530234
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500235namespace set
236{
237
238IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
239 const std::string& sensorPath,
240 const std::string& command,
241 const std::string& sensorInterface)
242{
Patrick Williams5d82f472022-07-22 19:26:53 -0500243 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500244 using namespace std::string_literals;
245
Patrick Venture0b02be92018-08-31 11:55:55 -0700246 auto dbusService = getService(bus, sensorInterface, sensorPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500247
Patrick Venture0b02be92018-08-31 11:55:55 -0700248 return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(),
249 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500250}
251
Willy Tu11d68892022-01-20 10:37:34 -0800252ipmi_ret_t eventdata(const SetSensorReadingReq&, const Info& sensorInfo,
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500253 uint8_t data)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500254{
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500255 auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
256 sensorInfo.sensorPath, "Set",
257 sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500258
259 const auto& interface = sensorInfo.propertyInterfaces.begin();
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500260 msg.append(interface->first);
261 for (const auto& property : interface->second)
262 {
263 msg.append(property.first);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500264 const auto& iter = std::get<OffsetValueMap>(property.second).find(data);
265 if (iter == std::get<OffsetValueMap>(property.second).end())
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500266 {
267 log<level::ERR>("Invalid event data");
268 return IPMI_CC_PARM_OUT_OF_RANGE;
269 }
270 msg.append(iter->second.assert);
271 }
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500272 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500273}
274
Patrick Venture0b02be92018-08-31 11:55:55 -0700275ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500276{
Brad Bishop06a0abf2018-02-26 20:46:00 -0500277 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
278 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
279 auto bothSet = assertionSet ^ deassertionSet;
280
281 const auto& interface = sensorInfo.propertyInterfaces.begin();
282
283 for (const auto& property : interface->second)
284 {
William A. Kennington III4c008022018-10-12 17:18:14 -0700285 std::optional<Value> tmp;
Brad Bishop06a0abf2018-02-26 20:46:00 -0500286 for (const auto& value : std::get<OffsetValueMap>(property.second))
287 {
288 if (bothSet.size() <= value.first || !bothSet.test(value.first))
289 {
290 // A BIOS shouldn't do this but ignore if they do.
291 continue;
292 }
293
294 if (assertionSet.test(value.first))
295 {
296 tmp = value.second.assert;
297 break;
298 }
299 if (deassertionSet.test(value.first))
300 {
301 tmp = value.second.deassert;
302 break;
303 }
304 }
305
William A. Kennington III4c008022018-10-12 17:18:14 -0700306 if (tmp)
Brad Bishop06a0abf2018-02-26 20:46:00 -0500307 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700308 auto msg = makeDbusMsg("org.freedesktop.DBus.Properties",
309 sensorInfo.sensorPath, "Set",
310 sensorInfo.sensorInterface);
Brad Bishop06a0abf2018-02-26 20:46:00 -0500311 msg.append(interface->first);
312 msg.append(property.first);
William A. Kennington III4c008022018-10-12 17:18:14 -0700313 msg.append(*tmp);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500314
Brad Bishop06a0abf2018-02-26 20:46:00 -0500315 auto rc = updateToDbus(msg);
316 if (rc)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500317 {
Brad Bishop06a0abf2018-02-26 20:46:00 -0500318 return rc;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500319 }
320 }
321 }
Brad Bishop06a0abf2018-02-26 20:46:00 -0500322
323 return IPMI_CC_OK;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500324}
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500325
Patrick Venture0b02be92018-08-31 11:55:55 -0700326} // namespace set
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500327
328namespace notify
329{
330
331IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
Willy Tu11d68892022-01-20 10:37:34 -0800332 const std::string&, const std::string& command,
333 const std::string&)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500334{
Patrick Williams5d82f472022-07-22 19:26:53 -0500335 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500336 using namespace std::string_literals;
337
Dhruvaraj Subhashchandranf915f852017-09-14 07:01:48 -0500338 static const auto dbusPath = "/xyz/openbmc_project/inventory"s;
339 std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500340
Patrick Venture0b02be92018-08-31 11:55:55 -0700341 return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(),
342 updateInterface.c_str(), command.c_str());
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500343}
344
Patrick Venture0b02be92018-08-31 11:55:55 -0700345ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500346{
Patrick Venture0b02be92018-08-31 11:55:55 -0700347 auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath,
348 "Notify", sensorInfo.sensorInterface);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500349
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500350 std::bitset<16> assertionSet(getAssertionSet(cmdData).first);
351 std::bitset<16> deassertionSet(getAssertionSet(cmdData).second);
352 ipmi::sensor::ObjectMap objects;
353 ipmi::sensor::InterfaceMap interfaces;
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500354 for (const auto& interface : sensorInfo.propertyInterfaces)
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500355 {
Santosh Puranikbbf8bd62019-05-01 19:02:52 +0530356 // An interface with no properties - It is possible that the sensor
357 // object on DBUS implements a DBUS interface with no properties.
358 // Make sure we add the interface to the list if interfaces on the
359 // object with an empty property map.
360 if (interface.second.empty())
361 {
362 interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{});
363 continue;
364 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700365 // For a property like functional state the result will be
366 // calculated based on the true value of all conditions.
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500367 for (const auto& property : interface.second)
368 {
369 ipmi::sensor::PropertyMap props;
370 bool valid = false;
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500371 auto result = true;
372 for (const auto& value : std::get<OffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500373 {
374 if (assertionSet.test(value.first))
375 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700376 // Skip update if skipOn is ASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500377 if (SkipAssertion::ASSERT == value.second.skip)
378 {
379 return IPMI_CC_OK;
380 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700381 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500382 valid = true;
383 }
384 else if (deassertionSet.test(value.first))
385 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700386 // Skip update if skipOn is DEASSERT
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500387 if (SkipAssertion::DEASSERT == value.second.skip)
388 {
389 return IPMI_CC_OK;
390 }
Vernon Maueryf442e112019-04-09 11:44:36 -0700391 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500392 valid = true;
393 }
394 }
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500395 for (const auto& value :
Patrick Venture0b02be92018-08-31 11:55:55 -0700396 std::get<PreReqOffsetValueMap>(property.second))
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500397 {
398 if (assertionSet.test(value.first))
399 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700400 result = result && std::get<bool>(value.second.assert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500401 }
402 else if (deassertionSet.test(value.first))
403 {
Vernon Maueryf442e112019-04-09 11:44:36 -0700404 result = result && std::get<bool>(value.second.deassert);
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500405 }
406 }
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500407 if (valid)
408 {
Dhruvaraj Subhashchandrane245e4e2017-10-03 03:58:05 -0500409 props.emplace(property.first, result);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500410 interfaces.emplace(interface.first, std::move(props));
411 }
412 }
413 }
Dhruvaraj Subhashchandrane84841c2017-08-22 07:40:27 -0500414
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500415 objects.emplace(sensorInfo.sensorPath, std::move(interfaces));
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500416 msg.append(std::move(objects));
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500417 return updateToDbus(msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500418}
Tom Joseph816e92b2017-09-06 19:23:00 +0530419
Patrick Venture0b02be92018-08-31 11:55:55 -0700420} // namespace notify
Tom Joseph816e92b2017-09-06 19:23:00 +0530421
422namespace inventory
423{
424
425namespace get
426{
427
Lei YUff8c9b42021-10-15 14:20:57 +0800428#ifndef FEATURE_SENSORS_CACHE
429
Tom Joseph816e92b2017-09-06 19:23:00 +0530430GetSensorResponse assertion(const Info& sensorInfo)
431{
Vernon Mauery185b9f82018-07-20 10:52:36 -0700432 namespace fs = std::filesystem;
Tom Joseph816e92b2017-09-06 19:23:00 +0530433
434 fs::path path{ipmi::sensor::inventoryRoot};
435 path += sensorInfo.sensorPath;
436
437 return ipmi::sensor::get::mapDbusToAssertion(
Patrick Venture0b02be92018-08-31 11:55:55 -0700438 sensorInfo, path.string(),
439 sensorInfo.propertyInterfaces.begin()->first);
Tom Joseph816e92b2017-09-06 19:23:00 +0530440}
441
Lei YUff8c9b42021-10-15 14:20:57 +0800442#else
443
444std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
Lei YU8e8152c2021-12-06 20:11:08 +0800445 const PropertyMap& /*properties*/)
Lei YUff8c9b42021-10-15 14:20:57 +0800446{
Lei YUff8c9b42021-10-15 14:20:57 +0800447 // The assertion may contain multiple properties
448 // So we have to get the properties from DBus anyway
449 namespace fs = std::filesystem;
450
451 fs::path path{ipmi::sensor::inventoryRoot};
452 path += sensorInfo.sensorPath;
453
454 auto response = ipmi::sensor::get::mapDbusToAssertion(
455 sensorInfo, path.string(),
456 sensorInfo.propertyInterfaces.begin()->first);
457
458 if (!sensorCacheMap[id].has_value())
459 {
460 sensorCacheMap[id] = SensorData{};
461 }
462 sensorCacheMap[id]->response = response;
463 return response;
464}
465
466#endif
467
Patrick Venture0b02be92018-08-31 11:55:55 -0700468} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530469
470} // namespace inventory
Patrick Venture0b02be92018-08-31 11:55:55 -0700471} // namespace sensor
472} // namespace ipmi