| 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 | 5e0dcb3 | 2019-08-02 18:04:34 +0800 | [diff] [blame^] | 48 | // TODO: create psu inventory objects based on the paths | 
|  | 49 | using namespace phosphor::logging; | 
|  | 50 | auto paths = utils::getPSUInventoryPath(bus); | 
|  | 51 | for (const auto& p : paths) | 
|  | 52 | { | 
|  | 53 | log<level::INFO>("PSU path", entry("PATH=%s", p.c_str())); | 
|  | 54 | } | 
| Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
|  | 57 | /** @brief Deletes version | 
|  | 58 | * | 
|  | 59 | *  @param[in] versionId - Id of the version to delete | 
|  | 60 | */ | 
|  | 61 | void erase(std::string versionId); | 
|  | 62 |  | 
|  | 63 | /** | 
|  | 64 | * @brief Erases any non-active versions. | 
|  | 65 | */ | 
|  | 66 | void deleteAll(); | 
|  | 67 |  | 
|  | 68 | private: | 
| Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 69 | /** @brief Creates an active association to the | 
|  | 70 | *  newly active software image | 
|  | 71 | * | 
|  | 72 | * @param[in]  path - The path to create the association to. | 
|  | 73 | */ | 
|  | 74 | void createActiveAssociation(const std::string& path); | 
|  | 75 |  | 
|  | 76 | /** @brief Updates the functional association to the | 
|  | 77 | *  new "running" PSU images | 
|  | 78 | * | 
|  | 79 | * @param[in]  versionId - The id of the image to update the association to. | 
|  | 80 | */ | 
|  | 81 | void updateFunctionalAssociation(const std::string& versionId); | 
|  | 82 |  | 
|  | 83 | /** @brief Removes the associations from the provided software image path | 
|  | 84 | * | 
|  | 85 | * @param[in]  path - The path to remove the association from. | 
|  | 86 | */ | 
|  | 87 | void removeAssociation(const std::string& path); | 
|  | 88 |  | 
| Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 89 | /** @brief Callback function for Software.Version match. | 
|  | 90 | *  @details Creates an Activation D-Bus object. | 
|  | 91 | * | 
|  | 92 | * @param[in]  msg       - Data associated with subscribed signal | 
|  | 93 | */ | 
|  | 94 | void createActivation(sdbusplus::message::message& msg); | 
|  | 95 |  | 
|  | 96 | /** @brief Create Activation object */ | 
|  | 97 | std::unique_ptr<Activation> createActivationObject( | 
|  | 98 | const std::string& path, const std::string& versionId, | 
|  | 99 | const std::string& extVersion, | 
|  | 100 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: | 
| Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 101 | Activations activationStatus, | 
|  | 102 | const AssociationList& assocs); | 
| Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 103 |  | 
|  | 104 | /** @brief Create Version object */ | 
|  | 105 | std::unique_ptr<Version> | 
|  | 106 | createVersionObject(const std::string& objPath, | 
|  | 107 | const std::string& versionId, | 
|  | 108 | const std::string& versionString, | 
|  | 109 | sdbusplus::xyz::openbmc_project::Software::server:: | 
|  | 110 | Version::VersionPurpose versionPurpose, | 
|  | 111 | const std::string& filePath); | 
|  | 112 |  | 
|  | 113 | /** @brief Persistent sdbusplus D-Bus bus connection. */ | 
|  | 114 | sdbusplus::bus::bus& bus; | 
|  | 115 |  | 
|  | 116 | /** @brief Persistent map of Activation D-Bus objects and their | 
|  | 117 | * version id */ | 
|  | 118 | std::map<std::string, std::unique_ptr<Activation>> activations; | 
|  | 119 |  | 
|  | 120 | /** @brief Persistent map of Version D-Bus objects and their | 
|  | 121 | * version id */ | 
|  | 122 | std::map<std::string, std::unique_ptr<Version>> versions; | 
|  | 123 |  | 
|  | 124 | /** @brief sdbusplus signal match for Software.Version */ | 
|  | 125 | sdbusplus::bus::match_t versionMatch; | 
| Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 126 |  | 
|  | 127 | /** @brief This entry's associations */ | 
|  | 128 | AssociationList assocs; | 
| Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 129 | }; | 
|  | 130 |  | 
|  | 131 | } // namespace updater | 
|  | 132 | } // namespace software | 
|  | 133 | } // namespace phosphor |