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