blob: 14d2151d3a97f8d8d9fa8b472c21bf0b983b5cb7 [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#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>
SunnySrivastava19849a195542020-09-07 06:04:50 -05007#include <sdbusplus/sdbuspp_support/server.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06008#include <sdbusplus/server.hpp>
9#include <string>
10#include <tuple>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060011#include <xyz/openbmc_project/Common/error.hpp>
12
13namespace sdbusplus
14{
15namespace com
16{
17namespace ibm
18{
19namespace VPD
20{
21namespace server
22{
23
Patrick Williams2eb01762022-07-22 19:26:56 -050024Manager::Manager(bus_t& bus, const char* path) :
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060025 _com_ibm_VPD_Manager_interface(bus, path, interface, _vtable, this),
26 _intf(bus.getInterface())
27{
28}
29
30int Manager::_callback_WriteKeyword(sd_bus_message* msg, void* context,
31 sd_bus_error* error)
32{
SunnySrivastava19849a195542020-09-07 06:04:50 -050033 auto o = static_cast<Manager*>(context);
34
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060035 try
36 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050037 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 }));
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060044 }
Patrick Williams8e15b932021-10-06 13:04:22 -050045 catch (
46 const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
47 e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060048 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050049 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060050 }
Patrick Williams8e15b932021-10-06 13:04:22 -050051 catch (const sdbusplus::com::ibm::VPD::Error::PathNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060052 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050053 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060054 }
Patrick Williams8e15b932021-10-06 13:04:22 -050055 catch (const sdbusplus::com::ibm::VPD::Error::RecordNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060056 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050057 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060058 }
Patrick Williams8e15b932021-10-06 13:04:22 -050059 catch (const sdbusplus::com::ibm::VPD::Error::KeywordNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060060 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050061 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060062 }
63
SunnySrivastava19849a195542020-09-07 06:04:50 -050064 return 0;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060065}
66
67namespace details
68{
69namespace Manager
70{
71static const auto _param_WriteKeyword = utility::tuple_to_array(
72 message::types::type_id<sdbusplus::message::object_path, std::string,
73 std::string, std::vector<uint8_t>>());
74static const auto _return_WriteKeyword =
75 utility::tuple_to_array(std::make_tuple('\0'));
76} // namespace Manager
77} // namespace details
78
79int Manager::_callback_GetFRUsByUnexpandedLocationCode(sd_bus_message* msg,
80 void* context,
81 sd_bus_error* error)
82{
SunnySrivastava19849a195542020-09-07 06:04:50 -050083 auto o = static_cast<Manager*>(context);
84
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060085 try
86 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050087 return sdbusplus::sdbuspp::method_callback(
88 msg, o->_intf, error,
89 std::function(
90 [=](std::string&& locationCode, uint16_t&& nodeNumber) {
91 return o->getFRUsByUnexpandedLocationCode(locationCode,
92 nodeNumber);
93 }));
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060094 }
Patrick Williams8e15b932021-10-06 13:04:22 -050095 catch (
96 const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
97 e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060098 {
SunnySrivastava19849a195542020-09-07 06:04:50 -050099 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600100 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500101 catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600102 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500103 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600104 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500105 catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600106 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500107 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600108 }
109
SunnySrivastava19849a195542020-09-07 06:04:50 -0500110 return 0;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600111}
112
113namespace details
114{
115namespace Manager
116{
117static const auto _param_GetFRUsByUnexpandedLocationCode =
118 utility::tuple_to_array(message::types::type_id<std::string, uint16_t>());
119static const auto _return_GetFRUsByUnexpandedLocationCode =
120 utility::tuple_to_array(message::types::type_id<
121 std::vector<sdbusplus::message::object_path>>());
122} // namespace Manager
123} // namespace details
124
125int Manager::_callback_GetFRUsByExpandedLocationCode(sd_bus_message* msg,
126 void* context,
127 sd_bus_error* error)
128{
SunnySrivastava19849a195542020-09-07 06:04:50 -0500129 auto o = static_cast<Manager*>(context);
130
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600131 try
132 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500133 return sdbusplus::sdbuspp::method_callback(
134 msg, o->_intf, error,
135 std::function([=](std::string&& locationCode) {
136 return o->getFRUsByExpandedLocationCode(locationCode);
137 }));
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600138 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500139 catch (
140 const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
141 e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600142 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500143 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600144 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500145 catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600146 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500147 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600148 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500149 catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600150 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500151 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600152 }
153
SunnySrivastava19849a195542020-09-07 06:04:50 -0500154 return 0;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600155}
156
157namespace details
158{
159namespace Manager
160{
161static const auto _param_GetFRUsByExpandedLocationCode =
162 utility::tuple_to_array(message::types::type_id<std::string>());
163static const auto _return_GetFRUsByExpandedLocationCode =
164 utility::tuple_to_array(message::types::type_id<
165 std::vector<sdbusplus::message::object_path>>());
166} // namespace Manager
167} // namespace details
168
169int Manager::_callback_GetExpandedLocationCode(sd_bus_message* msg,
170 void* context,
171 sd_bus_error* error)
172{
SunnySrivastava19849a195542020-09-07 06:04:50 -0500173 auto o = static_cast<Manager*>(context);
174
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600175 try
176 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500177 return sdbusplus::sdbuspp::method_callback(
178 msg, o->_intf, error,
179 std::function(
180 [=](std::string&& locationCode, uint16_t&& nodeNumber) {
181 return o->getExpandedLocationCode(locationCode, nodeNumber);
182 }));
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600183 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500184 catch (
185 const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
186 e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600187 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500188 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600189 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500190 catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600191 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500192 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600193 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500194 catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600195 {
SunnySrivastava19849a195542020-09-07 06:04:50 -0500196 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600197 }
198
SunnySrivastava19849a195542020-09-07 06:04:50 -0500199 return 0;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600200}
201
202namespace details
203{
204namespace Manager
205{
206static const auto _param_GetExpandedLocationCode =
207 utility::tuple_to_array(message::types::type_id<std::string, uint16_t>());
208static const auto _return_GetExpandedLocationCode =
209 utility::tuple_to_array(message::types::type_id<std::string>());
210} // namespace Manager
211} // namespace details
212
SunnySrivastava19849a195542020-09-07 06:04:50 -0500213int Manager::_callback_PerformVPDRecollection(sd_bus_message* msg,
214 void* context,
215 sd_bus_error* error)
216{
217 auto o = static_cast<Manager*>(context);
218
219 try
220 {
221 return sdbusplus::sdbuspp::method_callback(
222 msg, o->_intf, error,
223 std::function([=]() { return o->performVPDRecollection(); }));
224 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500225 catch (
226 const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
227 e)
SunnySrivastava19849a195542020-09-07 06:04:50 -0500228 {
229 return o->_intf->sd_bus_error_set(error, e.name(), e.description());
230 }
231
232 return 0;
233}
234
235namespace details
236{
237namespace Manager
238{
239static const auto _param_PerformVPDRecollection =
240 utility::tuple_to_array(std::make_tuple('\0'));
241static const auto _return_PerformVPDRecollection =
242 utility::tuple_to_array(std::make_tuple('\0'));
243} // namespace Manager
244} // namespace details
245
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600246const vtable::vtable_t Manager::_vtable[] = {
247 vtable::start(),
248
249 vtable::method("WriteKeyword", details::Manager::_param_WriteKeyword.data(),
250 details::Manager::_return_WriteKeyword.data(),
251 _callback_WriteKeyword),
252
253 vtable::method(
254 "GetFRUsByUnexpandedLocationCode",
255 details::Manager::_param_GetFRUsByUnexpandedLocationCode.data(),
256 details::Manager::_return_GetFRUsByUnexpandedLocationCode.data(),
257 _callback_GetFRUsByUnexpandedLocationCode),
258
259 vtable::method(
260 "GetFRUsByExpandedLocationCode",
261 details::Manager::_param_GetFRUsByExpandedLocationCode.data(),
262 details::Manager::_return_GetFRUsByExpandedLocationCode.data(),
263 _callback_GetFRUsByExpandedLocationCode),
264
265 vtable::method("GetExpandedLocationCode",
266 details::Manager::_param_GetExpandedLocationCode.data(),
267 details::Manager::_return_GetExpandedLocationCode.data(),
268 _callback_GetExpandedLocationCode),
SunnySrivastava19849a195542020-09-07 06:04:50 -0500269
270 vtable::method("PerformVPDRecollection",
271 details::Manager::_param_PerformVPDRecollection.data(),
272 details::Manager::_return_PerformVPDRecollection.data(),
273 _callback_PerformVPDRecollection),
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600274 vtable::end()};
275
276} // namespace server
277} // namespace VPD
278} // namespace ibm
279} // namespace com
280} // namespace sdbusplus