blob: 68a122d935c2bbbf7ca5beb6aa7a540399cdc7c1 [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
98
99/** @brief Update d-bus based on eventdata type sensor data
100 * @param[in] cmdData - input sensor data
101 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500102 * @return a IPMI error code
103 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500104ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData,
105 const Info& sensorInfo,
106 uint8_t data);
107
108/** @brief Update d-bus based on eventdata1 type sensor data
109 * @param[in] cmdData - input sensor data
110 * @param[in] sensorInfo - sensor d-bus info
111 * @return a IPMI error code
112 */
113inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData,
114 const Info& sensorInfo)
115{
116 return eventdata(cmdData, sensorInfo, cmdData.eventData1);
117}
118
119/** @brief Update d-bus based on eventdata2 type sensor data
120 * @param[in] cmdData - input sensor data
121 * @param[in] sensorInfo - sensor d-bus info
122 * @return a IPMI error code
123 */
124inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData,
125 const Info& sensorInfo)
126{
127 return eventdata(cmdData, sensorInfo, cmdData.eventData2);
128}
129
130/** @brief Update d-bus based on eventdata3 type sensor data
131 * @param[in] cmdData - input sensor data
132 * @param[in] sensorInfo - sensor d-bus info
133 * @return a IPMI error code
134 */
135inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData,
136 const Info& sensorInfo)
137{
138 return eventdata(cmdData, sensorInfo, cmdData.eventData3);
139}
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500140
141}//namespace set
142
143namespace notify
144{
145
146/** @brief Make a DBus message for a Dbus call
147 * @param[in] updateInterface - Interface name
148 * @param[in] sensorPath - Path of the sensor
149 * @param[in] command - command to be executed
150 * @param[in] sensorInterface - DBus interface of sensor
151 * @return a dbus message
152 */
153IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
154 const std::string& sensorPath,
155 const std::string& command,
156 const std::string& sensorInterface);
157
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500158/** @brief Update d-bus based on assertion type sensor data
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500159 * @param[in] interfaceMap - sensor interface
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500160 * @param[in] cmdData - input sensor data
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500161 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500162 * @return a IPMI error code
163 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500164ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
165 const Info& sensorInfo);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500166
167}//namespace notify
168}//namespace sensor
169}//namespace ipmi