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