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 | ef4781f | 2017-04-19 11:28:24 -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 |
| 24 | * DBus API. |
| 25 | */ |
| 26 | class Version : public VersionInherit |
| 27 | { |
| 28 | public: |
| 29 | /** @brief Constructs Version Software Manager |
| 30 | * |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 31 | * @param[in] bus - The Dbus bus object |
| 32 | * @param[in] objPath - The Dbus object path |
| 33 | * @param[in] versionId - The version identifier |
| 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 | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 39 | const std::string& versionId, |
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( |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 42 | bus, (objPath).c_str(), true), versionStr(versionId) |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 43 | { |
| 44 | // Set properties. |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 45 | purpose(versionPurpose); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 46 | version(versionId); |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 47 | path(filePath); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 48 | // Emit deferred signal. |
| 49 | emit_object_added(); |
| 50 | } |
| 51 | |
| 52 | /** |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 53 | * @brief Read the manifest file to get the value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 54 | * |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 55 | * @return The value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 56 | **/ |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 57 | static std::string getValue(const std::string& manifestFilePath, |
| 58 | std::string key); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 59 | |
| 60 | /** |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 61 | * @brief Get the Version id. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 62 | * |
| 63 | * @return The id. |
| 64 | **/ |
| 65 | static std::string getId(const std::string& version); |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 66 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 67 | /** |
| 68 | * @brief Get the active bmc version identifier. |
| 69 | * |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 70 | * @param[in] releaseFilePath - The Path to file which contains |
| 71 | * the release version. |
| 72 | * |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 73 | * @return The version identifier. |
| 74 | */ |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 75 | static std::string getBMCVersion(const std::string& releaseFilePath); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 76 | |
| 77 | /* @brief Check if this version matches the currently running version |
| 78 | * |
| 79 | * @return - Returns true if this version matches the currently running |
| 80 | * version. |
| 81 | */ |
| 82 | bool isFunctional(); |
| 83 | |
| 84 | private: |
| 85 | /** @brief This Version's version string */ |
| 86 | const std::string versionStr; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace manager |
| 90 | } // namespace software |
| 91 | } // namespace phosphor |