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 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 { 48ad90ad51SLei YU processPSUImage(); 4901539e7eSLei YU } 5001539e7eSLei YU 5101539e7eSLei YU /** @brief Deletes version 5201539e7eSLei YU * 5301539e7eSLei YU * @param[in] versionId - Id of the version to delete 5401539e7eSLei YU */ 5501539e7eSLei YU void erase(std::string versionId); 5601539e7eSLei YU 5701539e7eSLei YU /** 5801539e7eSLei YU * @brief Erases any non-active versions. 5901539e7eSLei YU */ 6001539e7eSLei YU void deleteAll(); 6101539e7eSLei YU 6201539e7eSLei YU private: 6391029448SLei YU /** @brief Creates an active association to the 6491029448SLei YU * newly active software image 6591029448SLei YU * 6691029448SLei YU * @param[in] path - The path to create the association to. 6791029448SLei YU */ 6891029448SLei YU void createActiveAssociation(const std::string& path); 6991029448SLei YU 70ad90ad51SLei YU /** @brief Add the functional association to the 7191029448SLei YU * new "running" PSU images 7291029448SLei YU * 73ad90ad51SLei YU * @param[in] path - The path to add the association to. 7491029448SLei YU */ 75ad90ad51SLei YU void addFunctionalAssociation(const std::string& path); 7691029448SLei YU 7791029448SLei YU /** @brief Removes the associations from the provided software image path 7891029448SLei YU * 7991029448SLei YU * @param[in] path - The path to remove the association from. 8091029448SLei YU */ 8191029448SLei YU void removeAssociation(const std::string& path); 8291029448SLei YU 8301539e7eSLei YU /** @brief Callback function for Software.Version match. 8401539e7eSLei YU * @details Creates an Activation D-Bus object. 8501539e7eSLei YU * 8601539e7eSLei YU * @param[in] msg - Data associated with subscribed signal 8701539e7eSLei YU */ 8801539e7eSLei YU void createActivation(sdbusplus::message::message& msg); 8901539e7eSLei YU 90ad90ad51SLei YU /** @brief Callback function for PSU inventory match. 91ad90ad51SLei YU * @details Update an Activation D-Bus object for PSU inventory. 92ad90ad51SLei YU * 93ad90ad51SLei YU * @param[in] msg - Data associated with subscribed signal 94ad90ad51SLei YU */ 95ad90ad51SLei YU void onPsuInventoryChanged(sdbusplus::message::message& msg); 96ad90ad51SLei YU 9701539e7eSLei YU /** @brief Create Activation object */ 9801539e7eSLei YU std::unique_ptr<Activation> createActivationObject( 9901539e7eSLei YU const std::string& path, const std::string& versionId, 10001539e7eSLei YU const std::string& extVersion, 10101539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 10291029448SLei YU Activations activationStatus, 10391029448SLei YU const AssociationList& assocs); 10401539e7eSLei YU 10501539e7eSLei YU /** @brief Create Version object */ 10601539e7eSLei YU std::unique_ptr<Version> 10701539e7eSLei YU createVersionObject(const std::string& objPath, 10801539e7eSLei YU const std::string& versionId, 10901539e7eSLei YU const std::string& versionString, 11001539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server:: 11101539e7eSLei YU Version::VersionPurpose versionPurpose, 11201539e7eSLei YU const std::string& filePath); 11301539e7eSLei YU 114*bd3b0076SLei YU /** @brief Create Activation and Version object for PSU inventory 115*bd3b0076SLei YU * @details If the same version exists for multiple PSUs, just add 116*bd3b0076SLei YU * related association, instead of creating new objects. 117*bd3b0076SLei YU * */ 118ad90ad51SLei YU void createPsuObject(const std::string& psuInventoryPath, 119ad90ad51SLei YU const std::string& psuVersion); 120ad90ad51SLei YU 121*bd3b0076SLei YU /** @brief Remove Activation and Version object for PSU inventory 122*bd3b0076SLei YU * @details If the same version exists for mutliple PSUs, just remove 123*bd3b0076SLei YU * related association. 124*bd3b0076SLei YU * If the version has no association, the Activation and 125*bd3b0076SLei YU * Version object will be removed 126*bd3b0076SLei YU */ 127*bd3b0076SLei YU void removePsuObject(const std::string& psuInventoryPath); 128*bd3b0076SLei YU 129ad90ad51SLei YU /** 130ad90ad51SLei YU * @brief Create and populate the active PSU Version. 131ad90ad51SLei YU */ 132ad90ad51SLei YU void processPSUImage(); 133ad90ad51SLei YU 13401539e7eSLei YU /** @brief Persistent sdbusplus D-Bus bus connection. */ 13501539e7eSLei YU sdbusplus::bus::bus& bus; 13601539e7eSLei YU 13701539e7eSLei YU /** @brief Persistent map of Activation D-Bus objects and their 13801539e7eSLei YU * version id */ 13901539e7eSLei YU std::map<std::string, std::unique_ptr<Activation>> activations; 14001539e7eSLei YU 14101539e7eSLei YU /** @brief Persistent map of Version D-Bus objects and their 14201539e7eSLei YU * version id */ 14301539e7eSLei YU std::map<std::string, std::unique_ptr<Version>> versions; 14401539e7eSLei YU 145*bd3b0076SLei YU /** @brief The reference map of PSU Inventory objects and the 146*bd3b0076SLei YU * Activation*/ 147*bd3b0076SLei YU std::map<std::string, const std::unique_ptr<Activation>&> 148*bd3b0076SLei YU psuPathActivationMap; 149*bd3b0076SLei YU 150*bd3b0076SLei YU /** @brief A struct to hold the PSU present status and version */ 151*bd3b0076SLei YU struct psuStatus 152*bd3b0076SLei YU { 153*bd3b0076SLei YU bool present; 154*bd3b0076SLei YU std::string version; 155*bd3b0076SLei YU }; 156*bd3b0076SLei YU 157*bd3b0076SLei YU /** @brief The map of PSU inventory path and the psuStatus */ 158*bd3b0076SLei YU std::map<std::string, psuStatus> psuStatusMap; 159*bd3b0076SLei YU 160ad90ad51SLei YU /** @brief sdbusplus signal match for PSU Software*/ 16101539e7eSLei YU sdbusplus::bus::match_t versionMatch; 16291029448SLei YU 163ad90ad51SLei YU /** @brief sdbusplus signal matches for PSU Inventory */ 164ad90ad51SLei YU std::vector<sdbusplus::bus::match_t> psuMatches; 165ad90ad51SLei YU 16691029448SLei YU /** @brief This entry's associations */ 16791029448SLei YU AssociationList assocs; 16801539e7eSLei YU }; 16901539e7eSLei YU 17001539e7eSLei YU } // namespace updater 17101539e7eSLei YU } // namespace software 17201539e7eSLei YU } // namespace phosphor 173