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 | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 6 | #include "association_interface.hpp" |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 7 | #include "types.hpp" |
Lei YU | 5e0dcb3 | 2019-08-02 18:04:34 +0800 | [diff] [blame] | 8 | #include "utils.hpp" |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 9 | #include "version.hpp" |
| 10 | |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 11 | #include <filesystem> |
Lei YU | 5e0dcb3 | 2019-08-02 18:04:34 +0800 | [diff] [blame] | 12 | #include <phosphor-logging/log.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 13 | #include <sdbusplus/server.hpp> |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Collection/DeleteAll/server.hpp> |
| 16 | |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 17 | class TestItemUpdater; |
| 18 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 19 | namespace phosphor |
| 20 | { |
| 21 | namespace software |
| 22 | { |
| 23 | namespace updater |
| 24 | { |
| 25 | |
| 26 | class Version; |
| 27 | |
| 28 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame] | 29 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
| 30 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 31 | namespace MatchRules = sdbusplus::bus::match::rules; |
| 32 | |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 33 | namespace fs = std::filesystem; |
| 34 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 35 | /** @class ItemUpdater |
| 36 | * @brief Manages the activation of the PSU version items. |
| 37 | */ |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 38 | class ItemUpdater : public ItemUpdaterInherit, public AssociationInterface |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 39 | { |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 40 | friend class ::TestItemUpdater; |
| 41 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 42 | public: |
| 43 | /** @brief Constructs ItemUpdater |
| 44 | * |
| 45 | * @param[in] bus - The D-Bus bus object |
| 46 | * @param[in] path - The D-Bus path |
| 47 | */ |
| 48 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 49 | ItemUpdaterInherit(bus, path.c_str()), bus(bus), |
| 50 | versionMatch(bus, |
| 51 | MatchRules::interfacesAdded() + |
| 52 | MatchRules::path(SOFTWARE_OBJPATH), |
| 53 | std::bind(std::mem_fn(&ItemUpdater::createActivation), |
| 54 | this, std::placeholders::_1)) |
| 55 | { |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 56 | processPSUImage(); |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 57 | processStoredImage(); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** @brief Deletes version |
| 61 | * |
| 62 | * @param[in] versionId - Id of the version to delete |
| 63 | */ |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame] | 64 | void erase(const std::string& versionId); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 65 | |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 66 | /** @brief Creates an active association to the |
| 67 | * newly active software image |
| 68 | * |
| 69 | * @param[in] path - The path to create the association to. |
| 70 | */ |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 71 | void createActiveAssociation(const std::string& path) override; |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 72 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 73 | /** @brief Add the functional association to the |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 74 | * new "running" PSU images |
| 75 | * |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 76 | * @param[in] path - The path to add the association to. |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 77 | */ |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 78 | void addFunctionalAssociation(const std::string& path) override; |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 79 | |
| 80 | /** @brief Removes the associations from the provided software image path |
| 81 | * |
| 82 | * @param[in] path - The path to remove the association from. |
| 83 | */ |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 84 | void removeAssociation(const std::string& path) override; |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 85 | |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 86 | private: |
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, |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 116 | const std::string& extVersion, Activation::Status activationStatus, |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 117 | const AssociationList& assocs, const std::string& filePath); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 118 | |
| 119 | /** @brief Create Version object */ |
| 120 | std::unique_ptr<Version> |
| 121 | createVersionObject(const std::string& objPath, |
| 122 | const std::string& versionId, |
| 123 | const std::string& versionString, |
| 124 | sdbusplus::xyz::openbmc_project::Software::server:: |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 125 | Version::VersionPurpose versionPurpose); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 126 | |
Lei YU | bd3b007 | 2019-08-08 13:09:50 +0800 | [diff] [blame] | 127 | /** @brief Create Activation and Version object for PSU inventory |
| 128 | * @details If the same version exists for multiple PSUs, just add |
| 129 | * related association, instead of creating new objects. |
| 130 | * */ |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 131 | void createPsuObject(const std::string& psuInventoryPath, |
| 132 | const std::string& psuVersion); |
| 133 | |
Lei YU | bd3b007 | 2019-08-08 13:09:50 +0800 | [diff] [blame] | 134 | /** @brief Remove Activation and Version object for PSU inventory |
| 135 | * @details If the same version exists for mutliple PSUs, just remove |
| 136 | * related association. |
| 137 | * If the version has no association, the Activation and |
| 138 | * Version object will be removed |
| 139 | */ |
| 140 | void removePsuObject(const std::string& psuInventoryPath); |
| 141 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 142 | /** |
| 143 | * @brief Create and populate the active PSU Version. |
| 144 | */ |
| 145 | void processPSUImage(); |
| 146 | |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 147 | /** @brief Create PSU Version from stored images */ |
| 148 | void processStoredImage(); |
| 149 | |
| 150 | /** @brief Scan a directory and create PSU Version from stored images */ |
| 151 | void scanDirectory(const fs::path& p); |
| 152 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 153 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 154 | sdbusplus::bus::bus& bus; |
| 155 | |
| 156 | /** @brief Persistent map of Activation D-Bus objects and their |
| 157 | * version id */ |
| 158 | std::map<std::string, std::unique_ptr<Activation>> activations; |
| 159 | |
| 160 | /** @brief Persistent map of Version D-Bus objects and their |
| 161 | * version id */ |
| 162 | std::map<std::string, std::unique_ptr<Version>> versions; |
| 163 | |
Lei YU | bd3b007 | 2019-08-08 13:09:50 +0800 | [diff] [blame] | 164 | /** @brief The reference map of PSU Inventory objects and the |
| 165 | * Activation*/ |
| 166 | std::map<std::string, const std::unique_ptr<Activation>&> |
| 167 | psuPathActivationMap; |
| 168 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 169 | /** @brief sdbusplus signal match for PSU Software*/ |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 170 | sdbusplus::bus::match_t versionMatch; |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 171 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame] | 172 | /** @brief sdbusplus signal matches for PSU Inventory */ |
| 173 | std::vector<sdbusplus::bus::match_t> psuMatches; |
| 174 | |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 175 | /** @brief This entry's associations */ |
| 176 | AssociationList assocs; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } // namespace updater |
| 180 | } // namespace software |
| 181 | } // namespace phosphor |