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