Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
| 7 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace software |
| 12 | { |
| 13 | namespace updater |
| 14 | { |
| 15 | |
| 16 | using eraseFunc = std::function<void(std::string)>; |
| 17 | |
| 18 | using VersionInherit = sdbusplus::server::object::object< |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::Software::server::Version>; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 20 | using DeleteInherit = sdbusplus::server::object::object< |
| 21 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
| 22 | |
| 23 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 24 | |
| 25 | class Version; |
| 26 | |
| 27 | /** @class Delete |
| 28 | * @brief OpenBMC Delete implementation. |
| 29 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 30 | * D-Bus API. |
| 31 | */ |
| 32 | class Delete : public DeleteInherit |
| 33 | { |
| 34 | public: |
| 35 | /** @brief Constructs Delete. |
| 36 | * |
| 37 | * @param[in] bus - The D-Bus bus object |
| 38 | * @param[in] path - The D-Bus object path |
| 39 | * @param[in] version - The Version object. |
| 40 | */ |
| 41 | Delete(sdbusplus::bus::bus& bus, const std::string& path, |
| 42 | Version& version) : |
| 43 | DeleteInherit(bus, path.c_str(), true), |
| 44 | version(version), bus(bus), path(path) |
| 45 | { |
| 46 | std::vector<std::string> interfaces({interface}); |
| 47 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 48 | } |
| 49 | |
| 50 | ~Delete() |
| 51 | { |
| 52 | std::vector<std::string> interfaces({interface}); |
| 53 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @brief Delete the D-Bus object. |
| 58 | * Overrides the default delete function by calling |
| 59 | * Version class erase Method. |
| 60 | **/ |
| 61 | void delete_() override; |
| 62 | |
| 63 | private: |
| 64 | /** @brief The Version Object. */ |
| 65 | Version& version; |
| 66 | |
| 67 | static constexpr auto interface = "xyz.openbmc_project.Object.Delete"; |
| 68 | sdbusplus::bus::bus& bus; |
| 69 | std::string path; |
| 70 | }; |
| 71 | |
| 72 | /** @class Version |
| 73 | * @brief OpenBMC version software management implementation. |
| 74 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
| 75 | * D-Bus API. |
| 76 | */ |
| 77 | class Version : public VersionInherit |
| 78 | { |
| 79 | public: |
| 80 | /** @brief Constructs Version Software Manager. |
| 81 | * |
| 82 | * @param[in] bus - The D-Bus bus object |
| 83 | * @param[in] objPath - The D-Bus object path |
| 84 | * @param[in] versionId - The version Id |
| 85 | * @param[in] versionString - The version string |
| 86 | * @param[in] versionPurpose - The version purpose |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 87 | * @param[in] callback - The eraseFunc callback |
| 88 | */ |
| 89 | Version(sdbusplus::bus::bus& bus, const std::string& objPath, |
| 90 | const std::string& versionId, const std::string& versionString, |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 91 | VersionPurpose versionPurpose, eraseFunc callback) : |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 92 | VersionInherit(bus, (objPath).c_str(), true), |
| 93 | eraseCallback(callback), bus(bus), objPath(objPath), |
| 94 | versionId(versionId), versionStr(versionString) |
| 95 | { |
| 96 | // Set properties. |
| 97 | purpose(versionPurpose); |
| 98 | version(versionString); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 99 | |
| 100 | deleteObject = std::make_unique<Delete>(bus, objPath, *this); |
| 101 | |
| 102 | // Emit deferred signal. |
| 103 | emit_object_added(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @brief Return the version id |
| 108 | */ |
| 109 | std::string getVersionId() const |
| 110 | { |
| 111 | return versionId; |
| 112 | } |
| 113 | |
| 114 | /** |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 115 | * @brief Read the manifest file to get the values of the keys. |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 116 | * |
| 117 | * @param[in] filePath - The path to the file which contains the value |
| 118 | * of keys. |
Lei YU | fda15a3 | 2019-09-19 14:43:02 +0800 | [diff] [blame] | 119 | * @param[in] keys - A vector of keys. |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 120 | * |
| 121 | * @return The map of keys with filled values. |
| 122 | **/ |
| 123 | static std::map<std::string, std::string> |
Lei YU | fda15a3 | 2019-09-19 14:43:02 +0800 | [diff] [blame] | 124 | getValues(const std::string& filePath, |
| 125 | const std::vector<std::string>& keys); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 126 | |
Lei YU | 58c26e3 | 2019-09-27 17:52:06 +0800 | [diff] [blame] | 127 | /** |
| 128 | * @brief Read the manifest file to get the value of the key. |
| 129 | * |
| 130 | * @param[in] filePath - The path to the file which contains the value |
| 131 | * of keys. |
| 132 | * @param[in] key - The string of the key. |
| 133 | * |
| 134 | * @return The string of the value. |
| 135 | **/ |
| 136 | static std::string getValue(const std::string& filePath, |
| 137 | const std::string& key); |
| 138 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 139 | /** @brief Get information from extVersion |
| 140 | * |
| 141 | * @param[in] extVersion - The extended version string that contains |
| 142 | * key/value pairs separated by comma. |
| 143 | * |
| 144 | * @return The map of key/value pairs |
| 145 | */ |
| 146 | static std::map<std::string, std::string> |
| 147 | getExtVersionInfo(const std::string& extVersion); |
| 148 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 149 | /** @brief The temUpdater's erase callback. */ |
| 150 | eraseFunc eraseCallback; |
| 151 | |
Lei YU | 1517f5f | 2019-10-14 16:44:42 +0800 | [diff] [blame^] | 152 | /** @brief Get the version string. */ |
| 153 | const std::string& getVersionString() const |
| 154 | { |
| 155 | return versionStr; |
| 156 | } |
| 157 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 158 | private: |
| 159 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 160 | sdbusplus::bus::bus& bus; |
| 161 | |
| 162 | /** @brief Persistent DBus object path */ |
| 163 | std::string objPath; |
| 164 | |
| 165 | /** @brief This Version's version Id */ |
| 166 | const std::string versionId; |
| 167 | |
| 168 | /** @brief This Version's version string */ |
| 169 | const std::string versionStr; |
Lei YU | f77189f | 2019-08-07 14:26:30 +0800 | [diff] [blame] | 170 | |
| 171 | /** @brief Persistent Delete D-Bus object */ |
| 172 | std::unique_ptr<Delete> deleteObject; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | } // namespace updater |
| 176 | } // namespace software |
| 177 | } // namespace phosphor |