blob: ca82666849e929ac4274a748f6a0dc2850a041ec [file] [log] [blame]
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -05001#pragma once
2
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -05003#include "types.hpp"
4#include "host-ipmid/ipmid-api.h"
5
6namespace ipmi
7{
8namespace sensor
9{
10
11using Assertion = uint16_t;
12using Deassertion = uint16_t;
13using AssertionSet = std::pair<Assertion, Deassertion>;
14
15using Service = std::string;
16using Path = std::string;
17using Interface = std::string;
18
19using ServicePath = std::pair<Path, Service>;
20
21using Interfaces = std::vector<Interface>;
22
23using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>;
24
25/** @brief get the D-Bus service and service path
26 * @param[in] bus - The Dbus bus object
27 * @param[in] interface - interface to the service
28 * @param[in] path - interested path in the list of objects
29 * @return pair of service path and service
30 */
31ServicePath getServiceAndPath(sdbusplus::bus::bus& bus,
32 const std::string& interface,
33 const std::string& path = std::string());
34
35/** @brief Make assertion set from input data
36 * @param[in] cmdData - Input sensor data
37 * @return pair of assertion and deassertion set
38 */
39AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData);
40
41/** @brief send the message to DBus
42 * @param[in] msg - message to send
43 * @return failure status in IPMI error code
44 */
Dhruvaraj Subhashchandran2a444d02017-08-07 01:45:14 -050045ipmi_ret_t updateToDbus(IpmiUpdateData& msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050046
47namespace set
48{
49
50/** @brief Make a DBus message for a Dbus call
51 * @param[in] updateInterface - Interface name
52 * @param[in] sensorPath - Path of the sensor
53 * @param[in] command - command to be executed
54 * @param[in] sensorInterface - DBus interface of sensor
55 * @return a dbus message
56 */
57IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
58 const std::string& sensorPath,
59 const std::string& command,
60 const std::string& sensorInterface);
61
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050062/** @brief Update d-bus based on assertion type sensor data
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050063 * @param[in] cmdData - input sensor data
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050064 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050065 * @return a IPMI error code
66 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050067ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
68 const Info& sensorInfo);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050069
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050070/** @brief Update d-bus based on a reading assertion
71 * @tparam T - type of d-bus property mapping this sensor
72 * @param[in] cmdData - input sensor data
73 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050074 * @return a IPMI error code
75 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050076template<typename T>
77ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData,
78 const Info& sensorInfo)
79{
80 auto msg = makeDbusMsg(
81 "org.freedesktop.DBus.Properties",
82 sensorInfo.sensorPath,
83 "Set",
84 sensorInfo.sensorInterface);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050085
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -050086 const auto& interface = sensorInfo.propertyInterfaces.begin();
87 msg.append(interface->first);
88 for (const auto& property : interface->second)
89 {
90 msg.append(property.first);
91 sdbusplus::message::variant<T> value =
92 (cmdData.assertOffset8_14 << 8) | cmdData.assertOffset0_7;
93 msg.append(value);
94 }
95 return updateToDbus(msg);
96}
97
Emily Shaffercc941e12017-06-14 13:06:26 -070098/** @brief Update d-bus based on a discrete reading
99 * @param[in] cmdData - input sensor data
100 * @param[in] sensorInfo - sensor d-bus info
101 * @return an IPMI error code
102 */
103template<typename T>
104ipmi_ret_t readingData(const SetSensorReadingReq& cmdData,
105 const Info& sensorInfo)
106{
107 auto msg = makeDbusMsg(
108 "org.freedesktop.DBus.Properties",
109 sensorInfo.sensorPath,
110 "Set",
111 sensorInfo.sensorInterface);
112
113 const auto& interface = sensorInfo.propertyInterfaces.begin();
114 msg.append(interface->first);
115
116 ipmi::sensor::Multiplier m = sensorInfo.coefficientM;
117 if (0 == m)
118 {
119 m = 1; // Avoid * 0
120 }
121
122 // TODO: Refactor this into a generated function depending on the type
123 // of conversion for the value between IPMI and dbus.
124 T raw_value = (m * cmdData.reading) + sensorInfo.scaledOffset;
125
126 for (const auto& property : interface->second)
127 {
128 msg.append(property.first);
129 sdbusplus::message::variant<T> value = raw_value;
130 msg.append(value);
131 }
132 return updateToDbus(msg);
133}
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500134
135/** @brief Update d-bus based on eventdata type sensor data
136 * @param[in] cmdData - input sensor data
137 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500138 * @return a IPMI error code
139 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500140ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData,
141 const Info& sensorInfo,
142 uint8_t data);
143
144/** @brief Update d-bus based on eventdata1 type sensor data
145 * @param[in] cmdData - input sensor data
146 * @param[in] sensorInfo - sensor d-bus info
147 * @return a IPMI error code
148 */
149inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData,
150 const Info& sensorInfo)
151{
152 return eventdata(cmdData, sensorInfo, cmdData.eventData1);
153}
154
155/** @brief Update d-bus based on eventdata2 type sensor data
156 * @param[in] cmdData - input sensor data
157 * @param[in] sensorInfo - sensor d-bus info
158 * @return a IPMI error code
159 */
160inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData,
161 const Info& sensorInfo)
162{
163 return eventdata(cmdData, sensorInfo, cmdData.eventData2);
164}
165
166/** @brief Update d-bus based on eventdata3 type sensor data
167 * @param[in] cmdData - input sensor data
168 * @param[in] sensorInfo - sensor d-bus info
169 * @return a IPMI error code
170 */
171inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData,
172 const Info& sensorInfo)
173{
174 return eventdata(cmdData, sensorInfo, cmdData.eventData3);
175}
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500176
177}//namespace set
178
179namespace notify
180{
181
182/** @brief Make a DBus message for a Dbus call
183 * @param[in] updateInterface - Interface name
184 * @param[in] sensorPath - Path of the sensor
185 * @param[in] command - command to be executed
186 * @param[in] sensorInterface - DBus interface of sensor
187 * @return a dbus message
188 */
189IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
190 const std::string& sensorPath,
191 const std::string& command,
192 const std::string& sensorInterface);
193
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500194/** @brief Update d-bus based on assertion type sensor data
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500195 * @param[in] interfaceMap - sensor interface
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500196 * @param[in] cmdData - input sensor data
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500197 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500198 * @return a IPMI error code
199 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500200ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
201 const Info& sensorInfo);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500202
203}//namespace notify
204}//namespace sensor
205}//namespace ipmi