Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 5 | #include "types.hpp" |
| 6 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 7 | #include <sdbusplus/server.hpp> |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 8 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame^] | 11 | #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> |
| 13 | |
| 14 | namespace phosphor |
| 15 | { |
| 16 | namespace software |
| 17 | { |
| 18 | namespace updater |
| 19 | { |
| 20 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 21 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 22 | |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 23 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 24 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 25 | ActivationBlocksTransition>; |
| 26 | |
| 27 | /** @class ActivationBlocksTransition |
| 28 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 29 | * @details A concrete implementation for |
| 30 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 31 | */ |
| 32 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 33 | { |
| 34 | public: |
| 35 | /** @brief Constructs ActivationBlocksTransition. |
| 36 | * |
| 37 | * @param[in] bus - The Dbus bus object |
| 38 | * @param[in] path - The Dbus object path |
| 39 | */ |
| 40 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 41 | const std::string& path) : |
| 42 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 43 | bus(bus), path(path) |
| 44 | { |
| 45 | std::vector<std::string> interfaces({interface}); |
| 46 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 47 | } |
| 48 | |
| 49 | ~ActivationBlocksTransition() |
| 50 | { |
| 51 | std::vector<std::string> interfaces({interface}); |
| 52 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 57 | static constexpr auto interface = |
| 58 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 59 | sdbusplus::bus::bus& bus; |
| 60 | std::string path; |
| 61 | }; |
| 62 | |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame^] | 63 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 64 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
| 65 | |
| 66 | class ActivationProgress : public ActivationProgressInherit |
| 67 | { |
| 68 | public: |
| 69 | /** @brief Constructs ActivationProgress. |
| 70 | * |
| 71 | * @param[in] bus - The Dbus bus object |
| 72 | * @param[in] path - The Dbus object path |
| 73 | */ |
| 74 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 75 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 76 | { |
| 77 | progress(0); |
| 78 | std::vector<std::string> interfaces({interface}); |
| 79 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 80 | } |
| 81 | |
| 82 | ~ActivationProgress() |
| 83 | { |
| 84 | std::vector<std::string> interfaces({interface}); |
| 85 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 90 | static constexpr auto interface = |
| 91 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 92 | sdbusplus::bus::bus& bus; |
| 93 | std::string path; |
| 94 | }; |
| 95 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 96 | using ActivationInherit = sdbusplus::server::object::object< |
| 97 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 98 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
| 99 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 100 | |
| 101 | /** @class Activation |
| 102 | * @brief OpenBMC activation software management implementation. |
| 103 | * @details A concrete implementation for |
| 104 | * xyz.openbmc_project.Software.Activation DBus API. |
| 105 | */ |
| 106 | class Activation : public ActivationInherit |
| 107 | { |
| 108 | public: |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 109 | using Status = Activations; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 110 | /** @brief Constructs Activation Software Manager |
| 111 | * |
| 112 | * @param[in] bus - The Dbus bus object |
| 113 | * @param[in] path - The Dbus object path |
| 114 | * @param[in] versionId - The software version id |
| 115 | * @param[in] extVersion - The extended version |
| 116 | * @param[in] activationStatus - The status of Activation |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 117 | * @param[in] assocs - Association objects |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 118 | */ |
| 119 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 120 | const std::string& versionId, const std::string& extVersion, |
| 121 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 122 | Activations activationStatus, |
| 123 | const AssociationList& assocs) : |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 124 | ActivationInherit(bus, path.c_str(), true), |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 125 | versionId(versionId), bus(bus), path(path), |
| 126 | systemdSignals( |
| 127 | bus, |
| 128 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 129 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 130 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 131 | std::bind(&Activation::unitStateChange, this, |
| 132 | std::placeholders::_1)) |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 133 | { |
| 134 | // Set Properties. |
| 135 | extendedVersion(extVersion); |
| 136 | activation(activationStatus); |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 137 | associations(assocs); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 138 | |
| 139 | // Emit deferred signal. |
| 140 | emit_object_added(); |
| 141 | } |
| 142 | |
| 143 | /** @brief Overloaded Activation property setter function |
| 144 | * |
| 145 | * @param[in] value - One of Activation::Activations |
| 146 | * |
| 147 | * @return Success or exception thrown |
| 148 | */ |
| 149 | Activations activation(Activations value) override; |
| 150 | |
| 151 | /** @brief Activation */ |
| 152 | using ActivationInherit::activation; |
| 153 | |
| 154 | /** @brief Overloaded requestedActivation property setter function |
| 155 | * |
| 156 | * @param[in] value - One of Activation::RequestedActivations |
| 157 | * |
| 158 | * @return Success or exception thrown |
| 159 | */ |
| 160 | RequestedActivations |
| 161 | requestedActivation(RequestedActivations value) override; |
| 162 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 163 | /** @brief Version id */ |
| 164 | std::string versionId; |
| 165 | |
| 166 | private: |
| 167 | /** @brief Check if systemd state change is relevant to this object |
| 168 | * |
| 169 | * Instance specific interface to handle the detected systemd state |
| 170 | * change |
| 171 | * |
| 172 | * @param[in] msg - Data associated with subscribed signal |
| 173 | * |
| 174 | */ |
| 175 | void unitStateChange(sdbusplus::message::message& msg); |
| 176 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 177 | /** |
| 178 | * @brief Delete the version from Image Manager and the |
| 179 | * untar image from image upload dir. |
| 180 | */ |
| 181 | void deleteImageManagerObject(); |
| 182 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 183 | /** @brief Start PSU update */ |
| 184 | void startActivation(); |
| 185 | |
| 186 | /** @brief Finish PSU update */ |
| 187 | void finishActivation(); |
| 188 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 189 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 190 | sdbusplus::bus::bus& bus; |
| 191 | |
| 192 | /** @brief Persistent DBus object path */ |
| 193 | std::string path; |
| 194 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 195 | /** @brief Used to subscribe to dbus systemd signals */ |
| 196 | sdbusplus::bus::match_t systemdSignals; |
| 197 | |
| 198 | /** @brief The PSU update systemd unit */ |
| 199 | std::string psuUpdateUnit; |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 200 | |
| 201 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 202 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame^] | 203 | |
| 204 | /** @brief Persistent ActivationProgress dbus object */ |
| 205 | std::unique_ptr<ActivationProgress> activationProgress; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | } // namespace updater |
| 209 | } // namespace software |
| 210 | } // namespace phosphor |