blob: 8291ecdbd108a4e4f62f12724322e1fd01fe8ecf [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>
7#include <sdbusplus/server.hpp>
8#include <string>
9#include <tuple>
10#include <variant>
11#include <xyz/openbmc_project/Common/error.hpp>
12
13namespace sdbusplus
14{
15namespace com
16{
17namespace ibm
18{
19namespace VPD
20{
21namespace server
22{
23
24Manager::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
30int Manager::_callback_WriteKeyword(sd_bus_message* msg, void* context,
31 sd_bus_error* error)
32{
33 try
34 {
35 auto m = message::message(msg);
36#if 1
37 {
38 auto tbus = m.get_bus();
39 sdbusplus::server::transaction::Transaction t(tbus, m);
40 sdbusplus::server::transaction::set_id(
41 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
42 }
43#endif
44
45 sdbusplus::message::object_path path{};
46 std::string record{};
47 std::string keyword{};
48 std::vector<uint8_t> value{};
49
50 m.read(path, record, keyword, value);
51
52 auto o = static_cast<Manager*>(context);
53 o->writeKeyword(path, record, keyword, value);
54
55 auto reply = m.new_method_return();
56 // No data to append on reply.
57
58 reply.method_return();
59 }
60 catch (sdbusplus::internal_exception_t& e)
61 {
62 return sd_bus_error_set(error, e.name(), e.description());
63 }
64 catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
65 {
66 return sd_bus_error_set(error, e.name(), e.description());
67 }
68 catch (sdbusplus::com::ibm::VPD::Error::PathNotFound& e)
69 {
70 return sd_bus_error_set(error, e.name(), e.description());
71 }
72 catch (sdbusplus::com::ibm::VPD::Error::RecordNotFound& e)
73 {
74 return sd_bus_error_set(error, e.name(), e.description());
75 }
76 catch (sdbusplus::com::ibm::VPD::Error::KeywordNotFound& e)
77 {
78 return sd_bus_error_set(error, e.name(), e.description());
79 }
80
81 return true;
82}
83
84namespace details
85{
86namespace Manager
87{
88static const auto _param_WriteKeyword = utility::tuple_to_array(
89 message::types::type_id<sdbusplus::message::object_path, std::string,
90 std::string, std::vector<uint8_t>>());
91static const auto _return_WriteKeyword =
92 utility::tuple_to_array(std::make_tuple('\0'));
93} // namespace Manager
94} // namespace details
95
96int Manager::_callback_GetFRUsByUnexpandedLocationCode(sd_bus_message* msg,
97 void* context,
98 sd_bus_error* error)
99{
100 try
101 {
102 auto m = message::message(msg);
103#if 1
104 {
105 auto tbus = m.get_bus();
106 sdbusplus::server::transaction::Transaction t(tbus, m);
107 sdbusplus::server::transaction::set_id(
108 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
109 }
110#endif
111
112 std::string locationCode{};
113 uint16_t nodeNumber{};
114
115 m.read(locationCode, nodeNumber);
116
117 auto o = static_cast<Manager*>(context);
118 auto r = o->getFRUsByUnexpandedLocationCode(locationCode, nodeNumber);
119
120 auto reply = m.new_method_return();
121 reply.append(std::move(r));
122
123 reply.method_return();
124 }
125 catch (sdbusplus::internal_exception_t& e)
126 {
127 return sd_bus_error_set(error, e.name(), e.description());
128 }
129 catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
130 {
131 return sd_bus_error_set(error, e.name(), e.description());
132 }
133 catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
134 {
135 return sd_bus_error_set(error, e.name(), e.description());
136 }
137 catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
138 {
139 return sd_bus_error_set(error, e.name(), e.description());
140 }
141
142 return true;
143}
144
145namespace details
146{
147namespace Manager
148{
149static const auto _param_GetFRUsByUnexpandedLocationCode =
150 utility::tuple_to_array(message::types::type_id<std::string, uint16_t>());
151static const auto _return_GetFRUsByUnexpandedLocationCode =
152 utility::tuple_to_array(message::types::type_id<
153 std::vector<sdbusplus::message::object_path>>());
154} // namespace Manager
155} // namespace details
156
157int Manager::_callback_GetFRUsByExpandedLocationCode(sd_bus_message* msg,
158 void* context,
159 sd_bus_error* error)
160{
161 try
162 {
163 auto m = message::message(msg);
164#if 1
165 {
166 auto tbus = m.get_bus();
167 sdbusplus::server::transaction::Transaction t(tbus, m);
168 sdbusplus::server::transaction::set_id(
169 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
170 }
171#endif
172
173 std::string locationCode{};
174
175 m.read(locationCode);
176
177 auto o = static_cast<Manager*>(context);
178 auto r = o->getFRUsByExpandedLocationCode(locationCode);
179
180 auto reply = m.new_method_return();
181 reply.append(std::move(r));
182
183 reply.method_return();
184 }
185 catch (sdbusplus::internal_exception_t& e)
186 {
187 return sd_bus_error_set(error, e.name(), e.description());
188 }
189 catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
190 {
191 return sd_bus_error_set(error, e.name(), e.description());
192 }
193 catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
194 {
195 return sd_bus_error_set(error, e.name(), e.description());
196 }
197 catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
198 {
199 return sd_bus_error_set(error, e.name(), e.description());
200 }
201
202 return true;
203}
204
205namespace details
206{
207namespace Manager
208{
209static const auto _param_GetFRUsByExpandedLocationCode =
210 utility::tuple_to_array(message::types::type_id<std::string>());
211static const auto _return_GetFRUsByExpandedLocationCode =
212 utility::tuple_to_array(message::types::type_id<
213 std::vector<sdbusplus::message::object_path>>());
214} // namespace Manager
215} // namespace details
216
217int Manager::_callback_GetExpandedLocationCode(sd_bus_message* msg,
218 void* context,
219 sd_bus_error* error)
220{
221 try
222 {
223 auto m = message::message(msg);
224#if 1
225 {
226 auto tbus = m.get_bus();
227 sdbusplus::server::transaction::Transaction t(tbus, m);
228 sdbusplus::server::transaction::set_id(
229 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
230 }
231#endif
232
233 std::string locationCode{};
234 uint16_t nodeNumber{};
235
236 m.read(locationCode, nodeNumber);
237
238 auto o = static_cast<Manager*>(context);
239 auto r = o->getExpandedLocationCode(locationCode, nodeNumber);
240
241 auto reply = m.new_method_return();
242 reply.append(std::move(r));
243
244 reply.method_return();
245 }
246 catch (sdbusplus::internal_exception_t& e)
247 {
248 return sd_bus_error_set(error, e.name(), e.description());
249 }
250 catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
251 {
252 return sd_bus_error_set(error, e.name(), e.description());
253 }
254 catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
255 {
256 return sd_bus_error_set(error, e.name(), e.description());
257 }
258 catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
259 {
260 return sd_bus_error_set(error, e.name(), e.description());
261 }
262
263 return true;
264}
265
266namespace details
267{
268namespace Manager
269{
270static const auto _param_GetExpandedLocationCode =
271 utility::tuple_to_array(message::types::type_id<std::string, uint16_t>());
272static const auto _return_GetExpandedLocationCode =
273 utility::tuple_to_array(message::types::type_id<std::string>());
274} // namespace Manager
275} // namespace details
276
277const vtable::vtable_t Manager::_vtable[] = {
278 vtable::start(),
279
280 vtable::method("WriteKeyword", details::Manager::_param_WriteKeyword.data(),
281 details::Manager::_return_WriteKeyword.data(),
282 _callback_WriteKeyword),
283
284 vtable::method(
285 "GetFRUsByUnexpandedLocationCode",
286 details::Manager::_param_GetFRUsByUnexpandedLocationCode.data(),
287 details::Manager::_return_GetFRUsByUnexpandedLocationCode.data(),
288 _callback_GetFRUsByUnexpandedLocationCode),
289
290 vtable::method(
291 "GetFRUsByExpandedLocationCode",
292 details::Manager::_param_GetFRUsByExpandedLocationCode.data(),
293 details::Manager::_return_GetFRUsByExpandedLocationCode.data(),
294 _callback_GetFRUsByExpandedLocationCode),
295
296 vtable::method("GetExpandedLocationCode",
297 details::Manager::_param_GetExpandedLocationCode.data(),
298 details::Manager::_return_GetExpandedLocationCode.data(),
299 _callback_GetExpandedLocationCode),
300 vtable::end()};
301
302} // namespace server
303} // namespace VPD
304} // namespace ibm
305} // namespace com
306} // namespace sdbusplus