101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 591029448SLei YU #include "types.hpp" 691029448SLei YU 701539e7eSLei YU #include <sdbusplus/server.hpp> 891029448SLei YU #include <xyz/openbmc_project/Association/Definitions/server.hpp> 901539e7eSLei YU #include <xyz/openbmc_project/Software/Activation/server.hpp> 10*81c67725SLei YU #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> 1101539e7eSLei YU #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> 1201539e7eSLei YU 1301539e7eSLei YU namespace phosphor 1401539e7eSLei YU { 1501539e7eSLei YU namespace software 1601539e7eSLei YU { 1701539e7eSLei YU namespace updater 1801539e7eSLei YU { 1901539e7eSLei YU 2012c9f4c4SLei YU namespace sdbusRule = sdbusplus::bus::match::rules; 2112c9f4c4SLei YU 22*81c67725SLei YU using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< 23*81c67725SLei YU sdbusplus::xyz::openbmc_project::Software::server:: 24*81c67725SLei YU ActivationBlocksTransition>; 25*81c67725SLei YU 26*81c67725SLei YU /** @class ActivationBlocksTransition 27*81c67725SLei YU * @brief OpenBMC ActivationBlocksTransition implementation. 28*81c67725SLei YU * @details A concrete implementation for 29*81c67725SLei YU * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. 30*81c67725SLei YU */ 31*81c67725SLei YU class ActivationBlocksTransition : public ActivationBlocksTransitionInherit 32*81c67725SLei YU { 33*81c67725SLei YU public: 34*81c67725SLei YU /** @brief Constructs ActivationBlocksTransition. 35*81c67725SLei YU * 36*81c67725SLei YU * @param[in] bus - The Dbus bus object 37*81c67725SLei YU * @param[in] path - The Dbus object path 38*81c67725SLei YU */ 39*81c67725SLei YU ActivationBlocksTransition(sdbusplus::bus::bus& bus, 40*81c67725SLei YU const std::string& path) : 41*81c67725SLei YU ActivationBlocksTransitionInherit(bus, path.c_str(), true), 42*81c67725SLei YU bus(bus), path(path) 43*81c67725SLei YU { 44*81c67725SLei YU std::vector<std::string> interfaces({interface}); 45*81c67725SLei YU bus.emit_interfaces_added(path.c_str(), interfaces); 46*81c67725SLei YU } 47*81c67725SLei YU 48*81c67725SLei YU ~ActivationBlocksTransition() 49*81c67725SLei YU { 50*81c67725SLei YU std::vector<std::string> interfaces({interface}); 51*81c67725SLei YU bus.emit_interfaces_removed(path.c_str(), interfaces); 52*81c67725SLei YU } 53*81c67725SLei YU 54*81c67725SLei YU private: 55*81c67725SLei YU // TODO Remove once openbmc/openbmc#1975 is resolved 56*81c67725SLei YU static constexpr auto interface = 57*81c67725SLei YU "xyz.openbmc_project.Software.ActivationBlocksTransition"; 58*81c67725SLei YU sdbusplus::bus::bus& bus; 59*81c67725SLei YU std::string path; 60*81c67725SLei YU }; 61*81c67725SLei YU 6201539e7eSLei YU using ActivationInherit = sdbusplus::server::object::object< 6301539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, 6491029448SLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation, 6591029448SLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions>; 6601539e7eSLei YU 6701539e7eSLei YU /** @class Activation 6801539e7eSLei YU * @brief OpenBMC activation software management implementation. 6901539e7eSLei YU * @details A concrete implementation for 7001539e7eSLei YU * xyz.openbmc_project.Software.Activation DBus API. 7101539e7eSLei YU */ 7201539e7eSLei YU class Activation : public ActivationInherit 7301539e7eSLei YU { 7401539e7eSLei YU public: 7512c9f4c4SLei YU using Status = Activations; 7601539e7eSLei YU /** @brief Constructs Activation Software Manager 7701539e7eSLei YU * 7801539e7eSLei YU * @param[in] bus - The Dbus bus object 7901539e7eSLei YU * @param[in] path - The Dbus object path 8001539e7eSLei YU * @param[in] versionId - The software version id 8101539e7eSLei YU * @param[in] extVersion - The extended version 8201539e7eSLei YU * @param[in] activationStatus - The status of Activation 8391029448SLei YU * @param[in] assocs - Association objects 8401539e7eSLei YU */ 8501539e7eSLei YU Activation(sdbusplus::bus::bus& bus, const std::string& path, 8601539e7eSLei YU const std::string& versionId, const std::string& extVersion, 8701539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 8891029448SLei YU Activations activationStatus, 8991029448SLei YU const AssociationList& assocs) : 9001539e7eSLei YU ActivationInherit(bus, path.c_str(), true), 9112c9f4c4SLei YU versionId(versionId), bus(bus), path(path), 9212c9f4c4SLei YU systemdSignals( 9312c9f4c4SLei YU bus, 9412c9f4c4SLei YU sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + 9512c9f4c4SLei YU sdbusRule::path("/org/freedesktop/systemd1") + 9612c9f4c4SLei YU sdbusRule::interface("org.freedesktop.systemd1.Manager"), 9712c9f4c4SLei YU std::bind(&Activation::unitStateChange, this, 9812c9f4c4SLei YU std::placeholders::_1)) 9901539e7eSLei YU { 10001539e7eSLei YU // Set Properties. 10101539e7eSLei YU extendedVersion(extVersion); 10201539e7eSLei YU activation(activationStatus); 10391029448SLei YU associations(assocs); 10401539e7eSLei YU 10501539e7eSLei YU // Emit deferred signal. 10601539e7eSLei YU emit_object_added(); 10701539e7eSLei YU } 10801539e7eSLei YU 10901539e7eSLei YU /** @brief Overloaded Activation property setter function 11001539e7eSLei YU * 11101539e7eSLei YU * @param[in] value - One of Activation::Activations 11201539e7eSLei YU * 11301539e7eSLei YU * @return Success or exception thrown 11401539e7eSLei YU */ 11501539e7eSLei YU Activations activation(Activations value) override; 11601539e7eSLei YU 11701539e7eSLei YU /** @brief Activation */ 11801539e7eSLei YU using ActivationInherit::activation; 11901539e7eSLei YU 12001539e7eSLei YU /** @brief Overloaded requestedActivation property setter function 12101539e7eSLei YU * 12201539e7eSLei YU * @param[in] value - One of Activation::RequestedActivations 12301539e7eSLei YU * 12401539e7eSLei YU * @return Success or exception thrown 12501539e7eSLei YU */ 12601539e7eSLei YU RequestedActivations 12701539e7eSLei YU requestedActivation(RequestedActivations value) override; 12801539e7eSLei YU 12912c9f4c4SLei YU /** @brief Version id */ 13012c9f4c4SLei YU std::string versionId; 13112c9f4c4SLei YU 13212c9f4c4SLei YU private: 13312c9f4c4SLei YU /** @brief Check if systemd state change is relevant to this object 13412c9f4c4SLei YU * 13512c9f4c4SLei YU * Instance specific interface to handle the detected systemd state 13612c9f4c4SLei YU * change 13712c9f4c4SLei YU * 13812c9f4c4SLei YU * @param[in] msg - Data associated with subscribed signal 13912c9f4c4SLei YU * 14012c9f4c4SLei YU */ 14112c9f4c4SLei YU void unitStateChange(sdbusplus::message::message& msg); 14212c9f4c4SLei YU 143d0bbfa9eSLei YU /** 144d0bbfa9eSLei YU * @brief Delete the version from Image Manager and the 145d0bbfa9eSLei YU * untar image from image upload dir. 146d0bbfa9eSLei YU */ 147d0bbfa9eSLei YU void deleteImageManagerObject(); 148d0bbfa9eSLei YU 14912c9f4c4SLei YU /** @brief Start PSU update */ 15012c9f4c4SLei YU void startActivation(); 15112c9f4c4SLei YU 15212c9f4c4SLei YU /** @brief Finish PSU update */ 15312c9f4c4SLei YU void finishActivation(); 15412c9f4c4SLei YU 15501539e7eSLei YU /** @brief Persistent sdbusplus DBus bus connection */ 15601539e7eSLei YU sdbusplus::bus::bus& bus; 15701539e7eSLei YU 15801539e7eSLei YU /** @brief Persistent DBus object path */ 15901539e7eSLei YU std::string path; 16001539e7eSLei YU 16112c9f4c4SLei YU /** @brief Used to subscribe to dbus systemd signals */ 16212c9f4c4SLei YU sdbusplus::bus::match_t systemdSignals; 16312c9f4c4SLei YU 16412c9f4c4SLei YU /** @brief The PSU update systemd unit */ 16512c9f4c4SLei YU std::string psuUpdateUnit; 166*81c67725SLei YU 167*81c67725SLei YU /** @brief Persistent ActivationBlocksTransition dbus object */ 168*81c67725SLei YU std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; 16901539e7eSLei YU }; 17001539e7eSLei YU 17101539e7eSLei YU } // namespace updater 17201539e7eSLei YU } // namespace software 17301539e7eSLei YU } // namespace phosphor 174