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 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace software |
| 18 | { |
| 19 | namespace updater |
| 20 | { |
| 21 | |
| 22 | class Version; |
| 23 | |
| 24 | using ItemUpdaterInherit = sdbusplus::server::object::object< |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Association::server::Definitions, |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 26 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
| 27 | namespace MatchRules = sdbusplus::bus::match::rules; |
| 28 | |
| 29 | /** @class ItemUpdater |
| 30 | * @brief Manages the activation of the PSU version items. |
| 31 | */ |
| 32 | class ItemUpdater : public ItemUpdaterInherit |
| 33 | { |
| 34 | public: |
| 35 | /** @brief Constructs ItemUpdater |
| 36 | * |
| 37 | * @param[in] bus - The D-Bus bus object |
| 38 | * @param[in] path - The D-Bus path |
| 39 | */ |
| 40 | ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) : |
| 41 | ItemUpdaterInherit(bus, path.c_str()), bus(bus), |
| 42 | versionMatch(bus, |
| 43 | MatchRules::interfacesAdded() + |
| 44 | MatchRules::path(SOFTWARE_OBJPATH), |
| 45 | std::bind(std::mem_fn(&ItemUpdater::createActivation), |
| 46 | this, std::placeholders::_1)) |
| 47 | { |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 48 | processPSUImage(); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** @brief Deletes version |
| 52 | * |
| 53 | * @param[in] versionId - Id of the version to delete |
| 54 | */ |
| 55 | void erase(std::string versionId); |
| 56 | |
| 57 | /** |
| 58 | * @brief Erases any non-active versions. |
| 59 | */ |
| 60 | void deleteAll(); |
| 61 | |
| 62 | private: |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 63 | /** @brief Creates an active association to the |
| 64 | * newly active software image |
| 65 | * |
| 66 | * @param[in] path - The path to create the association to. |
| 67 | */ |
| 68 | void createActiveAssociation(const std::string& path); |
| 69 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 70 | /** @brief Add the functional association to the |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 71 | * new "running" PSU images |
| 72 | * |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 73 | * @param[in] path - The path to add the association to. |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 74 | */ |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 75 | void addFunctionalAssociation(const std::string& path); |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 76 | |
| 77 | /** @brief Removes the associations from the provided software image path |
| 78 | * |
| 79 | * @param[in] path - The path to remove the association from. |
| 80 | */ |
| 81 | void removeAssociation(const std::string& path); |
| 82 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 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 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 90 | /** @brief Callback function for PSU inventory match. |
| 91 | * @details Update an Activation D-Bus object for PSU inventory. |
| 92 | * |
| 93 | * @param[in] msg - Data associated with subscribed signal |
| 94 | */ |
| 95 | void onPsuInventoryChanged(sdbusplus::message::message& msg); |
| 96 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 97 | /** @brief Create Activation object */ |
| 98 | std::unique_ptr<Activation> createActivationObject( |
| 99 | const std::string& path, const std::string& versionId, |
| 100 | const std::string& extVersion, |
| 101 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 102 | Activations activationStatus, |
| 103 | const AssociationList& assocs); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 104 | |
| 105 | /** @brief Create Version object */ |
| 106 | std::unique_ptr<Version> |
| 107 | createVersionObject(const std::string& objPath, |
| 108 | const std::string& versionId, |
| 109 | const std::string& versionString, |
| 110 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 111 | Version::VersionPurpose versionPurpose, |
| 112 | const std::string& filePath); |
| 113 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 114 | /** @brief Create Activation and Version object for PSU inventory */ |
| 115 | void createPsuObject(const std::string& psuInventoryPath, |
| 116 | const std::string& psuVersion); |
| 117 | |
| 118 | /** |
| 119 | * @brief Create and populate the active PSU Version. |
| 120 | */ |
| 121 | void processPSUImage(); |
| 122 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 123 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 124 | sdbusplus::bus::bus& bus; |
| 125 | |
| 126 | /** @brief Persistent map of Activation D-Bus objects and their |
| 127 | * version id */ |
| 128 | std::map<std::string, std::unique_ptr<Activation>> activations; |
| 129 | |
| 130 | /** @brief Persistent map of Version D-Bus objects and their |
| 131 | * version id */ |
| 132 | std::map<std::string, std::unique_ptr<Version>> versions; |
| 133 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 134 | /** @brief sdbusplus signal match for PSU Software*/ |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 135 | sdbusplus::bus::match_t versionMatch; |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 136 | |
Lei YU | ad90ad5 | 2019-08-06 11:19:28 +0800 | [diff] [blame^] | 137 | /** @brief sdbusplus signal matches for PSU Inventory */ |
| 138 | std::vector<sdbusplus::bus::match_t> psuMatches; |
| 139 | |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 140 | /** @brief This entry's associations */ |
| 141 | AssociationList assocs; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | } // namespace updater |
| 145 | } // namespace software |
| 146 | } // namespace phosphor |