Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 3 | #include <sdbusplus/server.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace software |
| 14 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 15 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 16 | { |
| 17 | |
| 18 | using ActivationInherit = sdbusplus::server::object::object< |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::Object::server::Delete, |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 20 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Software::server::Activation>; |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 22 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 23 | sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 24 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 25 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 26 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 27 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 28 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 29 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 30 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 31 | class ItemUpdater; |
| 32 | class Activation; |
| 33 | class RedundancyPriority; |
| 34 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 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 |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 47 | * @param[in] parent - Parent object. |
| 48 | * @param[in] value - The redundancyPriority value |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 49 | */ |
| 50 | RedundancyPriority(sdbusplus::bus::bus& bus, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 51 | const std::string& path, |
| 52 | Activation& parent, |
| 53 | uint8_t value) : |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 54 | RedundancyPriorityInherit(bus, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 55 | path.c_str(), true), |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 56 | parent(parent), |
| 57 | bus(bus), |
| 58 | path(path) |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 59 | { |
| 60 | // Set Property |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 61 | priority(value); |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 70 | } |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 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; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 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; |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 95 | }; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 96 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 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) : |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 132 | }; |
| 133 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -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) : |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 144 | ActivationProgressInherit(bus, path.c_str(), true), |
| 145 | bus(bus), |
| 146 | path(path) |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 147 | { |
| 148 | progress(0); |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 149 | std::vector<std::string> interfaces({interface}); |
| 150 | bus.emit_interfaces_added(path.c_str(), interfaces); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 151 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -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 | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 165 | }; |
| 166 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -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 | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 179 | * @param[in] parent - Parent object. |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 180 | * @param[in] versionId - The software version id |
| 181 | * @param[in] extVersion - The extended version |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 182 | * @param[in] activationStatus - The status of Activation |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 183 | */ |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 184 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 185 | ItemUpdater& parent, |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 186 | std::string& versionId, |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 187 | std::string& extVersion, |
| 188 | sdbusplus::xyz::openbmc_project::Software:: |
| 189 | server::Activation::Activations activationStatus) : |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 190 | ActivationInherit(bus, path.c_str(), true), |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 191 | bus(bus), |
| 192 | path(path), |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 193 | parent(parent), |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -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)) |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 204 | { |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 205 | // Enable systemd signals |
| 206 | subscribeToSystemdSignals(); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 207 | // Set Properties. |
| 208 | extendedVersion(extVersion); |
Saqib Khan | a8ade7e | 2017-04-12 10:27:56 -0500 | [diff] [blame] | 209 | activation(activationStatus); |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 210 | // Emit deferred signal. |
| 211 | emit_object_added(); |
| 212 | } |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 213 | |
| 214 | /** @brief Overloaded Activation property setter function |
| 215 | * |
| 216 | * @param[in] value - One of Activation::Activations |
| 217 | * |
| 218 | * @return Success or exception thrown |
| 219 | */ |
| 220 | Activations activation(Activations value) override; |
| 221 | |
| 222 | /** @brief Overloaded requestedActivation property setter function |
| 223 | * |
| 224 | * @param[in] value - One of Activation::RequestedActivations |
| 225 | * |
| 226 | * @return Success or exception thrown |
| 227 | */ |
| 228 | RequestedActivations requestedActivation(RequestedActivations value) |
| 229 | override; |
| 230 | |
Saqib Khan | 2af5c49 | 2017-07-17 16:15:13 -0500 | [diff] [blame] | 231 | /** @brief Create symlinks for the current Software Version */ |
| 232 | void createSymlinks(); |
| 233 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 234 | /** @brief Check if systemd state change is relevant to this object |
| 235 | * |
| 236 | * Instance specific interface to handle the detected systemd state |
| 237 | * change |
| 238 | * |
| 239 | * @param[in] msg - Data associated with subscribed signal |
| 240 | * |
| 241 | */ |
| 242 | void unitStateChange(sdbusplus::message::message& msg); |
| 243 | |
| 244 | /** |
| 245 | * @brief subscribe to the systemd signals |
| 246 | * |
| 247 | * This object needs to capture when it's systemd targets complete |
| 248 | * so it can keep it's state updated |
| 249 | * |
| 250 | **/ |
| 251 | void subscribeToSystemdSignals(); |
| 252 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 253 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 254 | sdbusplus::bus::bus& bus; |
| 255 | |
| 256 | /** @brief Persistent DBus object path */ |
| 257 | std::string path; |
| 258 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 259 | /** @brief Parent Object. */ |
| 260 | ItemUpdater& parent; |
| 261 | |
Adriana Kobylak | bc37a4c | 2017-04-10 09:45:36 -0500 | [diff] [blame] | 262 | /** @brief Version id */ |
| 263 | std::string versionId; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 264 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 265 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 266 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 267 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 268 | /** @brief Persistent ActivationProgress dbus object */ |
| 269 | std::unique_ptr<ActivationProgress> activationProgress; |
| 270 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 271 | /** @brief Persistent RedundancyPriority dbus object */ |
| 272 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 273 | |
| 274 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 275 | sdbusplus::bus::match_t systemdSignals; |
| 276 | |
| 277 | /** @brief Tracks whether the squashfs image has been loaded as part of |
| 278 | * the activation process. **/ |
| 279 | bool squashfsLoaded = false; |
| 280 | |
| 281 | /** @brief Tracks whether the read-write volumes have been created as |
| 282 | * part of the activation process. **/ |
| 283 | bool rwVolumesCreated = false; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 284 | |
| 285 | /** @brief activation status property get function |
| 286 | * |
| 287 | * @returns Activations - The activation value |
| 288 | */ |
| 289 | using ActivationInherit::activation; |
| 290 | |
| 291 | /** @brief Deletes the d-bus object. |
| 292 | * |
| 293 | * |
| 294 | * */ |
| 295 | void delete_() override; |
| 296 | |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 297 | }; |
| 298 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 299 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 300 | } // namespace software |
| 301 | } // namespace openpower |