Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 3 | #include <sdbusplus/server.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 8 | #include "org/openbmc/Associations/server.hpp" |
Eddie James | 9440f49 | 2017-08-30 11:34:16 -0500 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace software |
| 14 | { |
| 15 | namespace updater |
| 16 | { |
| 17 | |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 18 | using AssociationList = |
| 19 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 20 | using ActivationInherit = sdbusplus::server::object::object< |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 22 | sdbusplus::org::openbmc::server::Associations>; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 23 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 24 | sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 25 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 26 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 27 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 28 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 29 | using DeleteInherit = sdbusplus::server::object::object< |
| 30 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 31 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 32 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 33 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 34 | class ItemUpdater; |
| 35 | class Activation; |
| 36 | class RedundancyPriority; |
| 37 | |
| 38 | /** @class RedundancyPriority |
| 39 | * @brief OpenBMC RedundancyPriority implementation |
| 40 | * @details A concrete implementation for |
| 41 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 42 | */ |
| 43 | class RedundancyPriority : public RedundancyPriorityInherit |
| 44 | { |
| 45 | public: |
| 46 | /** @brief Constructs RedundancyPriority. |
| 47 | * |
| 48 | * @param[in] bus - The Dbus bus object |
| 49 | * @param[in] path - The Dbus object path |
| 50 | * @param[in] parent - Parent object. |
| 51 | * @param[in] value - The redundancyPriority value |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 52 | * @param[in] freePriority - Call freePriorioty, default to true |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 53 | */ |
| 54 | RedundancyPriority(sdbusplus::bus::bus& bus, |
| 55 | const std::string& path, |
| 56 | Activation& parent, |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 57 | uint8_t value, |
| 58 | bool freePriority=true) : |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 59 | RedundancyPriorityInherit(bus, |
| 60 | path.c_str(), true), |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 61 | parent(parent), |
| 62 | bus(bus), |
| 63 | path(path) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 64 | { |
| 65 | // Set Property |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 66 | if (freePriority) |
| 67 | { |
| 68 | priority(value); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | sdbusPriority(value); |
| 73 | } |
| 74 | |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 75 | std::vector<std::string> interfaces({interface}); |
| 76 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 77 | } |
| 78 | |
| 79 | ~RedundancyPriority() |
| 80 | { |
| 81 | std::vector<std::string> interfaces({interface}); |
| 82 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 85 | /** @brief Overriden Priority property set function, calls freePriority |
| 86 | * to bump the duplicated priority values. |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 87 | * |
| 88 | * @param[in] value - uint8_t |
| 89 | * |
| 90 | * @return Success or exception thrown |
| 91 | */ |
| 92 | uint8_t priority(uint8_t value) override; |
| 93 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 94 | /** @brief Non-Overriden Priority property set function |
| 95 | * |
| 96 | * @param[in] value - uint8_t |
| 97 | * |
| 98 | * @return Success or exception thrown |
| 99 | */ |
| 100 | uint8_t sdbusPriority(uint8_t value); |
| 101 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 102 | /** @brief Priority property get function |
| 103 | * |
| 104 | * @returns uint8_t - The Priority value |
| 105 | */ |
| 106 | using RedundancyPriorityInherit::priority; |
| 107 | |
| 108 | /** @brief Parent Object. */ |
| 109 | Activation& parent; |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 110 | |
| 111 | private: |
| 112 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 113 | static constexpr auto interface = |
| 114 | "xyz.openbmc_project.Software.RedundancyPriority"; |
| 115 | sdbusplus::bus::bus& bus; |
| 116 | std::string path; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 117 | }; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 118 | |
| 119 | /** @class ActivationBlocksTransition |
| 120 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 121 | * @details A concrete implementation for |
| 122 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 123 | */ |
| 124 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 125 | { |
| 126 | public: |
| 127 | /** @brief Constructs ActivationBlocksTransition. |
| 128 | * |
| 129 | * @param[in] bus - The Dbus bus object |
| 130 | * @param[in] path - The Dbus object path |
| 131 | */ |
| 132 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 133 | const std::string& path) : |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 134 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 135 | bus(bus), |
| 136 | path(path) |
| 137 | { |
| 138 | std::vector<std::string> interfaces({interface}); |
| 139 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 140 | } |
| 141 | |
| 142 | ~ActivationBlocksTransition() |
| 143 | { |
| 144 | std::vector<std::string> interfaces({interface}); |
| 145 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 146 | } |
| 147 | |
| 148 | private: |
| 149 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 150 | static constexpr auto interface = |
| 151 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 152 | sdbusplus::bus::bus& bus; |
| 153 | std::string path; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 154 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 155 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 156 | class ActivationProgress : public ActivationProgressInherit |
| 157 | { |
| 158 | public: |
| 159 | /** @brief Constructs ActivationProgress. |
| 160 | * |
| 161 | * @param[in] bus - The Dbus bus object |
| 162 | * @param[in] path - The Dbus object path |
| 163 | */ |
| 164 | ActivationProgress(sdbusplus::bus::bus& bus, |
| 165 | const std::string& path) : |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 166 | ActivationProgressInherit(bus, path.c_str(), true), |
| 167 | bus(bus), |
| 168 | path(path) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 169 | { |
| 170 | progress(0); |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 171 | std::vector<std::string> interfaces({interface}); |
| 172 | bus.emit_interfaces_added(path.c_str(), interfaces); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 173 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 174 | |
| 175 | ~ActivationProgress() |
| 176 | { |
| 177 | std::vector<std::string> interfaces({interface}); |
| 178 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 179 | } |
| 180 | |
| 181 | private: |
| 182 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 183 | static constexpr auto interface = |
| 184 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 185 | sdbusplus::bus::bus& bus; |
| 186 | std::string path; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 187 | }; |
| 188 | |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 189 | /** @class ActivationDelete |
| 190 | * @brief OpenBMC Delete implementation. |
| 191 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 192 | * DBus API. |
| 193 | */ |
| 194 | class Delete : public DeleteInherit |
| 195 | { |
| 196 | public: |
| 197 | /** @brief Constructs Delete. |
| 198 | * |
| 199 | * @param[in] bus - The Dbus bus object |
| 200 | * @param[in] path - The Dbus object path |
| 201 | * @param[in] parent - Parent object. |
| 202 | */ |
| 203 | // Delete(sdbusplus::bus::bus& bus, const std::string& path) : |
| 204 | Delete(sdbusplus::bus::bus& bus, |
| 205 | const std::string& path, |
| 206 | Activation& parent) : |
| 207 | DeleteInherit(bus, path.c_str(), true), |
| 208 | parent(parent), |
| 209 | bus(bus), |
| 210 | path(path) |
| 211 | { |
| 212 | std::vector<std::string> interfaces({interface}); |
| 213 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 214 | } |
| 215 | |
| 216 | ~Delete() |
| 217 | { |
| 218 | std::vector<std::string> interfaces({interface}); |
| 219 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * @brief delete the d-bus object. |
| 224 | */ |
| 225 | void delete_() override; |
| 226 | |
| 227 | /** @brief Parent Object. */ |
| 228 | Activation& parent; |
| 229 | |
| 230 | private: |
| 231 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 232 | static constexpr auto interface = |
| 233 | "xyz.openbmc_project.Object.Delete"; |
| 234 | sdbusplus::bus::bus& bus; |
| 235 | std::string path; |
| 236 | }; |
| 237 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 238 | /** @class Activation |
| 239 | * @brief OpenBMC activation software management implementation. |
| 240 | * @details A concrete implementation for |
| 241 | * xyz.openbmc_project.Software.Activation DBus API. |
| 242 | */ |
| 243 | class Activation : public ActivationInherit |
| 244 | { |
| 245 | public: |
| 246 | /** @brief Constructs Activation Software Manager |
| 247 | * |
| 248 | * @param[in] bus - The Dbus bus object |
| 249 | * @param[in] path - The Dbus object path |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 250 | * @param[in] parent - Parent object. |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 251 | * @param[in] versionId - The software version id |
| 252 | * @param[in] activationStatus - The status of Activation |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 253 | * @param[in] assocs - Association objects |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 254 | */ |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 255 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 256 | ItemUpdater& parent, |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 257 | std::string& versionId, |
| 258 | sdbusplus::xyz::openbmc_project::Software:: |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 259 | server::Activation::Activations activationStatus, |
| 260 | AssociationList& assocs) : |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 261 | ActivationInherit(bus, path.c_str(), true), |
| 262 | bus(bus), |
| 263 | path(path), |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 264 | parent(parent), |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 265 | versionId(versionId), |
| 266 | systemdSignals( |
| 267 | bus, |
| 268 | sdbusRule::type::signal() + |
| 269 | sdbusRule::member("JobRemoved") + |
| 270 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 271 | sdbusRule::interface( |
| 272 | "org.freedesktop.systemd1.Manager"), |
| 273 | std::bind(std::mem_fn(&Activation::unitStateChange), |
| 274 | this, std::placeholders::_1)) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 275 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 276 | // Enable systemd signals |
| 277 | subscribeToSystemdSignals(); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 278 | // Set Properties. |
| 279 | activation(activationStatus); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 280 | associations(assocs); |
| 281 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 282 | // Emit deferred signal. |
| 283 | emit_object_added(); |
| 284 | } |
| 285 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 286 | /** @brief Overloaded Activation property setter function |
| 287 | * |
| 288 | * @param[in] value - One of Activation::Activations |
| 289 | * |
| 290 | * @return Success or exception thrown |
| 291 | */ |
| 292 | Activations activation(Activations value) override; |
| 293 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 294 | /** @brief Activation */ |
| 295 | using ActivationInherit::activation; |
| 296 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 297 | /** @brief Overloaded requestedActivation property setter function |
| 298 | * |
| 299 | * @param[in] value - One of Activation::RequestedActivations |
| 300 | * |
| 301 | * @return Success or exception thrown |
| 302 | */ |
| 303 | RequestedActivations requestedActivation(RequestedActivations value) |
| 304 | override; |
| 305 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 306 | /** @brief Check if systemd state change is relevant to this object |
| 307 | * |
| 308 | * Instance specific interface to handle the detected systemd state |
| 309 | * change |
| 310 | * |
| 311 | * @param[in] msg - Data associated with subscribed signal |
| 312 | * |
| 313 | */ |
| 314 | void unitStateChange(sdbusplus::message::message& msg); |
| 315 | |
| 316 | /** |
| 317 | * @brief subscribe to the systemd signals |
| 318 | * |
| 319 | * This object needs to capture when it's systemd targets complete |
| 320 | * so it can keep it's state updated |
| 321 | * |
| 322 | */ |
| 323 | void subscribeToSystemdSignals(); |
| 324 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 325 | /** |
| 326 | * @brief unsubscribe from the systemd signals |
| 327 | * |
| 328 | * systemd signals are only of interest during the activation process. |
| 329 | * Once complete, we want to unsubscribe to avoid unnecessary calls of |
| 330 | * unitStateChange(). |
| 331 | * |
| 332 | */ |
| 333 | void unsubscribeFromSystemdSignals(); |
| 334 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 335 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 336 | sdbusplus::bus::bus& bus; |
| 337 | |
| 338 | /** @brief Persistent DBus object path */ |
| 339 | std::string path; |
| 340 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 341 | /** @brief Parent Object. */ |
| 342 | ItemUpdater& parent; |
| 343 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 344 | /** @brief Version id */ |
| 345 | std::string versionId; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 346 | |
| 347 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 348 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 349 | |
| 350 | /** @brief Persistent RedundancyPriority dbus object */ |
| 351 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 352 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 353 | /** @brief Persistent ActivationProgress dbus object */ |
| 354 | std::unique_ptr<ActivationProgress> activationProgress; |
| 355 | |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 356 | /** @brief Persistent Delete dbus object */ |
| 357 | std::unique_ptr<Delete> deleteObject; |
| 358 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 359 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 360 | sdbusplus::bus::match_t systemdSignals; |
| 361 | |
| 362 | /** @brief Tracks whether the read-write volume has been created as |
| 363 | * part of the activation process. **/ |
| 364 | bool rwVolumeCreated = false; |
| 365 | |
| 366 | /** @brief Tracks whether the read-only volume has been created as |
| 367 | * part of the activation process. **/ |
| 368 | bool roVolumeCreated = false; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | } // namespace updater |
| 372 | } // namespace software |
| 373 | } // namespace phosphor |