101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 501539e7eSLei YU #include "activation.hpp" 6*91029448SLei YU #include "types.hpp" 701539e7eSLei YU #include "version.hpp" 801539e7eSLei YU 901539e7eSLei YU #include <sdbusplus/server.hpp> 10*91029448SLei YU #include <xyz/openbmc_project/Association/Definitions/server.hpp> 1101539e7eSLei YU #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> 1201539e7eSLei YU 1301539e7eSLei YU namespace phosphor 1401539e7eSLei YU { 1501539e7eSLei YU namespace software 1601539e7eSLei YU { 1701539e7eSLei YU namespace updater 1801539e7eSLei YU { 1901539e7eSLei YU 2001539e7eSLei YU class Version; 2101539e7eSLei YU 2201539e7eSLei YU using ItemUpdaterInherit = sdbusplus::server::object::object< 23*91029448SLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions, 2401539e7eSLei YU sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; 2501539e7eSLei YU namespace MatchRules = sdbusplus::bus::match::rules; 2601539e7eSLei YU 2701539e7eSLei YU /** @class ItemUpdater 2801539e7eSLei YU * @brief Manages the activation of the PSU version items. 2901539e7eSLei YU */ 3001539e7eSLei YU class ItemUpdater : public ItemUpdaterInherit 3101539e7eSLei YU { 3201539e7eSLei YU public: 3301539e7eSLei YU /** @brief Constructs ItemUpdater 3401539e7eSLei YU * 3501539e7eSLei YU * @param[in] bus - The D-Bus bus object 3601539e7eSLei YU * @param[in] path - The D-Bus path 3701539e7eSLei YU */ 3801539e7eSLei YU ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 3901539e7eSLei YU ItemUpdaterInherit(bus, path.c_str()), bus(bus), 4001539e7eSLei YU versionMatch(bus, 4101539e7eSLei YU MatchRules::interfacesAdded() + 4201539e7eSLei YU MatchRules::path(SOFTWARE_OBJPATH), 4301539e7eSLei YU std::bind(std::mem_fn(&ItemUpdater::createActivation), 4401539e7eSLei YU this, std::placeholders::_1)) 4501539e7eSLei YU { 4601539e7eSLei YU } 4701539e7eSLei YU 4801539e7eSLei YU /** @brief Deletes version 4901539e7eSLei YU * 5001539e7eSLei YU * @param[in] versionId - Id of the version to delete 5101539e7eSLei YU */ 5201539e7eSLei YU void erase(std::string versionId); 5301539e7eSLei YU 5401539e7eSLei YU /** 5501539e7eSLei YU * @brief Erases any non-active versions. 5601539e7eSLei YU */ 5701539e7eSLei YU void deleteAll(); 5801539e7eSLei YU 5901539e7eSLei YU private: 60*91029448SLei YU /** @brief Creates an active association to the 61*91029448SLei YU * newly active software image 62*91029448SLei YU * 63*91029448SLei YU * @param[in] path - The path to create the association to. 64*91029448SLei YU */ 65*91029448SLei YU void createActiveAssociation(const std::string& path); 66*91029448SLei YU 67*91029448SLei YU /** @brief Updates the functional association to the 68*91029448SLei YU * new "running" PSU images 69*91029448SLei YU * 70*91029448SLei YU * @param[in] versionId - The id of the image to update the association to. 71*91029448SLei YU */ 72*91029448SLei YU void updateFunctionalAssociation(const std::string& versionId); 73*91029448SLei YU 74*91029448SLei YU /** @brief Removes the associations from the provided software image path 75*91029448SLei YU * 76*91029448SLei YU * @param[in] path - The path to remove the association from. 77*91029448SLei YU */ 78*91029448SLei YU void removeAssociation(const std::string& path); 79*91029448SLei YU 8001539e7eSLei YU /** @brief Callback function for Software.Version match. 8101539e7eSLei YU * @details Creates an Activation D-Bus object. 8201539e7eSLei YU * 8301539e7eSLei YU * @param[in] msg - Data associated with subscribed signal 8401539e7eSLei YU */ 8501539e7eSLei YU void createActivation(sdbusplus::message::message& msg); 8601539e7eSLei YU 8701539e7eSLei YU /** @brief Create Activation object */ 8801539e7eSLei YU std::unique_ptr<Activation> createActivationObject( 8901539e7eSLei YU const std::string& path, const std::string& versionId, 9001539e7eSLei YU const std::string& extVersion, 9101539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 92*91029448SLei YU Activations activationStatus, 93*91029448SLei YU const AssociationList& assocs); 9401539e7eSLei YU 9501539e7eSLei YU /** @brief Create Version object */ 9601539e7eSLei YU std::unique_ptr<Version> 9701539e7eSLei YU createVersionObject(const std::string& objPath, 9801539e7eSLei YU const std::string& versionId, 9901539e7eSLei YU const std::string& versionString, 10001539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server:: 10101539e7eSLei YU Version::VersionPurpose versionPurpose, 10201539e7eSLei YU const std::string& filePath); 10301539e7eSLei YU 10401539e7eSLei YU /** @brief Persistent sdbusplus D-Bus bus connection. */ 10501539e7eSLei YU sdbusplus::bus::bus& bus; 10601539e7eSLei YU 10701539e7eSLei YU /** @brief Persistent map of Activation D-Bus objects and their 10801539e7eSLei YU * version id */ 10901539e7eSLei YU std::map<std::string, std::unique_ptr<Activation>> activations; 11001539e7eSLei YU 11101539e7eSLei YU /** @brief Persistent map of Version D-Bus objects and their 11201539e7eSLei YU * version id */ 11301539e7eSLei YU std::map<std::string, std::unique_ptr<Version>> versions; 11401539e7eSLei YU 11501539e7eSLei YU /** @brief sdbusplus signal match for Software.Version */ 11601539e7eSLei YU sdbusplus::bus::match_t versionMatch; 117*91029448SLei YU 118*91029448SLei YU /** @brief This entry's associations */ 119*91029448SLei YU AssociationList assocs; 12001539e7eSLei YU }; 12101539e7eSLei YU 12201539e7eSLei YU } // namespace updater 12301539e7eSLei YU } // namespace software 12401539e7eSLei YU } // namespace phosphor 125