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 | |
| 19 | using ActivationInherit = sdbusplus::server::object::object< |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 20 | sdbusplus::xyz::openbmc_project::Object::server::Delete, |
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 |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 185 | */ |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 186 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 187 | ItemUpdater& parent, |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 188 | std::string& versionId, |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 189 | std::string& extVersion, |
| 190 | sdbusplus::xyz::openbmc_project::Software:: |
| 191 | server::Activation::Activations activationStatus) : |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 192 | ActivationInherit(bus, path.c_str(), true), |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 193 | bus(bus), |
| 194 | path(path), |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 195 | parent(parent), |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 196 | versionId(versionId), |
| 197 | systemdSignals( |
| 198 | bus, |
| 199 | sdbusRule::type::signal() + |
| 200 | sdbusRule::member("JobRemoved") + |
| 201 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 202 | sdbusRule::interface( |
| 203 | "org.freedesktop.systemd1.Manager"), |
| 204 | std::bind(std::mem_fn(&Activation::unitStateChange), |
| 205 | this, std::placeholders::_1)) |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 206 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 207 | // Enable systemd signals |
| 208 | subscribeToSystemdSignals(); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 209 | // Set Properties. |
| 210 | extendedVersion(extVersion); |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 211 | activation(activationStatus); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 212 | // Emit deferred signal. |
| 213 | emit_object_added(); |
| 214 | } |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 215 | |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 216 | /** @brief Activation property get function |
| 217 | * |
| 218 | * @returns One of Activation::Activations |
| 219 | */ |
| 220 | using ActivationInherit::activation; |
| 221 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 222 | /** @brief Overloaded Activation property setter function |
| 223 | * |
| 224 | * @param[in] value - One of Activation::Activations |
| 225 | * |
| 226 | * @return Success or exception thrown |
| 227 | */ |
| 228 | Activations activation(Activations value) override; |
| 229 | |
| 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 | 9d25b60 | 2017-06-14 14:41:43 -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 | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 258 | /** |
| 259 | * @brief unsubscribe from the systemd signals |
| 260 | * |
| 261 | * Once the activation process has completed successfully, we can |
| 262 | * safely unsubscribe from systemd signals. |
| 263 | * |
| 264 | **/ |
| 265 | void unsubscribeFromSystemdSignals(); |
| 266 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 267 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 268 | sdbusplus::bus::bus& bus; |
| 269 | |
| 270 | /** @brief Persistent DBus object path */ |
| 271 | std::string path; |
| 272 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 273 | /** @brief Parent Object. */ |
| 274 | ItemUpdater& parent; |
| 275 | |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 276 | /** @brief Version id */ |
| 277 | std::string versionId; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 278 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 279 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 280 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 281 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 282 | /** @brief Persistent ActivationProgress dbus object */ |
| 283 | std::unique_ptr<ActivationProgress> activationProgress; |
| 284 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 285 | /** @brief Persistent RedundancyPriority dbus object */ |
| 286 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 287 | |
| 288 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 289 | sdbusplus::bus::match_t systemdSignals; |
| 290 | |
| 291 | /** @brief Tracks whether the squashfs image has been loaded as part of |
| 292 | * the activation process. **/ |
| 293 | bool squashfsLoaded = false; |
| 294 | |
| 295 | /** @brief Tracks whether the read-write volumes have been created as |
| 296 | * part of the activation process. **/ |
| 297 | bool rwVolumesCreated = 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 | |
| 305 | /** @brief Deletes the d-bus object. |
| 306 | * |
| 307 | * |
| 308 | * */ |
| 309 | void delete_() override; |
| 310 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 311 | private: |
| 312 | /** @brief Member function for clarity & brevity at activation start */ |
| 313 | void startActivation(); |
| 314 | |
| 315 | /** @brief Member function for clarity & brevity at activation end */ |
| 316 | void finishActivation(); |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 317 | }; |
| 318 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 319 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 320 | } // namespace software |
| 321 | } // namespace openpower |