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