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