Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Common/FilePath/server.hpp" |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Object/Delete/server.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
| 8 | |
| 9 | #include <sdbusplus/bus.hpp> |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 10 | |
Andrew Geissler | ab139ce | 2020-05-16 13:22:09 -0500 | [diff] [blame] | 11 | #include <string> |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 12 | |
| 13 | namespace openpower |
| 14 | { |
| 15 | namespace software |
| 16 | { |
| 17 | namespace updater |
| 18 | { |
| 19 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 20 | class ItemUpdater; |
| 21 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 22 | typedef std::function<void(std::string)> eraseFunc; |
| 23 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 24 | using VersionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 26 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 27 | using DeleteInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 28 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 29 | |
| 30 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 31 | |
| 32 | class Delete; |
| 33 | class Version; |
| 34 | |
| 35 | /** @class Delete |
| 36 | * @brief OpenBMC Delete implementation. |
| 37 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 38 | * D-Bus API. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 39 | */ |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 40 | class Delete : public DeleteInherit |
| 41 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 42 | public: |
| 43 | /** @brief Constructs Delete. |
| 44 | * |
| 45 | * @param[in] bus - The D-Bus bus object |
| 46 | * @param[in] path - The D-Bus object path |
| 47 | * @param[in] parent - Parent object. |
| 48 | */ |
| 49 | Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) : |
Albert Zhang | 7f1967d | 2020-03-02 14:12:08 +0800 | [diff] [blame] | 50 | DeleteInherit(bus, path.c_str(), action::emit_interface_added), |
| 51 | parent(parent) |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 52 | {} |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 53 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 54 | /** |
| 55 | * @brief Delete the D-Bus object. |
| 56 | * Overrides the default delete function by calling |
| 57 | * Version class erase Method. |
| 58 | **/ |
| 59 | void delete_() override; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 60 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 61 | private: |
| 62 | /** @brief Parent Object. */ |
| 63 | Version& parent; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 64 | }; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 65 | |
| 66 | /** @class Version |
| 67 | * @brief OpenBMC version software management implementation. |
| 68 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame] | 69 | * D-Bus API. |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 70 | */ |
| 71 | class Version : public VersionInherit |
| 72 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 73 | public: |
| 74 | /** @brief Constructs Version Software Manager. |
| 75 | * |
| 76 | * @param[in] bus - The D-Bus bus object |
| 77 | * @param[in] objPath - The D-Bus object path |
| 78 | * @param[in] parent - Parent object. |
| 79 | * @param[in] versionId - The version Id |
| 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 | ItemUpdater& parent, const std::string& versionId, |
| 87 | const std::string& versionString, VersionPurpose versionPurpose, |
| 88 | const std::string& filePath, eraseFunc callback) : |
| 89 | VersionInherit(bus, (objPath).c_str(), true), |
Lei YU | 1db9adf | 2019-03-05 16:02:31 +0800 | [diff] [blame] | 90 | eraseCallback(callback), bus(bus), objPath(objPath), parent(parent), |
| 91 | versionId(versionId), versionStr(versionString), |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 92 | chassisStateSignals( |
| 93 | bus, |
| 94 | sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") + |
| 95 | sdbusRule::path(CHASSIS_STATE_PATH) + |
| 96 | sdbusRule::argN(0, CHASSIS_STATE_OBJ) + |
| 97 | sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE), |
| 98 | std::bind(std::mem_fn(&Version::updateDeleteInterface), this, |
| 99 | std::placeholders::_1)) |
| 100 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 101 | // Set properties. |
| 102 | purpose(versionPurpose); |
| 103 | version(versionString); |
| 104 | path(filePath); |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 105 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 106 | // Emit deferred signal. |
| 107 | emit_object_added(); |
| 108 | } |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 109 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 110 | /** |
| 111 | * @brief Update the Object.Delete interface for this activation |
| 112 | * |
| 113 | * Update the delete interface based on whether or not this |
| 114 | * activation is currently functional. A functional activation |
| 115 | * will have no Object.Delete, while a non-functional activation |
| 116 | * will have one. |
| 117 | * |
| 118 | * @param[in] msg - Data associated with subscribed signal |
| 119 | */ |
| 120 | void updateDeleteInterface(sdbusplus::message::message& msg); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 121 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 122 | /** |
| 123 | * @brief Read the manifest file to get the value of the key. |
| 124 | * |
| 125 | * @param[in] filePath - The path to the file which contains the value |
| 126 | * of keys. |
| 127 | * @param[in] keys - A map of keys with empty values. |
| 128 | * |
| 129 | * @return The map of keys with filled values. |
| 130 | **/ |
| 131 | static std::map<std::string, std::string> |
| 132 | getValue(const std::string& filePath, |
| 133 | std::map<std::string, std::string> keys); |
Saqib Khan | 167601b | 2017-06-18 23:33:46 -0500 | [diff] [blame] | 134 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 135 | /** |
Lei YU | dec8cf9 | 2019-02-21 17:47:05 +0800 | [diff] [blame] | 136 | * @brief Get version and extended version from VERSION partition string. |
| 137 | * |
| 138 | * @param[in] versionPart - The string containing the VERSION partition. |
| 139 | * |
| 140 | * @return The pair contains the version and extended version. |
| 141 | **/ |
| 142 | static std::pair<std::string, std::string> |
| 143 | getVersions(const std::string& versionPart); |
| 144 | |
| 145 | /** |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 146 | * @brief Calculate the version id from the version string. |
| 147 | * |
| 148 | * @details The version id is a unique 8 hexadecimal digit id |
| 149 | * calculated from the version string. |
| 150 | * |
| 151 | * @param[in] version - The image version string (e.g. v1.99.10-19). |
| 152 | * |
| 153 | * @return The id. |
| 154 | */ |
| 155 | static std::string getId(const std::string& version); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 156 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 157 | /** @brief Persistent Delete D-Bus object */ |
| 158 | std::unique_ptr<Delete> deleteObject; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 159 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 160 | /** @brief The parent's erase callback. */ |
| 161 | eraseFunc eraseCallback; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 162 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 163 | private: |
| 164 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 165 | sdbusplus::bus::bus& bus; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 166 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 167 | /** @brief Persistent DBus object path */ |
| 168 | std::string objPath; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 169 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 170 | /** @brief Parent Object. */ |
| 171 | ItemUpdater& parent; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 172 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 173 | /** @brief This Version's version Id */ |
| 174 | const std::string versionId; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 175 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 176 | /** @brief This Version's version string */ |
| 177 | const std::string versionStr; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 178 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 179 | /** @brief Used to subscribe to chassis power state changes **/ |
| 180 | sdbusplus::bus::match_t chassisStateSignals; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | } // namespace updater |
| 184 | } // namespace software |
| 185 | } // namespace openpower |