Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Common/FilePath/server.hpp" |
| 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace software |
| 11 | { |
| 12 | namespace updater |
| 13 | { |
| 14 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 15 | class ItemUpdater; |
| 16 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 17 | using VersionInherit = sdbusplus::server::object::object< |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 18 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 19 | sdbusplus::xyz::openbmc_project::Object::server::Delete, |
| 20 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 21 | |
| 22 | /** @class Version |
| 23 | * @brief OpenBMC version software management implementation. |
| 24 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 25 | * D-Bus API. |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 26 | */ |
| 27 | class Version : public VersionInherit |
| 28 | { |
| 29 | public: |
| 30 | /** @brief Constructs Version Software Manager. |
| 31 | * |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 32 | * @param[in] bus - The D-Bus bus object |
| 33 | * @param[in] objPath - The D-Bus object path |
| 34 | * @param[in] versionString - The version string |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 35 | * @param[in] versionPurpose - The version purpose |
| 36 | * @param[in] filePath - The image filesystem path |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 37 | * @param[in] parent - The version's parent |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 38 | */ |
| 39 | Version(sdbusplus::bus::bus& bus, |
| 40 | const std::string& objPath, |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 41 | const std::string& versionString, |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 42 | VersionPurpose versionPurpose, |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 43 | const std::string& filePath, |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 44 | ItemUpdater& parent) : |
| 45 | VersionInherit(bus, (objPath).c_str(), true), |
| 46 | parent(parent) |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 47 | { |
| 48 | // Set properties. |
| 49 | purpose(versionPurpose); |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 50 | version(versionString); |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 51 | path(filePath); |
| 52 | |
| 53 | // Emit deferred signal. |
| 54 | emit_object_added(); |
| 55 | } |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * @brief Read the manifest file to get the value of the key. |
| 59 | * |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 60 | * @param[in] filePath - The path to the file which contains the value |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 61 | * of keys. |
| 62 | * @param[in] keys - A map of keys with empty values. |
| 63 | * |
| 64 | * @return The map of keys with filled values. |
| 65 | **/ |
| 66 | static std::map<std::string, std::string> getValue( |
| 67 | const std::string& filePath, |
| 68 | std::map<std::string, std::string> keys); |
| 69 | |
| 70 | /** |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 71 | * @brief Calculate the version id from the version string. |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 72 | * |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 73 | * @details The version id is a unique 8 hexadecimal digit id |
| 74 | * calculated from the version string. |
| 75 | * |
| 76 | * @param[in] version - The image version string (e.g. v1.99.10-19). |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 77 | * |
| 78 | * @return The id. |
| 79 | */ |
| 80 | static std::string getId(const std::string& version); |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 81 | |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame^] | 82 | /** @brief Deletes the D-Bus object and removes image. |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 83 | * |
| 84 | */ |
| 85 | void delete_() override; |
| 86 | |
| 87 | private: |
| 88 | ItemUpdater& parent; |
| 89 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace updater |
| 93 | } // namespace software |
| 94 | } // namespace openpower |