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