Adriana Kobylak | 88d7cf8 | 2017-01-24 12:30:15 -0600 | [diff] [blame^] | 1 | #include <algorithm> |
| 2 | #include <sdbusplus/server.hpp> |
| 3 | #include <sdbusplus/exception.hpp> |
| 4 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 5 | |
| 6 | namespace sdbusplus |
| 7 | { |
| 8 | namespace xyz |
| 9 | { |
| 10 | namespace openbmc_project |
| 11 | { |
| 12 | namespace Logging |
| 13 | { |
| 14 | namespace server |
| 15 | { |
| 16 | |
| 17 | Entry::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 | |
| 25 | auto Entry::id() const -> |
| 26 | uint32_t |
| 27 | { |
| 28 | return _id; |
| 29 | } |
| 30 | |
| 31 | int 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 | |
| 54 | auto 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 | |
| 66 | int 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 | |
| 90 | namespace details |
| 91 | { |
| 92 | namespace Entry |
| 93 | { |
| 94 | static const auto _property_Id = |
| 95 | utility::tuple_to_array(message::types::type_id< |
| 96 | uint32_t>()); |
| 97 | } |
| 98 | } |
| 99 | auto Entry::severity() const -> |
| 100 | Level |
| 101 | { |
| 102 | return _severity; |
| 103 | } |
| 104 | |
| 105 | int 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 | |
| 128 | auto 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 | |
| 140 | int 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 | |
| 164 | namespace details |
| 165 | { |
| 166 | namespace Entry |
| 167 | { |
| 168 | static const auto _property_Severity = |
| 169 | utility::tuple_to_array(message::types::type_id< |
| 170 | std::string>()); |
| 171 | } |
| 172 | } |
| 173 | auto Entry::message() const -> |
| 174 | std::string |
| 175 | { |
| 176 | return _message; |
| 177 | } |
| 178 | |
| 179 | int 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 | |
| 202 | auto 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 | |
| 214 | int 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 | |
| 238 | namespace details |
| 239 | { |
| 240 | namespace Entry |
| 241 | { |
| 242 | static const auto _property_Message = |
| 243 | utility::tuple_to_array(message::types::type_id< |
| 244 | std::string>()); |
| 245 | } |
| 246 | } |
| 247 | auto Entry::additionalData() const -> |
| 248 | std::vector<std::string> |
| 249 | { |
| 250 | return _additionalData; |
| 251 | } |
| 252 | |
| 253 | int 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 | |
| 276 | auto 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 | |
| 288 | int 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 | |
| 312 | namespace details |
| 313 | { |
| 314 | namespace Entry |
| 315 | { |
| 316 | static const auto _property_AdditionalData = |
| 317 | utility::tuple_to_array(message::types::type_id< |
| 318 | std::vector<std::string>>()); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | |
| 323 | namespace |
| 324 | { |
| 325 | /** String to enum mapping for Entry::Level */ |
| 326 | static 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 | |
| 340 | auto 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 | |
| 357 | std::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 | |
| 366 | const 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 | |