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