1 #pragma once 2 3 #include "config.h" 4 5 #include "activation.hpp" 6 #include "association_interface.hpp" 7 #include "types.hpp" 8 #include "utils.hpp" 9 #include "version.hpp" 10 11 #include <phosphor-logging/log.hpp> 12 #include <sdbusplus/server.hpp> 13 #include <xyz/openbmc_project/Association/Definitions/server.hpp> 14 #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> 15 16 class TestItemUpdater; 17 18 namespace phosphor 19 { 20 namespace software 21 { 22 namespace updater 23 { 24 25 class Version; 26 27 using ItemUpdaterInherit = sdbusplus::server::object::object< 28 sdbusplus::xyz::openbmc_project::Association::server::Definitions>; 29 30 namespace MatchRules = sdbusplus::bus::match::rules; 31 32 /** @class ItemUpdater 33 * @brief Manages the activation of the PSU version items. 34 */ 35 class ItemUpdater : public ItemUpdaterInherit, public AssociationInterface 36 { 37 friend class ::TestItemUpdater; 38 39 public: 40 /** @brief Constructs ItemUpdater 41 * 42 * @param[in] bus - The D-Bus bus object 43 * @param[in] path - The D-Bus path 44 */ 45 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : 46 ItemUpdaterInherit(bus, path.c_str()), bus(bus), 47 versionMatch(bus, 48 MatchRules::interfacesAdded() + 49 MatchRules::path(SOFTWARE_OBJPATH), 50 std::bind(std::mem_fn(&ItemUpdater::createActivation), 51 this, std::placeholders::_1)) 52 { 53 processPSUImage(); 54 } 55 56 /** @brief Deletes version 57 * 58 * @param[in] versionId - Id of the version to delete 59 */ 60 void erase(const std::string& versionId); 61 62 /** @brief Creates an active association to the 63 * newly active software image 64 * 65 * @param[in] path - The path to create the association to. 66 */ 67 void createActiveAssociation(const std::string& path) override; 68 69 /** @brief Add the functional association to the 70 * new "running" PSU images 71 * 72 * @param[in] path - The path to add the association to. 73 */ 74 void addFunctionalAssociation(const std::string& path) override; 75 76 /** @brief Removes the associations from the provided software image path 77 * 78 * @param[in] path - The path to remove the association from. 79 */ 80 void removeAssociation(const std::string& path) override; 81 82 private: 83 /** @brief Callback function for Software.Version match. 84 * @details Creates an Activation D-Bus object. 85 * 86 * @param[in] msg - Data associated with subscribed signal 87 */ 88 void createActivation(sdbusplus::message::message& msg); 89 90 using Properties = 91 std::map<std::string, utils::UtilsInterface::PropertyType>; 92 93 /** @brief Callback function for PSU inventory match. 94 * @details Update an Activation D-Bus object for PSU inventory. 95 * 96 * @param[in] msg - Data associated with subscribed signal 97 */ 98 void onPsuInventoryChangedMsg(sdbusplus::message::message& msg); 99 100 /** @brief Callback function for PSU inventory match. 101 * @details Update an Activation D-Bus object for PSU inventory. 102 * 103 * @param[in] psuPath - The PSU inventory path 104 * @param[in] properties - The updated properties 105 */ 106 void onPsuInventoryChanged(const std::string& psuPath, 107 const Properties& properties); 108 109 /** @brief Create Activation object */ 110 std::unique_ptr<Activation> createActivationObject( 111 const std::string& path, const std::string& versionId, 112 const std::string& extVersion, 113 sdbusplus::xyz::openbmc_project::Software::server::Activation:: 114 Activations activationStatus, 115 const AssociationList& assocs); 116 117 /** @brief Create Version object */ 118 std::unique_ptr<Version> 119 createVersionObject(const std::string& objPath, 120 const std::string& versionId, 121 const std::string& versionString, 122 sdbusplus::xyz::openbmc_project::Software::server:: 123 Version::VersionPurpose versionPurpose, 124 const std::string& filePath); 125 126 /** @brief Create Activation and Version object for PSU inventory 127 * @details If the same version exists for multiple PSUs, just add 128 * related association, instead of creating new objects. 129 * */ 130 void createPsuObject(const std::string& psuInventoryPath, 131 const std::string& psuVersion); 132 133 /** @brief Remove Activation and Version object for PSU inventory 134 * @details If the same version exists for mutliple PSUs, just remove 135 * related association. 136 * If the version has no association, the Activation and 137 * Version object will be removed 138 */ 139 void removePsuObject(const std::string& psuInventoryPath); 140 141 /** 142 * @brief Create and populate the active PSU Version. 143 */ 144 void processPSUImage(); 145 146 /** @brief Persistent sdbusplus D-Bus bus connection. */ 147 sdbusplus::bus::bus& bus; 148 149 /** @brief Persistent map of Activation D-Bus objects and their 150 * version id */ 151 std::map<std::string, std::unique_ptr<Activation>> activations; 152 153 /** @brief Persistent map of Version D-Bus objects and their 154 * version id */ 155 std::map<std::string, std::unique_ptr<Version>> versions; 156 157 /** @brief The reference map of PSU Inventory objects and the 158 * Activation*/ 159 std::map<std::string, const std::unique_ptr<Activation>&> 160 psuPathActivationMap; 161 162 /** @brief sdbusplus signal match for PSU Software*/ 163 sdbusplus::bus::match_t versionMatch; 164 165 /** @brief sdbusplus signal matches for PSU Inventory */ 166 std::vector<sdbusplus::bus::match_t> psuMatches; 167 168 /** @brief This entry's associations */ 169 AssociationList assocs; 170 }; 171 172 } // namespace updater 173 } // namespace software 174 } // namespace phosphor 175