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