| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 1 | #pragma once | 
 | 2 |  | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 3 | #include "types.hpp" | 
 | 4 | #include "host-ipmid/ipmid-api.h" | 
 | 5 |  | 
 | 6 | namespace ipmi | 
 | 7 | { | 
 | 8 | namespace sensor | 
 | 9 | { | 
 | 10 |  | 
 | 11 | using Assertion = uint16_t; | 
 | 12 | using Deassertion = uint16_t; | 
 | 13 | using AssertionSet = std::pair<Assertion, Deassertion>; | 
 | 14 |  | 
 | 15 | using Service = std::string; | 
 | 16 | using Path = std::string; | 
 | 17 | using Interface = std::string; | 
 | 18 |  | 
 | 19 | using ServicePath = std::pair<Path, Service>; | 
 | 20 |  | 
 | 21 | using Interfaces = std::vector<Interface>; | 
 | 22 |  | 
 | 23 | using 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 |  */ | 
 | 31 | ServicePath 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 |  */ | 
 | 39 | AssertionSet 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 Subhashchandran | 2a444d0 | 2017-08-07 01:45:14 -0500 | [diff] [blame] | 45 | ipmi_ret_t updateToDbus(IpmiUpdateData& msg); | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 46 |  | 
 | 47 | namespace 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 |  */ | 
 | 57 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, | 
 | 58 |                            const std::string& sensorPath, | 
 | 59 |                            const std::string& command, | 
 | 60 |                            const std::string& sensorInterface); | 
 | 61 |  | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 62 | /** @brief Update d-bus based on assertion type sensor data | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 63 |  *  @param[in] cmdData - input sensor data | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 64 |  *  @param[in] sensorInfo - sensor d-bus info | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 65 |  *  @return a IPMI error code | 
 | 66 |  */ | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 67 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, | 
 | 68 |                      const Info& sensorInfo); | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 69 |  | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 70 | /** @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 Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 74 |  *  @return a IPMI error code | 
 | 75 |  */ | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 76 | template<typename T> | 
 | 77 | ipmi_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 Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 85 |  | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 86 |     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 Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame^] | 98 | /** @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 |  */ | 
 | 103 | template<typename T> | 
 | 104 | ipmi_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 Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 134 |  | 
 | 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 Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 138 |  *  @return a IPMI error code | 
 | 139 |  */ | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 140 | ipmi_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 |  */ | 
 | 149 | inline 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 |  */ | 
 | 160 | inline 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 |  */ | 
 | 171 | inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData, | 
 | 172 |                              const Info& sensorInfo) | 
 | 173 | { | 
 | 174 |     return eventdata(cmdData, sensorInfo, cmdData.eventData3); | 
 | 175 | } | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 176 |  | 
 | 177 | }//namespace set | 
 | 178 |  | 
 | 179 | namespace 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 |  */ | 
 | 189 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, | 
 | 190 |                            const std::string& sensorPath, | 
 | 191 |                            const std::string& command, | 
 | 192 |                            const std::string& sensorInterface); | 
 | 193 |  | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 194 | /** @brief Update d-bus based on assertion type sensor data | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 195 |  *  @param[in] interfaceMap - sensor interface | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 196 |  *  @param[in] cmdData - input sensor data | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 197 |  *  @param[in] sensorInfo - sensor d-bus info | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 198 |  *  @return a IPMI error code | 
 | 199 |  */ | 
| Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 200 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, | 
 | 201 |                      const Info& sensorInfo); | 
| Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 202 |  | 
 | 203 | }//namespace notify | 
 | 204 | }//namespace sensor | 
 | 205 | }//namespace ipmi |