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