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 | |
| 17 | using ActivationInherit = sdbusplus::server::object::object< |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 18 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
| 19 | sdbusplus::org::openbmc::server::Associations>; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 20 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 21 | sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 22 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 23 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 24 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 25 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 26 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 27 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 28 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 29 | class ItemUpdater; |
| 30 | class Activation; |
| 31 | class RedundancyPriority; |
| 32 | |
| 33 | /** @class RedundancyPriority |
| 34 | * @brief OpenBMC RedundancyPriority implementation |
| 35 | * @details A concrete implementation for |
| 36 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 37 | */ |
| 38 | class RedundancyPriority : public RedundancyPriorityInherit |
| 39 | { |
| 40 | public: |
| 41 | /** @brief Constructs RedundancyPriority. |
| 42 | * |
| 43 | * @param[in] bus - The Dbus bus object |
| 44 | * @param[in] path - The Dbus object path |
| 45 | * @param[in] parent - Parent object. |
| 46 | * @param[in] value - The redundancyPriority value |
| 47 | */ |
| 48 | RedundancyPriority(sdbusplus::bus::bus& bus, |
| 49 | const std::string& path, |
| 50 | Activation& parent, |
| 51 | uint8_t value) : |
| 52 | RedundancyPriorityInherit(bus, |
| 53 | path.c_str(), true), |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 54 | parent(parent), |
| 55 | bus(bus), |
| 56 | path(path) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 57 | { |
| 58 | // Set Property |
| 59 | priority(value); |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 60 | std::vector<std::string> interfaces({interface}); |
| 61 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 62 | } |
| 63 | |
| 64 | ~RedundancyPriority() |
| 65 | { |
| 66 | std::vector<std::string> interfaces({interface}); |
| 67 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 68 | } |
| 69 | |
| 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; |
| 77 | |
| 78 | /** @brief Priority property get function |
| 79 | * |
| 80 | * @returns uint8_t - The Priority value |
| 81 | */ |
| 82 | using RedundancyPriorityInherit::priority; |
| 83 | |
| 84 | /** @brief Parent Object. */ |
| 85 | Activation& parent; |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 86 | |
| 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 | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 93 | }; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 94 | |
| 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 | { |
| 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) : |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 110 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 111 | bus(bus), |
| 112 | path(path) |
| 113 | { |
| 114 | std::vector<std::string> interfaces({interface}); |
| 115 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 116 | } |
| 117 | |
| 118 | ~ActivationBlocksTransition() |
| 119 | { |
| 120 | std::vector<std::string> interfaces({interface}); |
| 121 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 122 | } |
| 123 | |
| 124 | private: |
| 125 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 126 | static constexpr auto interface = |
| 127 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 128 | sdbusplus::bus::bus& bus; |
| 129 | std::string path; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 130 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 131 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 132 | class ActivationProgress : public ActivationProgressInherit |
| 133 | { |
| 134 | public: |
| 135 | /** @brief Constructs ActivationProgress. |
| 136 | * |
| 137 | * @param[in] bus - The Dbus bus object |
| 138 | * @param[in] path - The Dbus object path |
| 139 | */ |
| 140 | ActivationProgress(sdbusplus::bus::bus& bus, |
| 141 | const std::string& path) : |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 142 | ActivationProgressInherit(bus, path.c_str(), true), |
| 143 | bus(bus), |
| 144 | path(path) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 145 | { |
| 146 | progress(0); |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 147 | std::vector<std::string> interfaces({interface}); |
| 148 | bus.emit_interfaces_added(path.c_str(), interfaces); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 149 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 150 | |
| 151 | ~ActivationProgress() |
| 152 | { |
| 153 | std::vector<std::string> interfaces({interface}); |
| 154 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 159 | static constexpr auto interface = |
| 160 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 161 | sdbusplus::bus::bus& bus; |
| 162 | std::string path; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 163 | }; |
| 164 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 165 | /** @class Activation |
| 166 | * @brief OpenBMC activation software management implementation. |
| 167 | * @details A concrete implementation for |
| 168 | * xyz.openbmc_project.Software.Activation DBus API. |
| 169 | */ |
| 170 | class Activation : public ActivationInherit |
| 171 | { |
| 172 | public: |
| 173 | /** @brief Constructs Activation Software Manager |
| 174 | * |
| 175 | * @param[in] bus - The Dbus bus object |
| 176 | * @param[in] path - The Dbus object path |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 177 | * @param[in] parent - Parent object. |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 178 | * @param[in] versionId - The software version id |
| 179 | * @param[in] activationStatus - The status of Activation |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 180 | */ |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 181 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 182 | ItemUpdater& parent, |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 183 | std::string& versionId, |
| 184 | sdbusplus::xyz::openbmc_project::Software:: |
| 185 | server::Activation::Activations activationStatus) : |
| 186 | ActivationInherit(bus, path.c_str(), true), |
| 187 | bus(bus), |
| 188 | path(path), |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 189 | parent(parent), |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 190 | versionId(versionId), |
| 191 | systemdSignals( |
| 192 | bus, |
| 193 | sdbusRule::type::signal() + |
| 194 | sdbusRule::member("JobRemoved") + |
| 195 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 196 | sdbusRule::interface( |
| 197 | "org.freedesktop.systemd1.Manager"), |
| 198 | std::bind(std::mem_fn(&Activation::unitStateChange), |
| 199 | this, std::placeholders::_1)) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 200 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 201 | // Enable systemd signals |
| 202 | subscribeToSystemdSignals(); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 203 | // Set Properties. |
| 204 | activation(activationStatus); |
| 205 | // Emit deferred signal. |
| 206 | emit_object_added(); |
| 207 | } |
| 208 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 209 | /** @brief Overloaded Activation property setter function |
| 210 | * |
| 211 | * @param[in] value - One of Activation::Activations |
| 212 | * |
| 213 | * @return Success or exception thrown |
| 214 | */ |
| 215 | Activations activation(Activations value) override; |
| 216 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 217 | /** @brief Activation */ |
| 218 | using ActivationInherit::activation; |
| 219 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [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 requestedActivation(RequestedActivations value) |
| 227 | override; |
| 228 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [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); |
| 238 | |
| 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(); |
| 247 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 248 | /** |
| 249 | * @brief unsubscribe from the systemd signals |
| 250 | * |
| 251 | * systemd signals are only of interest during the activation process. |
| 252 | * Once complete, we want to unsubscribe to avoid unnecessary calls of |
| 253 | * unitStateChange(). |
| 254 | * |
| 255 | */ |
| 256 | void unsubscribeFromSystemdSignals(); |
| 257 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 258 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 259 | sdbusplus::bus::bus& bus; |
| 260 | |
| 261 | /** @brief Persistent DBus object path */ |
| 262 | std::string path; |
| 263 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 264 | /** @brief Parent Object. */ |
| 265 | ItemUpdater& parent; |
| 266 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 267 | /** @brief Version id */ |
| 268 | std::string versionId; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 269 | |
| 270 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 271 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 272 | |
| 273 | /** @brief Persistent RedundancyPriority dbus object */ |
| 274 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 275 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 276 | /** @brief Persistent ActivationProgress dbus object */ |
| 277 | std::unique_ptr<ActivationProgress> activationProgress; |
| 278 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 279 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 280 | sdbusplus::bus::match_t systemdSignals; |
| 281 | |
| 282 | /** @brief Tracks whether the read-write volume has been created as |
| 283 | * part of the activation process. **/ |
| 284 | bool rwVolumeCreated = false; |
| 285 | |
| 286 | /** @brief Tracks whether the read-only volume has been created as |
| 287 | * part of the activation process. **/ |
| 288 | bool roVolumeCreated = false; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | } // namespace updater |
| 292 | } // namespace software |
| 293 | } // namespace phosphor |