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