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