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 | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 167 | // TODO: openbmc/openbmc#2086 - Add removeActiveAssociation() after |
| 168 | // Delete() is implemented |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -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 | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 181 | * @param[in] parent - Parent object. |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 182 | * @param[in] versionId - The software version id |
| 183 | * @param[in] activationStatus - The status of Activation |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 184 | * @param[in] assocs - Association objects |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 185 | */ |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 186 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 187 | ItemUpdater& parent, |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 188 | std::string& versionId, |
| 189 | sdbusplus::xyz::openbmc_project::Software:: |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 190 | server::Activation::Activations activationStatus, |
| 191 | AssociationList& assocs) : |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 192 | ActivationInherit(bus, path.c_str(), true), |
| 193 | bus(bus), |
| 194 | path(path), |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 195 | parent(parent), |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -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)) |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 206 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 207 | // Enable systemd signals |
| 208 | subscribeToSystemdSignals(); |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 209 | // Set Properties. |
| 210 | activation(activationStatus); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 211 | associations(assocs); |
| 212 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 213 | // Emit deferred signal. |
| 214 | emit_object_added(); |
| 215 | } |
| 216 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 217 | /** @brief Overloaded Activation property setter function |
| 218 | * |
| 219 | * @param[in] value - One of Activation::Activations |
| 220 | * |
| 221 | * @return Success or exception thrown |
| 222 | */ |
| 223 | Activations activation(Activations value) override; |
| 224 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 225 | /** @brief Activation */ |
| 226 | using ActivationInherit::activation; |
| 227 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 228 | /** @brief Overloaded requestedActivation property setter function |
| 229 | * |
| 230 | * @param[in] value - One of Activation::RequestedActivations |
| 231 | * |
| 232 | * @return Success or exception thrown |
| 233 | */ |
| 234 | RequestedActivations requestedActivation(RequestedActivations value) |
| 235 | override; |
| 236 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 237 | /** @brief Check if systemd state change is relevant to this object |
| 238 | * |
| 239 | * Instance specific interface to handle the detected systemd state |
| 240 | * change |
| 241 | * |
| 242 | * @param[in] msg - Data associated with subscribed signal |
| 243 | * |
| 244 | */ |
| 245 | void unitStateChange(sdbusplus::message::message& msg); |
| 246 | |
| 247 | /** |
| 248 | * @brief subscribe to the systemd signals |
| 249 | * |
| 250 | * This object needs to capture when it's systemd targets complete |
| 251 | * so it can keep it's state updated |
| 252 | * |
| 253 | */ |
| 254 | void subscribeToSystemdSignals(); |
| 255 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 256 | /** |
| 257 | * @brief unsubscribe from the systemd signals |
| 258 | * |
| 259 | * systemd signals are only of interest during the activation process. |
| 260 | * Once complete, we want to unsubscribe to avoid unnecessary calls of |
| 261 | * unitStateChange(). |
| 262 | * |
| 263 | */ |
| 264 | void unsubscribeFromSystemdSignals(); |
| 265 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 266 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 267 | sdbusplus::bus::bus& bus; |
| 268 | |
| 269 | /** @brief Persistent DBus object path */ |
| 270 | std::string path; |
| 271 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 272 | /** @brief Parent Object. */ |
| 273 | ItemUpdater& parent; |
| 274 | |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 275 | /** @brief Version id */ |
| 276 | std::string versionId; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 277 | |
| 278 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 279 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 280 | |
| 281 | /** @brief Persistent RedundancyPriority dbus object */ |
| 282 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 283 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 284 | /** @brief Persistent ActivationProgress dbus object */ |
| 285 | std::unique_ptr<ActivationProgress> activationProgress; |
| 286 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 287 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 288 | sdbusplus::bus::match_t systemdSignals; |
| 289 | |
| 290 | /** @brief Tracks whether the read-write volume has been created as |
| 291 | * part of the activation process. **/ |
| 292 | bool rwVolumeCreated = false; |
| 293 | |
| 294 | /** @brief Tracks whether the read-only volume has been created as |
| 295 | * part of the activation process. **/ |
| 296 | bool roVolumeCreated = false; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | } // namespace updater |
| 300 | } // namespace software |
| 301 | } // namespace phosphor |