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" |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 7 | #include <functional> |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace software |
| 12 | { |
| 13 | namespace manager |
| 14 | { |
| 15 | |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 16 | typedef std::function<void(std::string)> eraseFunc; |
| 17 | |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 18 | using VersionInherit = sdbusplus::server::object::object< |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 19 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 20 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 21 | using DeleteInherit = sdbusplus::server::object::object< |
| 22 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
| 23 | |
| 24 | class Version; |
| 25 | class Delete; |
| 26 | |
| 27 | /** @class Delete |
| 28 | * @brief OpenBMC Delete implementation. |
| 29 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 30 | * D-Bus API. |
| 31 | */ |
| 32 | class Delete : public DeleteInherit |
| 33 | { |
| 34 | public: |
| 35 | /** @brief Constructs Delete. |
| 36 | * |
| 37 | * @param[in] bus - The D-Bus bus object |
| 38 | * @param[in] path - The D-Bus object path |
| 39 | * @param[in] parent - Parent object. |
| 40 | */ |
| 41 | Delete(sdbusplus::bus::bus& bus, |
| 42 | const std::string& path, |
| 43 | Version& parent) : |
| 44 | DeleteInherit(bus, path.c_str(), true), |
| 45 | parent(parent), |
| 46 | bus(bus), |
| 47 | path(path) |
| 48 | { |
| 49 | std::vector<std::string> interfaces({interface}); |
| 50 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 51 | } |
| 52 | |
| 53 | ~Delete() |
| 54 | { |
| 55 | std::vector<std::string> interfaces({interface}); |
| 56 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 57 | } |
| 58 | |
| 59 | /** @brief delete the D-Bus object. */ |
| 60 | void delete_() override; |
| 61 | |
| 62 | private: |
| 63 | |
| 64 | /** @brief Parent Object. */ |
| 65 | Version& parent; |
| 66 | |
| 67 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 68 | static constexpr auto interface = |
| 69 | "xyz.openbmc_project.Object.Delete"; |
| 70 | sdbusplus::bus::bus& bus; |
| 71 | std::string path; |
| 72 | }; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 73 | |
| 74 | /** @class Version |
| 75 | * @brief OpenBMC version software management implementation. |
| 76 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 77 | * D-Bus API. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 78 | */ |
| 79 | class Version : public VersionInherit |
| 80 | { |
| 81 | public: |
| 82 | /** @brief Constructs Version Software Manager |
| 83 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 84 | * @param[in] bus - The D-Bus bus object |
| 85 | * @param[in] objPath - The D-Bus object path |
| 86 | * @param[in] versionString - The version string |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 87 | * @param[in] versionPurpose - The version purpose |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 88 | * @param[in] filePath - The image filesystem path |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 89 | * @param[in] callback - The eraseFunc callback |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 90 | */ |
| 91 | Version(sdbusplus::bus::bus& bus, |
| 92 | const std::string& objPath, |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 93 | const std::string& versionString, |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 94 | VersionPurpose versionPurpose, |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 95 | const std::string& filePath, |
| 96 | eraseFunc callback) : VersionInherit( |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 97 | bus, (objPath).c_str(), true), |
| 98 | versionStr(versionString) |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 99 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 100 | // Bind erase method |
| 101 | eraseCallback = callback; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 102 | // Set properties. |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 103 | purpose(versionPurpose); |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 104 | version(versionString); |
Gunnar Mills | ef4781f | 2017-04-19 11:28:24 -0500 | [diff] [blame] | 105 | path(filePath); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 106 | // Emit deferred signal. |
| 107 | emit_object_added(); |
| 108 | } |
| 109 | |
| 110 | /** |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 111 | * @brief Read the manifest file to get the value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 112 | * |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 113 | * @return The value of the key. |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 114 | **/ |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 115 | static std::string getValue(const std::string& manifestFilePath, |
| 116 | std::string key); |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 117 | |
| 118 | /** |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [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 | * |
| 124 | * @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] | 125 | * |
| 126 | * @return The id. |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 127 | */ |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 128 | static std::string getId(const std::string& version); |
Gunnar Mills | cebd102 | 2017-04-17 16:10:15 -0500 | [diff] [blame] | 129 | |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 130 | /** |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 131 | * @brief Get the active BMC version string. |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 132 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 133 | * @param[in] releaseFilePath - The path to the file which contains |
| 134 | * the release version string. |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 135 | * |
Gunnar Mills | a4fcb68 | 2017-10-06 13:14:12 -0500 | [diff] [blame] | 136 | * @return The version string (e.g. v1.99.10-19). |
Saqib Khan | ba23988 | 2017-05-26 08:41:54 -0500 | [diff] [blame] | 137 | */ |
Saqib Khan | 1eef62d | 2017-08-10 15:29:34 -0500 | [diff] [blame] | 138 | static std::string getBMCVersion(const std::string& releaseFilePath); |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 139 | |
| 140 | /* @brief Check if this version matches the currently running version |
| 141 | * |
| 142 | * @return - Returns true if this version matches the currently running |
| 143 | * version. |
| 144 | */ |
| 145 | bool isFunctional(); |
| 146 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 147 | /** @brief Persistent Delete D-Bus object */ |
| 148 | std::unique_ptr<Delete> deleteObject; |
| 149 | |
| 150 | /** @brief The parent's erase callback. */ |
| 151 | eraseFunc eraseCallback; |
| 152 | |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 153 | private: |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 154 | |
Eddie James | 6d87371 | 2017-09-01 11:29:07 -0500 | [diff] [blame] | 155 | /** @brief This Version's version string */ |
| 156 | const std::string versionStr; |
Gunnar Mills | 392f294 | 2017-04-12 11:04:37 -0500 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | } // namespace manager |
| 160 | } // namespace software |
| 161 | } // namespace phosphor |