SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #include <algorithm> |
| 2 | #include <com/ibm/VPD/Manager/server.hpp> |
| 3 | #include <com/ibm/VPD/error.hpp> |
| 4 | #include <map> |
| 5 | #include <sdbusplus/exception.hpp> |
| 6 | #include <sdbusplus/sdbus.hpp> |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 7 | #include <sdbusplus/sdbuspp_support/server.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 8 | #include <sdbusplus/server.hpp> |
| 9 | #include <string> |
| 10 | #include <tuple> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | |
| 13 | namespace sdbusplus |
| 14 | { |
| 15 | namespace com |
| 16 | { |
| 17 | namespace ibm |
| 18 | { |
| 19 | namespace VPD |
| 20 | { |
| 21 | namespace server |
| 22 | { |
| 23 | |
| 24 | Manager::Manager(bus::bus& bus, const char* path) : |
| 25 | _com_ibm_VPD_Manager_interface(bus, path, interface, _vtable, this), |
| 26 | _intf(bus.getInterface()) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | int Manager::_callback_WriteKeyword(sd_bus_message* msg, void* context, |
| 31 | sd_bus_error* error) |
| 32 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 33 | auto o = static_cast<Manager*>(context); |
| 34 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 35 | try |
| 36 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 37 | return sdbusplus::sdbuspp::method_callback( |
| 38 | msg, o->_intf, error, |
| 39 | std::function([=](sdbusplus::message::object_path&& path, |
| 40 | std::string&& record, std::string&& keyword, |
| 41 | std::vector<uint8_t>&& value) { |
| 42 | return o->writeKeyword(path, record, keyword, value); |
| 43 | })); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 44 | } |
| 45 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 46 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 47 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 48 | } |
| 49 | catch (sdbusplus::com::ibm::VPD::Error::PathNotFound& e) |
| 50 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 51 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 52 | } |
| 53 | catch (sdbusplus::com::ibm::VPD::Error::RecordNotFound& e) |
| 54 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 55 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 56 | } |
| 57 | catch (sdbusplus::com::ibm::VPD::Error::KeywordNotFound& e) |
| 58 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 59 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 60 | } |
| 61 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 62 | return 0; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | namespace details |
| 66 | { |
| 67 | namespace Manager |
| 68 | { |
| 69 | static const auto _param_WriteKeyword = utility::tuple_to_array( |
| 70 | message::types::type_id<sdbusplus::message::object_path, std::string, |
| 71 | std::string, std::vector<uint8_t>>()); |
| 72 | static const auto _return_WriteKeyword = |
| 73 | utility::tuple_to_array(std::make_tuple('\0')); |
| 74 | } // namespace Manager |
| 75 | } // namespace details |
| 76 | |
| 77 | int Manager::_callback_GetFRUsByUnexpandedLocationCode(sd_bus_message* msg, |
| 78 | void* context, |
| 79 | sd_bus_error* error) |
| 80 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 81 | auto o = static_cast<Manager*>(context); |
| 82 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 83 | try |
| 84 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 85 | return sdbusplus::sdbuspp::method_callback( |
| 86 | msg, o->_intf, error, |
| 87 | std::function( |
| 88 | [=](std::string&& locationCode, uint16_t&& nodeNumber) { |
| 89 | return o->getFRUsByUnexpandedLocationCode(locationCode, |
| 90 | nodeNumber); |
| 91 | })); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 92 | } |
| 93 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 94 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 95 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 96 | } |
| 97 | catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e) |
| 98 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 99 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 100 | } |
| 101 | catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e) |
| 102 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 103 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 104 | } |
| 105 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 106 | return 0; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | namespace details |
| 110 | { |
| 111 | namespace Manager |
| 112 | { |
| 113 | static const auto _param_GetFRUsByUnexpandedLocationCode = |
| 114 | utility::tuple_to_array(message::types::type_id<std::string, uint16_t>()); |
| 115 | static const auto _return_GetFRUsByUnexpandedLocationCode = |
| 116 | utility::tuple_to_array(message::types::type_id< |
| 117 | std::vector<sdbusplus::message::object_path>>()); |
| 118 | } // namespace Manager |
| 119 | } // namespace details |
| 120 | |
| 121 | int Manager::_callback_GetFRUsByExpandedLocationCode(sd_bus_message* msg, |
| 122 | void* context, |
| 123 | sd_bus_error* error) |
| 124 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 125 | auto o = static_cast<Manager*>(context); |
| 126 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 127 | try |
| 128 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 129 | return sdbusplus::sdbuspp::method_callback( |
| 130 | msg, o->_intf, error, |
| 131 | std::function([=](std::string&& locationCode) { |
| 132 | return o->getFRUsByExpandedLocationCode(locationCode); |
| 133 | })); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 134 | } |
| 135 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 136 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 137 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 138 | } |
| 139 | catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e) |
| 140 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 141 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 142 | } |
| 143 | catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e) |
| 144 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 145 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 146 | } |
| 147 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 148 | return 0; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | namespace details |
| 152 | { |
| 153 | namespace Manager |
| 154 | { |
| 155 | static const auto _param_GetFRUsByExpandedLocationCode = |
| 156 | utility::tuple_to_array(message::types::type_id<std::string>()); |
| 157 | static const auto _return_GetFRUsByExpandedLocationCode = |
| 158 | utility::tuple_to_array(message::types::type_id< |
| 159 | std::vector<sdbusplus::message::object_path>>()); |
| 160 | } // namespace Manager |
| 161 | } // namespace details |
| 162 | |
| 163 | int Manager::_callback_GetExpandedLocationCode(sd_bus_message* msg, |
| 164 | void* context, |
| 165 | sd_bus_error* error) |
| 166 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 167 | auto o = static_cast<Manager*>(context); |
| 168 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 169 | try |
| 170 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 171 | return sdbusplus::sdbuspp::method_callback( |
| 172 | msg, o->_intf, error, |
| 173 | std::function( |
| 174 | [=](std::string&& locationCode, uint16_t&& nodeNumber) { |
| 175 | return o->getExpandedLocationCode(locationCode, nodeNumber); |
| 176 | })); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 177 | } |
| 178 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 179 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 180 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 181 | } |
| 182 | catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e) |
| 183 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 184 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 185 | } |
| 186 | catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e) |
| 187 | { |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 188 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 189 | } |
| 190 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 191 | return 0; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | namespace details |
| 195 | { |
| 196 | namespace Manager |
| 197 | { |
| 198 | static const auto _param_GetExpandedLocationCode = |
| 199 | utility::tuple_to_array(message::types::type_id<std::string, uint16_t>()); |
| 200 | static const auto _return_GetExpandedLocationCode = |
| 201 | utility::tuple_to_array(message::types::type_id<std::string>()); |
| 202 | } // namespace Manager |
| 203 | } // namespace details |
| 204 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 205 | int Manager::_callback_PerformVPDRecollection(sd_bus_message* msg, |
| 206 | void* context, |
| 207 | sd_bus_error* error) |
| 208 | { |
| 209 | auto o = static_cast<Manager*>(context); |
| 210 | |
| 211 | try |
| 212 | { |
| 213 | return sdbusplus::sdbuspp::method_callback( |
| 214 | msg, o->_intf, error, |
| 215 | std::function([=]() { return o->performVPDRecollection(); })); |
| 216 | } |
| 217 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 218 | { |
| 219 | return o->_intf->sd_bus_error_set(error, e.name(), e.description()); |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | namespace details |
| 226 | { |
| 227 | namespace Manager |
| 228 | { |
| 229 | static const auto _param_PerformVPDRecollection = |
| 230 | utility::tuple_to_array(std::make_tuple('\0')); |
| 231 | static const auto _return_PerformVPDRecollection = |
| 232 | utility::tuple_to_array(std::make_tuple('\0')); |
| 233 | } // namespace Manager |
| 234 | } // namespace details |
| 235 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 236 | const vtable::vtable_t Manager::_vtable[] = { |
| 237 | vtable::start(), |
| 238 | |
| 239 | vtable::method("WriteKeyword", details::Manager::_param_WriteKeyword.data(), |
| 240 | details::Manager::_return_WriteKeyword.data(), |
| 241 | _callback_WriteKeyword), |
| 242 | |
| 243 | vtable::method( |
| 244 | "GetFRUsByUnexpandedLocationCode", |
| 245 | details::Manager::_param_GetFRUsByUnexpandedLocationCode.data(), |
| 246 | details::Manager::_return_GetFRUsByUnexpandedLocationCode.data(), |
| 247 | _callback_GetFRUsByUnexpandedLocationCode), |
| 248 | |
| 249 | vtable::method( |
| 250 | "GetFRUsByExpandedLocationCode", |
| 251 | details::Manager::_param_GetFRUsByExpandedLocationCode.data(), |
| 252 | details::Manager::_return_GetFRUsByExpandedLocationCode.data(), |
| 253 | _callback_GetFRUsByExpandedLocationCode), |
| 254 | |
| 255 | vtable::method("GetExpandedLocationCode", |
| 256 | details::Manager::_param_GetExpandedLocationCode.data(), |
| 257 | details::Manager::_return_GetExpandedLocationCode.data(), |
| 258 | _callback_GetExpandedLocationCode), |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 259 | |
| 260 | vtable::method("PerformVPDRecollection", |
| 261 | details::Manager::_param_PerformVPDRecollection.data(), |
| 262 | details::Manager::_return_PerformVPDRecollection.data(), |
| 263 | _callback_PerformVPDRecollection), |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 264 | vtable::end()}; |
| 265 | |
| 266 | } // namespace server |
| 267 | } // namespace VPD |
| 268 | } // namespace ibm |
| 269 | } // namespace com |
| 270 | } // namespace sdbusplus |