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