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 = |
| 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< |
| 25 | sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 26 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 27 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 28 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 29 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 30 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 31 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 32 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 33 | class ItemUpdater; |
| 34 | class Activation; |
| 35 | class RedundancyPriority; |
| 36 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 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 |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 49 | * @param[in] parent - Parent object. |
| 50 | * @param[in] value - The redundancyPriority value |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 51 | */ |
| 52 | RedundancyPriority(sdbusplus::bus::bus& bus, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 53 | const std::string& path, |
| 54 | Activation& parent, |
| 55 | uint8_t value) : |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 56 | RedundancyPriorityInherit(bus, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 57 | path.c_str(), true), |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 58 | parent(parent), |
| 59 | bus(bus), |
| 60 | path(path) |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 61 | { |
| 62 | // Set Property |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 63 | priority(value); |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 72 | } |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 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; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 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; |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 97 | }; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 98 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 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) : |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 134 | }; |
| 135 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -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) : |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 146 | ActivationProgressInherit(bus, path.c_str(), true), |
| 147 | bus(bus), |
| 148 | path(path) |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 149 | { |
| 150 | progress(0); |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 151 | std::vector<std::string> interfaces({interface}); |
| 152 | bus.emit_interfaces_added(path.c_str(), interfaces); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 153 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 167 | }; |
| 168 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 169 | /** @class Activation |
| 170 | * @brief OpenBMC activation software management implementation. |
| 171 | * @details A concrete implementation for |
| 172 | * xyz.openbmc_project.Software.Activation DBus API. |
| 173 | */ |
| 174 | class Activation : public ActivationInherit |
| 175 | { |
| 176 | public: |
| 177 | /** @brief Constructs Activation Software Manager |
| 178 | * |
| 179 | * @param[in] bus - The Dbus bus object |
| 180 | * @param[in] path - The Dbus object path |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 181 | * @param[in] parent - Parent object. |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 182 | * @param[in] versionId - The software version id |
| 183 | * @param[in] extVersion - The extended version |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 184 | * @param[in] activationStatus - The status of Activation |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 185 | * @param[in] assocs - Association objects |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 186 | */ |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 187 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 188 | ItemUpdater& parent, |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 189 | std::string& versionId, |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 190 | std::string& extVersion, |
| 191 | sdbusplus::xyz::openbmc_project::Software:: |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 192 | server::Activation::Activations activationStatus, |
| 193 | AssociationList& assocs) : |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 194 | ActivationInherit(bus, path.c_str(), true), |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 195 | bus(bus), |
| 196 | path(path), |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 197 | parent(parent), |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -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), |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 207 | this, std::placeholders::_1)) |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 208 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 209 | // Enable systemd signals |
| 210 | subscribeToSystemdSignals(); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 211 | // Set Properties. |
| 212 | extendedVersion(extVersion); |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 213 | activation(activationStatus); |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 214 | associations(assocs); |
| 215 | |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 216 | // Emit deferred signal. |
| 217 | emit_object_added(); |
| 218 | } |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 219 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 220 | /** @brief Activation property get function |
| 221 | * |
| 222 | * @returns One of Activation::Activations |
| 223 | */ |
| 224 | using ActivationInherit::activation; |
| 225 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 226 | /** @brief Overloaded Activation property setter function |
| 227 | * |
| 228 | * @param[in] value - One of Activation::Activations |
| 229 | * |
| 230 | * @return Success or exception thrown |
| 231 | */ |
| 232 | Activations activation(Activations value) override; |
| 233 | |
| 234 | /** @brief Overloaded requestedActivation property setter function |
| 235 | * |
| 236 | * @param[in] value - One of Activation::RequestedActivations |
| 237 | * |
| 238 | * @return Success or exception thrown |
| 239 | */ |
| 240 | RequestedActivations requestedActivation(RequestedActivations value) |
| 241 | override; |
| 242 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 243 | /** @brief Check if systemd state change is relevant to this object |
| 244 | * |
| 245 | * Instance specific interface to handle the detected systemd state |
| 246 | * change |
| 247 | * |
| 248 | * @param[in] msg - Data associated with subscribed signal |
| 249 | * |
| 250 | */ |
| 251 | void unitStateChange(sdbusplus::message::message& msg); |
| 252 | |
| 253 | /** |
| 254 | * @brief subscribe to the systemd signals |
| 255 | * |
| 256 | * This object needs to capture when it's systemd targets complete |
| 257 | * so it can keep it's state updated |
| 258 | * |
| 259 | **/ |
| 260 | void subscribeToSystemdSignals(); |
| 261 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 262 | /** |
| 263 | * @brief unsubscribe from the systemd signals |
| 264 | * |
| 265 | * Once the activation process has completed successfully, we can |
| 266 | * safely unsubscribe from systemd signals. |
| 267 | * |
| 268 | **/ |
| 269 | void unsubscribeFromSystemdSignals(); |
| 270 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 271 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 272 | sdbusplus::bus::bus& bus; |
| 273 | |
| 274 | /** @brief Persistent DBus object path */ |
| 275 | std::string path; |
| 276 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 277 | /** @brief Parent Object. */ |
| 278 | ItemUpdater& parent; |
| 279 | |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 280 | /** @brief Version id */ |
| 281 | std::string versionId; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 282 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 283 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 284 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 285 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 286 | /** @brief Persistent ActivationProgress dbus object */ |
| 287 | std::unique_ptr<ActivationProgress> activationProgress; |
| 288 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 289 | /** @brief Persistent RedundancyPriority dbus object */ |
| 290 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 291 | |
| 292 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 293 | sdbusplus::bus::match_t systemdSignals; |
| 294 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 295 | /** @brief Tracks whether the read-only & read-write volumes have been |
| 296 | *created as part of the activation process. **/ |
| 297 | bool ubiVolumesCreated = false; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 298 | |
| 299 | /** @brief activation status property get function |
| 300 | * |
| 301 | * @returns Activations - The activation value |
| 302 | */ |
| 303 | using ActivationInherit::activation; |
| 304 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 305 | private: |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * @brief Deletes the version from Image Manager and the |
| 309 | * untar image from image upload dir. |
| 310 | */ |
| 311 | void deleteImageManagerObject(); |
| 312 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 313 | /** @brief Member function for clarity & brevity at activation start */ |
| 314 | void startActivation(); |
| 315 | |
| 316 | /** @brief Member function for clarity & brevity at activation end */ |
| 317 | void finishActivation(); |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 318 | }; |
| 319 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 320 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 321 | } // namespace software |
| 322 | } // namespace openpower |