blob: cdf91f5b15b40aee328e9df6cc7afd06eb2e01a9 [file] [log] [blame]
Adriana Kobylak88d7cf82017-01-24 12:30:15 -06001#include <algorithm>
2#include <sdbusplus/server.hpp>
3#include <sdbusplus/exception.hpp>
4#include <xyz/openbmc_project/Logging/Entry/server.hpp>
5
6namespace sdbusplus
7{
8namespace xyz
9{
10namespace openbmc_project
11{
12namespace Logging
13{
14namespace server
15{
16
17Entry::Entry(bus::bus& bus, const char* path)
18 : _xyz_openbmc_project_Logging_Entry_interface(
19 bus, path, _interface, _vtable, this)
20{
21}
22
23
24
25auto Entry::id() const ->
26 uint32_t
27{
28 return _id;
29}
30
31int Entry::_callback_get_Id(
32 sd_bus* bus, const char* path, const char* interface,
33 const char* property, sd_bus_message* reply, void* context,
34 sd_bus_error* error)
35{
36 using sdbusplus::server::binding::details::convertForMessage;
37
38 try
39 {
40 auto m = message::message(sd_bus_message_ref(reply));
41
42 auto o = static_cast<Entry*>(context);
43 m.append(convertForMessage(o->id()));
44 }
45 catch(sdbusplus::internal_exception_t& e)
46 {
47 sd_bus_error_set_const(error, e.name(), e.description());
48 return -EINVAL;
49 }
50
51 return true;
52}
53
54auto Entry::id(uint32_t value) ->
55 uint32_t
56{
57 if (_id != value)
58 {
59 _id = value;
60 _xyz_openbmc_project_Logging_Entry_interface.property_changed("Id");
61 }
62
63 return _id;
64}
65
66int Entry::_callback_set_Id(
67 sd_bus* bus, const char* path, const char* interface,
68 const char* property, sd_bus_message* value, void* context,
69 sd_bus_error* error)
70{
71 try
72 {
73 auto m = message::message(sd_bus_message_ref(value));
74
75 auto o = static_cast<Entry*>(context);
76
77 uint32_t v{};
78 m.read(v);
79 o->id(v);
80 }
81 catch(sdbusplus::internal_exception_t& e)
82 {
83 sd_bus_error_set_const(error, e.name(), e.description());
84 return -EINVAL;
85 }
86
87 return true;
88}
89
90namespace details
91{
92namespace Entry
93{
94static const auto _property_Id =
95 utility::tuple_to_array(message::types::type_id<
96 uint32_t>());
97}
98}
99auto Entry::severity() const ->
100 Level
101{
102 return _severity;
103}
104
105int Entry::_callback_get_Severity(
106 sd_bus* bus, const char* path, const char* interface,
107 const char* property, sd_bus_message* reply, void* context,
108 sd_bus_error* error)
109{
110 using sdbusplus::server::binding::details::convertForMessage;
111
112 try
113 {
114 auto m = message::message(sd_bus_message_ref(reply));
115
116 auto o = static_cast<Entry*>(context);
117 m.append(convertForMessage(o->severity()));
118 }
119 catch(sdbusplus::internal_exception_t& e)
120 {
121 sd_bus_error_set_const(error, e.name(), e.description());
122 return -EINVAL;
123 }
124
125 return true;
126}
127
128auto Entry::severity(Level value) ->
129 Level
130{
131 if (_severity != value)
132 {
133 _severity = value;
134 _xyz_openbmc_project_Logging_Entry_interface.property_changed("Severity");
135 }
136
137 return _severity;
138}
139
140int Entry::_callback_set_Severity(
141 sd_bus* bus, const char* path, const char* interface,
142 const char* property, sd_bus_message* value, void* context,
143 sd_bus_error* error)
144{
145 try
146 {
147 auto m = message::message(sd_bus_message_ref(value));
148
149 auto o = static_cast<Entry*>(context);
150
151 std::string v{};
152 m.read(v);
153 o->severity(convertLevelFromString(v));
154 }
155 catch(sdbusplus::internal_exception_t& e)
156 {
157 sd_bus_error_set_const(error, e.name(), e.description());
158 return -EINVAL;
159 }
160
161 return true;
162}
163
164namespace details
165{
166namespace Entry
167{
168static const auto _property_Severity =
169 utility::tuple_to_array(message::types::type_id<
170 std::string>());
171}
172}
173auto Entry::message() const ->
174 std::string
175{
176 return _message;
177}
178
179int Entry::_callback_get_Message(
180 sd_bus* bus, const char* path, const char* interface,
181 const char* property, sd_bus_message* reply, void* context,
182 sd_bus_error* error)
183{
184 using sdbusplus::server::binding::details::convertForMessage;
185
186 try
187 {
188 auto m = message::message(sd_bus_message_ref(reply));
189
190 auto o = static_cast<Entry*>(context);
191 m.append(convertForMessage(o->message()));
192 }
193 catch(sdbusplus::internal_exception_t& e)
194 {
195 sd_bus_error_set_const(error, e.name(), e.description());
196 return -EINVAL;
197 }
198
199 return true;
200}
201
202auto Entry::message(std::string value) ->
203 std::string
204{
205 if (_message != value)
206 {
207 _message = value;
208 _xyz_openbmc_project_Logging_Entry_interface.property_changed("Message");
209 }
210
211 return _message;
212}
213
214int Entry::_callback_set_Message(
215 sd_bus* bus, const char* path, const char* interface,
216 const char* property, sd_bus_message* value, void* context,
217 sd_bus_error* error)
218{
219 try
220 {
221 auto m = message::message(sd_bus_message_ref(value));
222
223 auto o = static_cast<Entry*>(context);
224
225 std::string v{};
226 m.read(v);
227 o->message(v);
228 }
229 catch(sdbusplus::internal_exception_t& e)
230 {
231 sd_bus_error_set_const(error, e.name(), e.description());
232 return -EINVAL;
233 }
234
235 return true;
236}
237
238namespace details
239{
240namespace Entry
241{
242static const auto _property_Message =
243 utility::tuple_to_array(message::types::type_id<
244 std::string>());
245}
246}
247auto Entry::additionalData() const ->
248 std::vector<std::string>
249{
250 return _additionalData;
251}
252
253int Entry::_callback_get_AdditionalData(
254 sd_bus* bus, const char* path, const char* interface,
255 const char* property, sd_bus_message* reply, void* context,
256 sd_bus_error* error)
257{
258 using sdbusplus::server::binding::details::convertForMessage;
259
260 try
261 {
262 auto m = message::message(sd_bus_message_ref(reply));
263
264 auto o = static_cast<Entry*>(context);
265 m.append(convertForMessage(o->additionalData()));
266 }
267 catch(sdbusplus::internal_exception_t& e)
268 {
269 sd_bus_error_set_const(error, e.name(), e.description());
270 return -EINVAL;
271 }
272
273 return true;
274}
275
276auto Entry::additionalData(std::vector<std::string> value) ->
277 std::vector<std::string>
278{
279 if (_additionalData != value)
280 {
281 _additionalData = value;
282 _xyz_openbmc_project_Logging_Entry_interface.property_changed("AdditionalData");
283 }
284
285 return _additionalData;
286}
287
288int Entry::_callback_set_AdditionalData(
289 sd_bus* bus, const char* path, const char* interface,
290 const char* property, sd_bus_message* value, void* context,
291 sd_bus_error* error)
292{
293 try
294 {
295 auto m = message::message(sd_bus_message_ref(value));
296
297 auto o = static_cast<Entry*>(context);
298
299 std::vector<std::string> v{};
300 m.read(v);
301 o->additionalData(v);
302 }
303 catch(sdbusplus::internal_exception_t& e)
304 {
305 sd_bus_error_set_const(error, e.name(), e.description());
306 return -EINVAL;
307 }
308
309 return true;
310}
311
312namespace details
313{
314namespace Entry
315{
316static const auto _property_AdditionalData =
317 utility::tuple_to_array(message::types::type_id<
318 std::vector<std::string>>());
319}
320}
321
322
323namespace
324{
325/** String to enum mapping for Entry::Level */
326static const std::tuple<const char*, Entry::Level> mappingEntryLevel[] =
327 {
328 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Emergency", Entry::Level::Emergency ),
329 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Alert", Entry::Level::Alert ),
330 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Critical", Entry::Level::Critical ),
331 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Error", Entry::Level::Error ),
332 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Warning", Entry::Level::Warning ),
333 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Notice", Entry::Level::Notice ),
334 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Informational", Entry::Level::Informational ),
335 std::make_tuple( "xyz.openbmc_project.Logging.Entry.Level.Debug", Entry::Level::Debug ),
336 };
337
338} // anonymous namespace
339
340auto Entry::convertLevelFromString(std::string& s) ->
341 Level
342{
343 auto i = std::find_if(
344 std::begin(mappingEntryLevel),
345 std::end(mappingEntryLevel),
346 [&s](auto& e){ return 0 == strcmp(s.c_str(), std::get<0>(e)); } );
347 if (std::end(mappingEntryLevel) == i)
348 {
349 throw sdbusplus::exception::InvalidEnumString();
350 }
351 else
352 {
353 return std::get<1>(*i);
354 }
355}
356
357std::string convertForMessage(Entry::Level v)
358{
359 auto i = std::find_if(
360 std::begin(mappingEntryLevel),
361 std::end(mappingEntryLevel),
362 [v](auto& e){ return v == std::get<1>(e); });
363 return std::get<0>(*i);
364}
365
366const vtable::vtable_t Entry::_vtable[] = {
367 vtable::start(),
368 vtable::property("Id",
369 details::Entry::_property_Id
370 .data(),
371 _callback_get_Id,
372 _callback_set_Id,
373 vtable::property_::emits_change),
374 vtable::property("Severity",
375 details::Entry::_property_Severity
376 .data(),
377 _callback_get_Severity,
378 _callback_set_Severity,
379 vtable::property_::emits_change),
380 vtable::property("Message",
381 details::Entry::_property_Message
382 .data(),
383 _callback_get_Message,
384 _callback_set_Message,
385 vtable::property_::emits_change),
386 vtable::property("AdditionalData",
387 details::Entry::_property_AdditionalData
388 .data(),
389 _callback_get_AdditionalData,
390 _callback_set_AdditionalData,
391 vtable::property_::emits_change),
392 vtable::end()
393};
394
395} // namespace server
396} // namespace Logging
397} // namespace openbmc_project
398} // namespace xyz
399} // namespace sdbusplus
400