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