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, |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 82 | eraseFunc callback) : |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 83 | VersionInherit(bus, (objPath).c_str(), true), |
Adriana Kobylak | 292159f | 2020-05-05 09:25:55 -0500 | [diff] [blame] | 84 | eraseCallback(callback), 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 | * |
| 109 | * @param[in] version - The image's version string (e.g. v1.99.10-19). |
| 110 | * |
| 111 | * @return The id. |
| 112 | */ |
| 113 | static std::string getId(const std::string& version); |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 114 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 115 | /** |
Vijay Khemka | b7c062e | 2019-09-18 17:15:57 -0700 | [diff] [blame] | 116 | * @brief Get the active BMC machine name string. |
| 117 | * |
| 118 | * @param[in] releaseFilePath - The path to the file which contains |
| 119 | * the release machine string. |
| 120 | * |
| 121 | * @return The machine name string (e.g. romulus, tiogapass). |
| 122 | */ |
| 123 | static std::string getBMCMachine(const std::string& releaseFilePath); |
| 124 | |
| 125 | /** |
Chanh Nguyen | 1fd6ddd | 2021-01-06 11:09:09 +0700 | [diff] [blame] | 126 | * @brief Get the BMC Extended Version string. |
| 127 | * |
| 128 | * @param[in] releaseFilePath - The path to the file which contains |
| 129 | * the release machine string. |
| 130 | * |
| 131 | * @return The extended version string. |
| 132 | */ |
| 133 | static std::string |
| 134 | getBMCExtendedVersion(const std::string& releaseFilePath); |
| 135 | |
| 136 | /** |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 137 | * @brief Get the active BMC version string. |
| 138 | * |
| 139 | * @param[in] releaseFilePath - The path to the file which contains |
| 140 | * the release version string. |
| 141 | * |
| 142 | * @return The version string (e.g. v1.99.10-19). |
| 143 | */ |
| 144 | static std::string getBMCVersion(const std::string& releaseFilePath); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 145 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 146 | /* @brief Check if this version matches the currently running version |
| 147 | * |
| 148 | * @return - Returns true if this version matches the currently running |
| 149 | * version. |
| 150 | */ |
| 151 | bool isFunctional(); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 152 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 153 | /** @brief Persistent Delete D-Bus object */ |
| 154 | std::unique_ptr<Delete> deleteObject; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 155 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 156 | /** @brief The parent's erase callback. */ |
| 157 | eraseFunc eraseCallback; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 158 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 159 | private: |
| 160 | /** @brief This Version's version string */ |
| 161 | const std::string versionStr; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } // namespace manager |
| 165 | } // namespace software |
| 166 | } // namespace phosphor |