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