Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 3 | #include "xyz/openbmc_project/Common/FilePath/server.hpp" |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 4 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
| 7 | |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
Adriana Kobylak | 58aa750 | 2020-06-08 11:12:11 -0500 | [diff] [blame] | 9 | |
| 10 | #include <functional> |
Andrew Geissler | 9155b71 | 2020-05-16 13:04:44 -0500 | [diff] [blame] | 11 | #include <string> |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace software |
| 16 | { |
| 17 | namespace manager |
| 18 | { |
| 19 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 20 | typedef std::function<void(std::string)> eraseFunc; |
| 21 | |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 22 | using VersionInherit = sdbusplus::server::object::object< |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 23 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 25 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 26 | using DeleteInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 27 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 28 | |
| 29 | class Version; |
| 30 | class Delete; |
| 31 | |
| 32 | /** @class Delete |
| 33 | * @brief OpenBMC Delete implementation. |
| 34 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 35 | * D-Bus API. |
| 36 | */ |
| 37 | class Delete : public DeleteInherit |
| 38 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 39 | public: |
| 40 | /** @brief Constructs Delete. |
| 41 | * |
| 42 | * @param[in] bus - The D-Bus bus object |
| 43 | * @param[in] path - The D-Bus object path |
| 44 | * @param[in] parent - Parent object. |
| 45 | */ |
| 46 | Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) : |
Lei YU | 29d84b0 | 2020-02-13 15:13:09 +0800 | [diff] [blame] | 47 | DeleteInherit(bus, path.c_str(), action::emit_interface_added), |
| 48 | parent(parent) |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 49 | { |
Lei YU | 29d84b0 | 2020-02-13 15:13:09 +0800 | [diff] [blame] | 50 | // Empty |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 51 | } |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 52 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 53 | /** @brief delete the D-Bus object. */ |
| 54 | void delete_() override; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 55 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 56 | private: |
| 57 | /** @brief Parent Object. */ |
| 58 | Version& parent; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 59 | }; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 60 | |
| 61 | /** @class Version |
| 62 | * @brief OpenBMC version software management implementation. |
| 63 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 64 | * D-Bus API. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 65 | */ |
| 66 | class Version : public VersionInherit |
| 67 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 68 | public: |
| 69 | /** @brief Constructs Version Software Manager |
| 70 | * |
| 71 | * @param[in] bus - The D-Bus bus object |
| 72 | * @param[in] objPath - The D-Bus object path |
| 73 | * @param[in] versionString - The version string |
| 74 | * @param[in] versionPurpose - The version purpose |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 75 | * @param[in] extVersion - The extended version |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 76 | * @param[in] filePath - The image filesystem path |
| 77 | * @param[in] callback - The eraseFunc callback |
| 78 | */ |
| 79 | Version(sdbusplus::bus::bus& bus, const std::string& objPath, |
| 80 | const std::string& versionString, VersionPurpose versionPurpose, |
Lei YU | b412bd1 | 2021-03-23 20:01:28 +0800 | [diff] [blame] | 81 | const std::string& extVersion, const std::string& filePath, |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 82 | eraseFunc callback, const std::string& id) : |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 83 | VersionInherit(bus, (objPath).c_str(), true), |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 84 | eraseCallback(callback), id(id), versionStr(versionString) |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 85 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 86 | // Set properties. |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 87 | extendedVersion(extVersion); |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 88 | purpose(versionPurpose); |
| 89 | version(versionString); |
| 90 | path(filePath); |
| 91 | // Emit deferred signal. |
| 92 | emit_object_added(); |
| 93 | } |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 94 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 95 | /** |
| 96 | * @brief Read the manifest file to get the value of the key. |
| 97 | * |
| 98 | * @return The value of the key. |
| 99 | **/ |
| 100 | static std::string getValue(const std::string& manifestFilePath, |
| 101 | std::string key); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 102 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 103 | /** |
| 104 | * @brief Calculate the version id from the version string. |
| 105 | * |
| 106 | * @details The version id is a unique 8 hexadecimal digit id |
| 107 | * calculated from the version string. |
| 108 | * |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 109 | * @param[in] versionWithSalt - The image's version string |
| 110 | * (e.g. v1.99.10-19) plus an optional salt |
| 111 | * string. |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 112 | * |
| 113 | * @return The id. |
| 114 | */ |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 115 | static std::string getId(const std::string& versionWithSalt); |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 116 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 117 | /** |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 118 | * @brief Get the active BMC machine name string. |
| 119 | * |
| 120 | * @param[in] releaseFilePath - The path to the file which contains |
| 121 | * the release machine string. |
| 122 | * |
| 123 | * @return The machine name string (e.g. romulus, tiogapass). |
| 124 | */ |
| 125 | static std::string getBMCMachine(const std::string& releaseFilePath); |
| 126 | |
| 127 | /** |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 128 | * @brief Get the BMC Extended Version string. |
| 129 | * |
| 130 | * @param[in] releaseFilePath - The path to the file which contains |
| 131 | * the release machine string. |
| 132 | * |
| 133 | * @return The extended version string. |
| 134 | */ |
| 135 | static std::string |
| 136 | getBMCExtendedVersion(const std::string& releaseFilePath); |
| 137 | |
| 138 | /** |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 139 | * @brief Get the active BMC version string. |
| 140 | * |
| 141 | * @param[in] releaseFilePath - The path to the file which contains |
| 142 | * the release version string. |
| 143 | * |
| 144 | * @return The version string (e.g. v1.99.10-19). |
| 145 | */ |
| 146 | static std::string getBMCVersion(const std::string& releaseFilePath); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 147 | |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 148 | /* @brief Check if this version is functional. |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 149 | * |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 150 | * @return - Returns the functional value. |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 151 | */ |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 152 | bool isFunctional() const |
| 153 | { |
| 154 | return functional; |
| 155 | } |
| 156 | |
| 157 | /** @brief Set the functional value. |
| 158 | * @param[in] value - True or False |
| 159 | */ |
| 160 | void setFunctional(bool value) |
| 161 | { |
| 162 | functional = value; |
| 163 | } |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 164 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 165 | /** @brief Persistent Delete D-Bus object */ |
| 166 | std::unique_ptr<Delete> deleteObject; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 167 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 168 | /** @brief The parent's erase callback. */ |
| 169 | eraseFunc eraseCallback; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 170 | |
Adriana Kobylak | 59b640b | 2022-01-21 19:45:22 +0000 | [diff] [blame] | 171 | /** @brief The version ID of the object */ |
| 172 | const std::string id; |
| 173 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 174 | private: |
| 175 | /** @brief This Version's version string */ |
| 176 | const std::string versionStr; |
Adriana Kobylak | 1e81f23 | 2022-01-18 22:28:47 +0000 | [diff] [blame] | 177 | |
| 178 | /** @brief If this version is the functional one */ |
| 179 | bool functional = false; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | } // namespace manager |
| 183 | } // namespace software |
| 184 | } // namespace phosphor |