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