Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Common/FilePath/server.hpp" |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 6 | #include <functional> |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace software |
| 11 | { |
| 12 | namespace manager |
| 13 | { |
| 14 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 15 | typedef std::function<void(std::string)> eraseFunc; |
| 16 | |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 17 | using VersionInherit = sdbusplus::server::object::object< |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 18 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 19 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 20 | |
| 21 | /** @class Version |
| 22 | * @brief OpenBMC version software management implementation. |
| 23 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 24 | * D-Bus API. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 25 | */ |
| 26 | class Version : public VersionInherit |
| 27 | { |
| 28 | public: |
| 29 | /** @brief Constructs Version Software Manager |
| 30 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 31 | * @param[in] bus - The D-Bus bus object |
| 32 | * @param[in] objPath - The D-Bus object path |
| 33 | * @param[in] versionString - The version string |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 34 | * @param[in] versionPurpose - The version purpose |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 35 | * @param[in] filePath - The image filesystem path |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 36 | */ |
| 37 | Version(sdbusplus::bus::bus& bus, |
| 38 | const std::string& objPath, |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 39 | const std::string& versionString, |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 40 | VersionPurpose versionPurpose, |
Eddie James | 9440f49 | 2017-08-30 11:34:16 -0500 | [diff] [blame] | 41 | const std::string& filePath) : VersionInherit( |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 42 | bus, (objPath).c_str(), true), |
| 43 | versionStr(versionString) |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 44 | { |
| 45 | // Set properties. |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 46 | purpose(versionPurpose); |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 47 | version(versionString); |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 48 | path(filePath); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 49 | // Emit deferred signal. |
| 50 | emit_object_added(); |
| 51 | } |
| 52 | |
| 53 | /** |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 54 | * @brief Read the manifest file to get the value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 55 | * |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 56 | * @return The value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 57 | **/ |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 58 | static std::string getValue(const std::string& manifestFilePath, |
| 59 | std::string key); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 60 | |
| 61 | /** |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 62 | * @brief Calculate the version id from the version string. |
| 63 | * |
| 64 | * @details The version id is a unique 8 hexadecimal digit id |
| 65 | * calculated from the version string. |
| 66 | * |
| 67 | * @param[in] version - The image's version string (e.g. v1.99.10-19). |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 68 | * |
| 69 | * @return The id. |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 70 | */ |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 71 | static std::string getId(const std::string& version); |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 72 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 73 | /** |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 74 | * @brief Get the active BMC version string. |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 75 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 76 | * @param[in] releaseFilePath - The path to the file which contains |
| 77 | * the release version string. |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 78 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame^] | 79 | * @return The version string (e.g. v1.99.10-19). |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 80 | */ |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 81 | static std::string getBMCVersion(const std::string& releaseFilePath); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 82 | |
| 83 | /* @brief Check if this version matches the currently running version |
| 84 | * |
| 85 | * @return - Returns true if this version matches the currently running |
| 86 | * version. |
| 87 | */ |
| 88 | bool isFunctional(); |
| 89 | |
| 90 | private: |
| 91 | /** @brief This Version's version string */ |
| 92 | const std::string versionStr; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace manager |
| 96 | } // namespace software |
| 97 | } // namespace phosphor |