101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 501539e7eSLei YU #include "activation.hpp" 691029448SLei YU #include "types.hpp" 7*5e0dcb39SLei YU #include "utils.hpp" 801539e7eSLei YU #include "version.hpp" 901539e7eSLei YU 10*5e0dcb39SLei YU #include <phosphor-logging/log.hpp> 1101539e7eSLei YU #include <sdbusplus/server.hpp> 1291029448SLei YU #include <xyz/openbmc_project/Association/Definitions/server.hpp> 1301539e7eSLei YU #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> 1401539e7eSLei YU 1501539e7eSLei YU namespace phosphor 1601539e7eSLei YU { 1701539e7eSLei YU namespace software 1801539e7eSLei YU { 1901539e7eSLei YU namespace updater 2001539e7eSLei YU { 2101539e7eSLei YU 2201539e7eSLei YU class Version; 2301539e7eSLei YU 2401539e7eSLei YU using ItemUpdaterInherit = sdbusplus::server::object::object< 2591029448SLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions, 2601539e7eSLei YU sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; 2701539e7eSLei YU namespace MatchRules = sdbusplus::bus::match::rules; 2801539e7eSLei YU 2901539e7eSLei YU /** @class ItemUpdater 3001539e7eSLei YU * @brief Manages the activation of the PSU version items. 3101539e7eSLei YU */ 3201539e7eSLei YU class ItemUpdater : public ItemUpdaterInherit 3301539e7eSLei YU { 3401539e7eSLei YU public: 3501539e7eSLei YU /** @brief Constructs ItemUpdater 3601539e7eSLei YU * 3701539e7eSLei YU * @param[in] bus - The D-Bus bus object 3801539e7eSLei YU * @param[in] path - The D-Bus path 3901539e7eSLei YU */ 4001539e7eSLei YU ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 4101539e7eSLei YU ItemUpdaterInherit(bus, path.c_str()), bus(bus), 4201539e7eSLei YU versionMatch(bus, 4301539e7eSLei YU MatchRules::interfacesAdded() + 4401539e7eSLei YU MatchRules::path(SOFTWARE_OBJPATH), 4501539e7eSLei YU std::bind(std::mem_fn(&ItemUpdater::createActivation), 4601539e7eSLei YU this, std::placeholders::_1)) 4701539e7eSLei YU { 48*5e0dcb39SLei YU // TODO: create psu inventory objects based on the paths 49*5e0dcb39SLei YU using namespace phosphor::logging; 50*5e0dcb39SLei YU auto paths = utils::getPSUInventoryPath(bus); 51*5e0dcb39SLei YU for (const auto& p : paths) 52*5e0dcb39SLei YU { 53*5e0dcb39SLei YU log<level::INFO>("PSU path", entry("PATH=%s", p.c_str())); 54*5e0dcb39SLei YU } 5501539e7eSLei YU } 5601539e7eSLei YU 5701539e7eSLei YU /** @brief Deletes version 5801539e7eSLei YU * 5901539e7eSLei YU * @param[in] versionId - Id of the version to delete 6001539e7eSLei YU */ 6101539e7eSLei YU void erase(std::string versionId); 6201539e7eSLei YU 6301539e7eSLei YU /** 6401539e7eSLei YU * @brief Erases any non-active versions. 6501539e7eSLei YU */ 6601539e7eSLei YU void deleteAll(); 6701539e7eSLei YU 6801539e7eSLei YU private: 6991029448SLei YU /** @brief Creates an active association to the 7091029448SLei YU * newly active software image 7191029448SLei YU * 7291029448SLei YU * @param[in] path - The path to create the association to. 7391029448SLei YU */ 7491029448SLei YU void createActiveAssociation(const std::string& path); 7591029448SLei YU 7691029448SLei YU /** @brief Updates the functional association to the 7791029448SLei YU * new "running" PSU images 7891029448SLei YU * 7991029448SLei YU * @param[in] versionId - The id of the image to update the association to. 8091029448SLei YU */ 8191029448SLei YU void updateFunctionalAssociation(const std::string& versionId); 8291029448SLei YU 8391029448SLei YU /** @brief Removes the associations from the provided software image path 8491029448SLei YU * 8591029448SLei YU * @param[in] path - The path to remove the association from. 8691029448SLei YU */ 8791029448SLei YU void removeAssociation(const std::string& path); 8891029448SLei YU 8901539e7eSLei YU /** @brief Callback function for Software.Version match. 9001539e7eSLei YU * @details Creates an Activation D-Bus object. 9101539e7eSLei YU * 9201539e7eSLei YU * @param[in] msg - Data associated with subscribed signal 9301539e7eSLei YU */ 9401539e7eSLei YU void createActivation(sdbusplus::message::message& msg); 9501539e7eSLei YU 9601539e7eSLei YU /** @brief Create Activation object */ 9701539e7eSLei YU std::unique_ptr<Activation> createActivationObject( 9801539e7eSLei YU const std::string& path, const std::string& versionId, 9901539e7eSLei YU const std::string& extVersion, 10001539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 10191029448SLei YU Activations activationStatus, 10291029448SLei YU const AssociationList& assocs); 10301539e7eSLei YU 10401539e7eSLei YU /** @brief Create Version object */ 10501539e7eSLei YU std::unique_ptr<Version> 10601539e7eSLei YU createVersionObject(const std::string& objPath, 10701539e7eSLei YU const std::string& versionId, 10801539e7eSLei YU const std::string& versionString, 10901539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server:: 11001539e7eSLei YU Version::VersionPurpose versionPurpose, 11101539e7eSLei YU const std::string& filePath); 11201539e7eSLei YU 11301539e7eSLei YU /** @brief Persistent sdbusplus D-Bus bus connection. */ 11401539e7eSLei YU sdbusplus::bus::bus& bus; 11501539e7eSLei YU 11601539e7eSLei YU /** @brief Persistent map of Activation D-Bus objects and their 11701539e7eSLei YU * version id */ 11801539e7eSLei YU std::map<std::string, std::unique_ptr<Activation>> activations; 11901539e7eSLei YU 12001539e7eSLei YU /** @brief Persistent map of Version D-Bus objects and their 12101539e7eSLei YU * version id */ 12201539e7eSLei YU std::map<std::string, std::unique_ptr<Version>> versions; 12301539e7eSLei YU 12401539e7eSLei YU /** @brief sdbusplus signal match for Software.Version */ 12501539e7eSLei YU sdbusplus::bus::match_t versionMatch; 12691029448SLei YU 12791029448SLei YU /** @brief This entry's associations */ 12891029448SLei YU AssociationList assocs; 12901539e7eSLei YU }; 13001539e7eSLei YU 13101539e7eSLei YU } // namespace updater 13201539e7eSLei YU } // namespace software 13301539e7eSLei YU } // namespace phosphor 134