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