101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 501539e7eSLei YU #include "activation.hpp" 691029448SLei YU #include "types.hpp" 75e0dcb39SLei YU #include "utils.hpp" 801539e7eSLei YU #include "version.hpp" 901539e7eSLei YU 105e0dcb39SLei 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 15*f77189f7SLei YU class TestItemUpdater; 16*f77189f7SLei YU 1701539e7eSLei YU namespace phosphor 1801539e7eSLei YU { 1901539e7eSLei YU namespace software 2001539e7eSLei YU { 2101539e7eSLei YU namespace updater 2201539e7eSLei YU { 2301539e7eSLei YU 2401539e7eSLei YU class Version; 2501539e7eSLei YU 2601539e7eSLei YU using ItemUpdaterInherit = sdbusplus::server::object::object< 2791029448SLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions, 2801539e7eSLei YU sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; 2901539e7eSLei YU namespace MatchRules = sdbusplus::bus::match::rules; 3001539e7eSLei YU 3101539e7eSLei YU /** @class ItemUpdater 3201539e7eSLei YU * @brief Manages the activation of the PSU version items. 3301539e7eSLei YU */ 3401539e7eSLei YU class ItemUpdater : public ItemUpdaterInherit 3501539e7eSLei YU { 36*f77189f7SLei YU friend class ::TestItemUpdater; 37*f77189f7SLei YU 3801539e7eSLei YU public: 3901539e7eSLei YU /** @brief Constructs ItemUpdater 4001539e7eSLei YU * 4101539e7eSLei YU * @param[in] bus - The D-Bus bus object 4201539e7eSLei YU * @param[in] path - The D-Bus path 4301539e7eSLei YU */ 4401539e7eSLei YU ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 4501539e7eSLei YU ItemUpdaterInherit(bus, path.c_str()), bus(bus), 4601539e7eSLei YU versionMatch(bus, 4701539e7eSLei YU MatchRules::interfacesAdded() + 4801539e7eSLei YU MatchRules::path(SOFTWARE_OBJPATH), 4901539e7eSLei YU std::bind(std::mem_fn(&ItemUpdater::createActivation), 5001539e7eSLei YU this, std::placeholders::_1)) 5101539e7eSLei YU { 52ad90ad51SLei YU processPSUImage(); 5301539e7eSLei YU } 5401539e7eSLei YU 5501539e7eSLei YU /** @brief Deletes version 5601539e7eSLei YU * 5701539e7eSLei YU * @param[in] versionId - Id of the version to delete 5801539e7eSLei YU */ 5901539e7eSLei YU void erase(std::string versionId); 6001539e7eSLei YU 6101539e7eSLei YU /** 6201539e7eSLei YU * @brief Erases any non-active versions. 6301539e7eSLei YU */ 6401539e7eSLei YU void deleteAll(); 6501539e7eSLei YU 6601539e7eSLei YU private: 6791029448SLei YU /** @brief Creates an active association to the 6891029448SLei YU * newly active software image 6991029448SLei YU * 7091029448SLei YU * @param[in] path - The path to create the association to. 7191029448SLei YU */ 7291029448SLei YU void createActiveAssociation(const std::string& path); 7391029448SLei YU 74ad90ad51SLei YU /** @brief Add the functional association to the 7591029448SLei YU * new "running" PSU images 7691029448SLei YU * 77ad90ad51SLei YU * @param[in] path - The path to add the association to. 7891029448SLei YU */ 79ad90ad51SLei YU void addFunctionalAssociation(const std::string& path); 8091029448SLei YU 8191029448SLei YU /** @brief Removes the associations from the provided software image path 8291029448SLei YU * 8391029448SLei YU * @param[in] path - The path to remove the association from. 8491029448SLei YU */ 8591029448SLei YU void removeAssociation(const std::string& path); 8691029448SLei YU 8701539e7eSLei YU /** @brief Callback function for Software.Version match. 8801539e7eSLei YU * @details Creates an Activation D-Bus object. 8901539e7eSLei YU * 9001539e7eSLei YU * @param[in] msg - Data associated with subscribed signal 9101539e7eSLei YU */ 9201539e7eSLei YU void createActivation(sdbusplus::message::message& msg); 9301539e7eSLei YU 94ad90ad51SLei YU /** @brief Callback function for PSU inventory match. 95ad90ad51SLei YU * @details Update an Activation D-Bus object for PSU inventory. 96ad90ad51SLei YU * 97ad90ad51SLei YU * @param[in] msg - Data associated with subscribed signal 98ad90ad51SLei YU */ 99ad90ad51SLei YU void onPsuInventoryChanged(sdbusplus::message::message& msg); 100ad90ad51SLei YU 10101539e7eSLei YU /** @brief Create Activation object */ 10201539e7eSLei YU std::unique_ptr<Activation> createActivationObject( 10301539e7eSLei YU const std::string& path, const std::string& versionId, 10401539e7eSLei YU const std::string& extVersion, 10501539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 10691029448SLei YU Activations activationStatus, 10791029448SLei YU const AssociationList& assocs); 10801539e7eSLei YU 10901539e7eSLei YU /** @brief Create Version object */ 11001539e7eSLei YU std::unique_ptr<Version> 11101539e7eSLei YU createVersionObject(const std::string& objPath, 11201539e7eSLei YU const std::string& versionId, 11301539e7eSLei YU const std::string& versionString, 11401539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server:: 11501539e7eSLei YU Version::VersionPurpose versionPurpose, 11601539e7eSLei YU const std::string& filePath); 11701539e7eSLei YU 118bd3b0076SLei YU /** @brief Create Activation and Version object for PSU inventory 119bd3b0076SLei YU * @details If the same version exists for multiple PSUs, just add 120bd3b0076SLei YU * related association, instead of creating new objects. 121bd3b0076SLei YU * */ 122ad90ad51SLei YU void createPsuObject(const std::string& psuInventoryPath, 123ad90ad51SLei YU const std::string& psuVersion); 124ad90ad51SLei YU 125bd3b0076SLei YU /** @brief Remove Activation and Version object for PSU inventory 126bd3b0076SLei YU * @details If the same version exists for mutliple PSUs, just remove 127bd3b0076SLei YU * related association. 128bd3b0076SLei YU * If the version has no association, the Activation and 129bd3b0076SLei YU * Version object will be removed 130bd3b0076SLei YU */ 131bd3b0076SLei YU void removePsuObject(const std::string& psuInventoryPath); 132bd3b0076SLei YU 133ad90ad51SLei YU /** 134ad90ad51SLei YU * @brief Create and populate the active PSU Version. 135ad90ad51SLei YU */ 136ad90ad51SLei YU void processPSUImage(); 137ad90ad51SLei YU 13801539e7eSLei YU /** @brief Persistent sdbusplus D-Bus bus connection. */ 13901539e7eSLei YU sdbusplus::bus::bus& bus; 14001539e7eSLei YU 14101539e7eSLei YU /** @brief Persistent map of Activation D-Bus objects and their 14201539e7eSLei YU * version id */ 14301539e7eSLei YU std::map<std::string, std::unique_ptr<Activation>> activations; 14401539e7eSLei YU 14501539e7eSLei YU /** @brief Persistent map of Version D-Bus objects and their 14601539e7eSLei YU * version id */ 14701539e7eSLei YU std::map<std::string, std::unique_ptr<Version>> versions; 14801539e7eSLei YU 149bd3b0076SLei YU /** @brief The reference map of PSU Inventory objects and the 150bd3b0076SLei YU * Activation*/ 151bd3b0076SLei YU std::map<std::string, const std::unique_ptr<Activation>&> 152bd3b0076SLei YU psuPathActivationMap; 153bd3b0076SLei YU 154bd3b0076SLei YU /** @brief A struct to hold the PSU present status and version */ 155bd3b0076SLei YU struct psuStatus 156bd3b0076SLei YU { 157bd3b0076SLei YU bool present; 158bd3b0076SLei YU std::string version; 159bd3b0076SLei YU }; 160bd3b0076SLei YU 161bd3b0076SLei YU /** @brief The map of PSU inventory path and the psuStatus */ 162bd3b0076SLei YU std::map<std::string, psuStatus> psuStatusMap; 163bd3b0076SLei YU 164ad90ad51SLei YU /** @brief sdbusplus signal match for PSU Software*/ 16501539e7eSLei YU sdbusplus::bus::match_t versionMatch; 16691029448SLei YU 167ad90ad51SLei YU /** @brief sdbusplus signal matches for PSU Inventory */ 168ad90ad51SLei YU std::vector<sdbusplus::bus::match_t> psuMatches; 169ad90ad51SLei YU 17091029448SLei YU /** @brief This entry's associations */ 17191029448SLei YU AssociationList assocs; 17201539e7eSLei YU }; 17301539e7eSLei YU 17401539e7eSLei YU } // namespace updater 17501539e7eSLei YU } // namespace software 17601539e7eSLei YU } // namespace phosphor 177