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