101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 501539e7eSLei YU #include "activation.hpp" 67f2a2152SLei YU #include "association_interface.hpp" 791029448SLei YU #include "types.hpp" 85e0dcb39SLei YU #include "utils.hpp" 901539e7eSLei YU #include "version.hpp" 1001539e7eSLei YU 11*58c26e3fSLei YU #include <filesystem> 125e0dcb39SLei YU #include <phosphor-logging/log.hpp> 1301539e7eSLei YU #include <sdbusplus/server.hpp> 1491029448SLei YU #include <xyz/openbmc_project/Association/Definitions/server.hpp> 1501539e7eSLei YU #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> 1601539e7eSLei YU 17f77189f7SLei YU class TestItemUpdater; 18f77189f7SLei YU 1901539e7eSLei YU namespace phosphor 2001539e7eSLei YU { 2101539e7eSLei YU namespace software 2201539e7eSLei YU { 2301539e7eSLei YU namespace updater 2401539e7eSLei YU { 2501539e7eSLei YU 2601539e7eSLei YU class Version; 2701539e7eSLei YU 2801539e7eSLei YU using ItemUpdaterInherit = sdbusplus::server::object::object< 29a5c47bb3SLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions>; 30a5c47bb3SLei YU 3101539e7eSLei YU namespace MatchRules = sdbusplus::bus::match::rules; 3201539e7eSLei YU 33*58c26e3fSLei YU namespace fs = std::filesystem; 34*58c26e3fSLei YU 3501539e7eSLei YU /** @class ItemUpdater 3601539e7eSLei YU * @brief Manages the activation of the PSU version items. 3701539e7eSLei YU */ 387f2a2152SLei YU class ItemUpdater : public ItemUpdaterInherit, public AssociationInterface 3901539e7eSLei YU { 40f77189f7SLei YU friend class ::TestItemUpdater; 41f77189f7SLei YU 4201539e7eSLei YU public: 4301539e7eSLei YU /** @brief Constructs ItemUpdater 4401539e7eSLei YU * 4501539e7eSLei YU * @param[in] bus - The D-Bus bus object 4601539e7eSLei YU * @param[in] path - The D-Bus path 4701539e7eSLei YU */ 4801539e7eSLei YU ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 4901539e7eSLei YU ItemUpdaterInherit(bus, path.c_str()), bus(bus), 5001539e7eSLei YU versionMatch(bus, 5101539e7eSLei YU MatchRules::interfacesAdded() + 5201539e7eSLei YU MatchRules::path(SOFTWARE_OBJPATH), 5301539e7eSLei YU std::bind(std::mem_fn(&ItemUpdater::createActivation), 5401539e7eSLei YU this, std::placeholders::_1)) 5501539e7eSLei YU { 56ad90ad51SLei YU processPSUImage(); 57*58c26e3fSLei YU processStoredImage(); 5801539e7eSLei YU } 5901539e7eSLei YU 6001539e7eSLei YU /** @brief Deletes version 6101539e7eSLei YU * 6201539e7eSLei YU * @param[in] versionId - Id of the version to delete 6301539e7eSLei YU */ 64a5c47bb3SLei YU void erase(const std::string& versionId); 6501539e7eSLei YU 6691029448SLei YU /** @brief Creates an active association to the 6791029448SLei YU * newly active software image 6891029448SLei YU * 6991029448SLei YU * @param[in] path - The path to create the association to. 7091029448SLei YU */ 717f2a2152SLei YU void createActiveAssociation(const std::string& path) override; 7291029448SLei YU 73ad90ad51SLei YU /** @brief Add the functional association to the 7491029448SLei YU * new "running" PSU images 7591029448SLei YU * 76ad90ad51SLei YU * @param[in] path - The path to add the association to. 7791029448SLei YU */ 787f2a2152SLei YU void addFunctionalAssociation(const std::string& path) override; 7991029448SLei YU 8091029448SLei YU /** @brief Removes the associations from the provided software image path 8191029448SLei YU * 8291029448SLei YU * @param[in] path - The path to remove the association from. 8391029448SLei YU */ 847f2a2152SLei YU void removeAssociation(const std::string& path) override; 8591029448SLei YU 867f2a2152SLei YU private: 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 94a2c2cd72SLei YU using Properties = 95a2c2cd72SLei YU std::map<std::string, utils::UtilsInterface::PropertyType>; 96a2c2cd72SLei YU 97ad90ad51SLei YU /** @brief Callback function for PSU inventory match. 98ad90ad51SLei YU * @details Update an Activation D-Bus object for PSU inventory. 99ad90ad51SLei YU * 100ad90ad51SLei YU * @param[in] msg - Data associated with subscribed signal 101ad90ad51SLei YU */ 102a2c2cd72SLei YU void onPsuInventoryChangedMsg(sdbusplus::message::message& msg); 103a2c2cd72SLei YU 104a2c2cd72SLei YU /** @brief Callback function for PSU inventory match. 105a2c2cd72SLei YU * @details Update an Activation D-Bus object for PSU inventory. 106a2c2cd72SLei YU * 107a2c2cd72SLei YU * @param[in] psuPath - The PSU inventory path 108a2c2cd72SLei YU * @param[in] properties - The updated properties 109a2c2cd72SLei YU */ 110a2c2cd72SLei YU void onPsuInventoryChanged(const std::string& psuPath, 111a2c2cd72SLei YU const Properties& properties); 112ad90ad51SLei YU 11301539e7eSLei YU /** @brief Create Activation object */ 11401539e7eSLei YU std::unique_ptr<Activation> createActivationObject( 11501539e7eSLei YU const std::string& path, const std::string& versionId, 116*58c26e3fSLei YU const std::string& extVersion, Activation::Status activationStatus, 1179930137bSLei YU const AssociationList& assocs, const std::string& filePath); 11801539e7eSLei YU 11901539e7eSLei YU /** @brief Create Version object */ 12001539e7eSLei YU std::unique_ptr<Version> 12101539e7eSLei YU createVersionObject(const std::string& objPath, 12201539e7eSLei YU const std::string& versionId, 12301539e7eSLei YU const std::string& versionString, 12401539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server:: 1259930137bSLei YU Version::VersionPurpose versionPurpose); 12601539e7eSLei YU 127bd3b0076SLei YU /** @brief Create Activation and Version object for PSU inventory 128bd3b0076SLei YU * @details If the same version exists for multiple PSUs, just add 129bd3b0076SLei YU * related association, instead of creating new objects. 130bd3b0076SLei YU * */ 131ad90ad51SLei YU void createPsuObject(const std::string& psuInventoryPath, 132ad90ad51SLei YU const std::string& psuVersion); 133ad90ad51SLei YU 134bd3b0076SLei YU /** @brief Remove Activation and Version object for PSU inventory 135bd3b0076SLei YU * @details If the same version exists for mutliple PSUs, just remove 136bd3b0076SLei YU * related association. 137bd3b0076SLei YU * If the version has no association, the Activation and 138bd3b0076SLei YU * Version object will be removed 139bd3b0076SLei YU */ 140bd3b0076SLei YU void removePsuObject(const std::string& psuInventoryPath); 141bd3b0076SLei YU 142ad90ad51SLei YU /** 143ad90ad51SLei YU * @brief Create and populate the active PSU Version. 144ad90ad51SLei YU */ 145ad90ad51SLei YU void processPSUImage(); 146ad90ad51SLei YU 147*58c26e3fSLei YU /** @brief Create PSU Version from stored images */ 148*58c26e3fSLei YU void processStoredImage(); 149*58c26e3fSLei YU 150*58c26e3fSLei YU /** @brief Scan a directory and create PSU Version from stored images */ 151*58c26e3fSLei YU void scanDirectory(const fs::path& p); 152*58c26e3fSLei YU 15301539e7eSLei YU /** @brief Persistent sdbusplus D-Bus bus connection. */ 15401539e7eSLei YU sdbusplus::bus::bus& bus; 15501539e7eSLei YU 15601539e7eSLei YU /** @brief Persistent map of Activation D-Bus objects and their 15701539e7eSLei YU * version id */ 15801539e7eSLei YU std::map<std::string, std::unique_ptr<Activation>> activations; 15901539e7eSLei YU 16001539e7eSLei YU /** @brief Persistent map of Version D-Bus objects and their 16101539e7eSLei YU * version id */ 16201539e7eSLei YU std::map<std::string, std::unique_ptr<Version>> versions; 16301539e7eSLei YU 164bd3b0076SLei YU /** @brief The reference map of PSU Inventory objects and the 165bd3b0076SLei YU * Activation*/ 166bd3b0076SLei YU std::map<std::string, const std::unique_ptr<Activation>&> 167bd3b0076SLei YU psuPathActivationMap; 168bd3b0076SLei YU 169ad90ad51SLei YU /** @brief sdbusplus signal match for PSU Software*/ 17001539e7eSLei YU sdbusplus::bus::match_t versionMatch; 17191029448SLei YU 172ad90ad51SLei YU /** @brief sdbusplus signal matches for PSU Inventory */ 173ad90ad51SLei YU std::vector<sdbusplus::bus::match_t> psuMatches; 174ad90ad51SLei YU 17591029448SLei YU /** @brief This entry's associations */ 17691029448SLei YU AssociationList assocs; 17701539e7eSLei YU }; 17801539e7eSLei YU 17901539e7eSLei YU } // namespace updater 18001539e7eSLei YU } // namespace software 18101539e7eSLei YU } // namespace phosphor 182