Gunnar Mills | ed92dfa | 2017-01-27 10:41:49 -0600 | [diff] [blame] | 1 | #include <algorithm> |
| 2 | #include <sdbusplus/server.hpp> |
| 3 | #include <sdbusplus/exception.hpp> |
| 4 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
| 5 | |
| 6 | namespace sdbusplus |
| 7 | { |
| 8 | namespace xyz |
| 9 | { |
| 10 | namespace openbmc_project |
| 11 | { |
| 12 | namespace Software |
| 13 | { |
| 14 | namespace server |
| 15 | { |
| 16 | |
| 17 | Activation::Activation(bus::bus& bus, const char* path) |
| 18 | : _xyz_openbmc_project_Software_Activation_interface( |
| 19 | bus, path, _interface, _vtable, this) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | |
| 24 | |
| 25 | auto Activation::activation() const -> |
| 26 | Activations |
| 27 | { |
| 28 | return _activation; |
| 29 | } |
| 30 | |
| 31 | int Activation::_callback_get_Activation( |
| 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<Activation*>(context); |
| 43 | m.append(convertForMessage(o->activation())); |
| 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 Activation::activation(Activations value) -> |
| 55 | Activations |
| 56 | { |
| 57 | if (_activation != value) |
| 58 | { |
| 59 | _activation = value; |
| 60 | _xyz_openbmc_project_Software_Activation_interface.property_changed("Activation"); |
| 61 | } |
| 62 | |
| 63 | return _activation; |
| 64 | } |
| 65 | |
| 66 | int Activation::_callback_set_Activation( |
| 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<Activation*>(context); |
| 76 | |
| 77 | std::string v{}; |
| 78 | m.read(v); |
| 79 | o->activation(convertActivationsFromString(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 Activation |
| 93 | { |
| 94 | static const auto _property_Activation = |
| 95 | utility::tuple_to_array(message::types::type_id< |
| 96 | std::string>()); |
| 97 | } |
| 98 | } |
| 99 | auto Activation::requestedActivation() const -> |
| 100 | RequestedActivations |
| 101 | { |
| 102 | return _requestedActivation; |
| 103 | } |
| 104 | |
| 105 | int Activation::_callback_get_RequestedActivation( |
| 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<Activation*>(context); |
| 117 | m.append(convertForMessage(o->requestedActivation())); |
| 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 Activation::requestedActivation(RequestedActivations value) -> |
| 129 | RequestedActivations |
| 130 | { |
| 131 | if (_requestedActivation != value) |
| 132 | { |
| 133 | _requestedActivation = value; |
| 134 | _xyz_openbmc_project_Software_Activation_interface.property_changed("RequestedActivation"); |
| 135 | } |
| 136 | |
| 137 | return _requestedActivation; |
| 138 | } |
| 139 | |
| 140 | int Activation::_callback_set_RequestedActivation( |
| 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<Activation*>(context); |
| 150 | |
| 151 | std::string v{}; |
| 152 | m.read(v); |
| 153 | o->requestedActivation(convertRequestedActivationsFromString(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 Activation |
| 167 | { |
| 168 | static const auto _property_RequestedActivation = |
| 169 | utility::tuple_to_array(message::types::type_id< |
| 170 | std::string>()); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
| 175 | namespace |
| 176 | { |
| 177 | /** String to enum mapping for Activation::Activations */ |
| 178 | static const std::tuple<const char*, Activation::Activations> mappingActivationActivations[] = |
| 179 | { |
| 180 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.NotReady", Activation::Activations::NotReady ), |
| 181 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.Invalid", Activation::Activations::Invalid ), |
| 182 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.Ready", Activation::Activations::Ready ), |
| 183 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.Activating", Activation::Activations::Activating ), |
| 184 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.Active", Activation::Activations::Active ), |
| 185 | std::make_tuple( "xyz.openbmc_project.Software.Activation.Activations.Failed", Activation::Activations::Failed ), |
| 186 | }; |
| 187 | |
| 188 | } // anonymous namespace |
| 189 | |
| 190 | auto Activation::convertActivationsFromString(std::string& s) -> |
| 191 | Activations |
| 192 | { |
| 193 | auto i = std::find_if( |
| 194 | std::begin(mappingActivationActivations), |
| 195 | std::end(mappingActivationActivations), |
| 196 | [&s](auto& e){ return 0 == strcmp(s.c_str(), std::get<0>(e)); } ); |
| 197 | if (std::end(mappingActivationActivations) == i) |
| 198 | { |
| 199 | throw sdbusplus::exception::InvalidEnumString(); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | return std::get<1>(*i); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | std::string convertForMessage(Activation::Activations v) |
| 208 | { |
| 209 | auto i = std::find_if( |
| 210 | std::begin(mappingActivationActivations), |
| 211 | std::end(mappingActivationActivations), |
| 212 | [v](auto& e){ return v == std::get<1>(e); }); |
| 213 | return std::get<0>(*i); |
| 214 | } |
| 215 | |
| 216 | namespace |
| 217 | { |
| 218 | /** String to enum mapping for Activation::RequestedActivations */ |
| 219 | static const std::tuple<const char*, Activation::RequestedActivations> mappingActivationRequestedActivations[] = |
| 220 | { |
| 221 | std::make_tuple( "xyz.openbmc_project.Software.Activation.RequestedActivations.None", Activation::RequestedActivations::None ), |
| 222 | std::make_tuple( "xyz.openbmc_project.Software.Activation.RequestedActivations.Active", Activation::RequestedActivations::Active ), |
| 223 | }; |
| 224 | |
| 225 | } // anonymous namespace |
| 226 | |
| 227 | auto Activation::convertRequestedActivationsFromString(std::string& s) -> |
| 228 | RequestedActivations |
| 229 | { |
| 230 | auto i = std::find_if( |
| 231 | std::begin(mappingActivationRequestedActivations), |
| 232 | std::end(mappingActivationRequestedActivations), |
| 233 | [&s](auto& e){ return 0 == strcmp(s.c_str(), std::get<0>(e)); } ); |
| 234 | if (std::end(mappingActivationRequestedActivations) == i) |
| 235 | { |
| 236 | throw sdbusplus::exception::InvalidEnumString(); |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | return std::get<1>(*i); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | std::string convertForMessage(Activation::RequestedActivations v) |
| 245 | { |
| 246 | auto i = std::find_if( |
| 247 | std::begin(mappingActivationRequestedActivations), |
| 248 | std::end(mappingActivationRequestedActivations), |
| 249 | [v](auto& e){ return v == std::get<1>(e); }); |
| 250 | return std::get<0>(*i); |
| 251 | } |
| 252 | |
| 253 | const vtable::vtable_t Activation::_vtable[] = { |
| 254 | vtable::start(), |
| 255 | vtable::property("Activation", |
| 256 | details::Activation::_property_Activation |
| 257 | .data(), |
| 258 | _callback_get_Activation, |
| 259 | _callback_set_Activation, |
| 260 | vtable::property_::emits_change), |
| 261 | vtable::property("RequestedActivation", |
| 262 | details::Activation::_property_RequestedActivation |
| 263 | .data(), |
| 264 | _callback_get_RequestedActivation, |
| 265 | _callback_set_RequestedActivation, |
| 266 | vtable::property_::emits_change), |
| 267 | vtable::end() |
| 268 | }; |
| 269 | |
| 270 | } // namespace server |
| 271 | } // namespace Software |
| 272 | } // namespace openbmc_project |
| 273 | } // namespace xyz |
| 274 | } // namespace sdbusplus |
| 275 | |