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