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 | |
| 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 Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 102 | * @return a IPMI error code |
| 103 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 104 | ipmi_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 | */ |
| 113 | inline 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 | */ |
| 124 | inline 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 | */ |
| 135 | inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData, |
| 136 | const Info& sensorInfo) |
| 137 | { |
| 138 | return eventdata(cmdData, sensorInfo, cmdData.eventData3); |
| 139 | } |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 140 | |
| 141 | }//namespace set |
| 142 | |
| 143 | namespace 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 | */ |
| 153 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 154 | const std::string& sensorPath, |
| 155 | const std::string& command, |
| 156 | const std::string& sensorInterface); |
| 157 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 158 | /** @brief Update d-bus based on assertion type sensor data |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 159 | * @param[in] interfaceMap - sensor interface |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 160 | * @param[in] cmdData - input sensor data |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 161 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 162 | * @return a IPMI error code |
| 163 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 164 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, |
| 165 | const Info& sensorInfo); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 166 | |
| 167 | }//namespace notify |
| 168 | }//namespace sensor |
| 169 | }//namespace ipmi |