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