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