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" |
| 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" |
| 7 | #include "config.h" |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 8 | |
| 9 | namespace openpower |
| 10 | { |
| 11 | namespace software |
| 12 | { |
| 13 | namespace updater |
| 14 | { |
| 15 | |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 16 | class ItemUpdater; |
| 17 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 18 | typedef std::function<void(std::string)> eraseFunc; |
| 19 | |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 20 | using VersionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Software::server::Version, |
| 22 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 23 | using DeleteInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 25 | |
| 26 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 27 | |
| 28 | class Delete; |
| 29 | class Version; |
| 30 | |
| 31 | /** @class Delete |
| 32 | * @brief OpenBMC Delete implementation. |
| 33 | * @details A concrete implementation for xyz.openbmc_project.Object.Delete |
| 34 | * D-Bus API. |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 35 | */ |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 36 | class Delete : public DeleteInherit |
| 37 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 38 | public: |
| 39 | /** @brief Constructs Delete. |
| 40 | * |
| 41 | * @param[in] bus - The D-Bus bus object |
| 42 | * @param[in] path - The D-Bus object path |
| 43 | * @param[in] parent - Parent object. |
| 44 | */ |
| 45 | Delete(sdbusplus::bus::bus& bus, const std::string& path, Version& parent) : |
| 46 | DeleteInherit(bus, path.c_str(), true), parent(parent), bus(bus), |
| 47 | path(path) |
| 48 | { |
| 49 | std::vector<std::string> interfaces({interface}); |
| 50 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 51 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 52 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 53 | ~Delete() |
| 54 | { |
| 55 | std::vector<std::string> interfaces({interface}); |
| 56 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 57 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 58 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 59 | /** |
| 60 | * @brief Delete the D-Bus object. |
| 61 | * Overrides the default delete function by calling |
| 62 | * Version class erase Method. |
| 63 | **/ |
| 64 | void delete_() override; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 65 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 66 | private: |
| 67 | /** @brief Parent Object. */ |
| 68 | Version& parent; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 69 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 70 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 71 | static constexpr auto interface = "xyz.openbmc_project.Object.Delete"; |
| 72 | sdbusplus::bus::bus& bus; |
| 73 | std::string path; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 74 | }; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 75 | |
| 76 | /** @class Version |
| 77 | * @brief OpenBMC version software management implementation. |
| 78 | * @details A concrete implementation for xyz.openbmc_project.Software.Version |
Gunnar Mills | b78dfa5 | 2017-09-21 16:05:22 -0500 | [diff] [blame] | 79 | * D-Bus API. |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 80 | */ |
| 81 | class Version : public VersionInherit |
| 82 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 83 | public: |
| 84 | /** @brief Constructs Version Software Manager. |
| 85 | * |
| 86 | * @param[in] bus - The D-Bus bus object |
| 87 | * @param[in] objPath - The D-Bus object path |
| 88 | * @param[in] parent - Parent object. |
| 89 | * @param[in] versionId - The version Id |
| 90 | * @param[in] versionString - The version string |
| 91 | * @param[in] versionPurpose - The version purpose |
| 92 | * @param[in] filePath - The image filesystem path |
| 93 | * @param[in] callback - The eraseFunc callback |
| 94 | */ |
| 95 | Version(sdbusplus::bus::bus& bus, const std::string& objPath, |
| 96 | ItemUpdater& parent, const std::string& versionId, |
| 97 | const std::string& versionString, VersionPurpose versionPurpose, |
| 98 | const std::string& filePath, eraseFunc callback) : |
| 99 | VersionInherit(bus, (objPath).c_str(), true), |
| 100 | bus(bus), objPath(objPath), parent(parent), versionId(versionId), |
| 101 | versionStr(versionString), |
| 102 | chassisStateSignals( |
| 103 | bus, |
| 104 | sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") + |
| 105 | sdbusRule::path(CHASSIS_STATE_PATH) + |
| 106 | sdbusRule::argN(0, CHASSIS_STATE_OBJ) + |
| 107 | sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE), |
| 108 | std::bind(std::mem_fn(&Version::updateDeleteInterface), this, |
| 109 | std::placeholders::_1)) |
| 110 | { |
| 111 | // Bind erase method |
| 112 | eraseCallback = callback; |
| 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 | /** |
| 148 | * @brief Calculate the version id from the version string. |
| 149 | * |
| 150 | * @details The version id is a unique 8 hexadecimal digit id |
| 151 | * calculated from the version string. |
| 152 | * |
| 153 | * @param[in] version - The image version string (e.g. v1.99.10-19). |
| 154 | * |
| 155 | * @return The id. |
| 156 | */ |
| 157 | static std::string getId(const std::string& version); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 158 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 159 | /** @brief Persistent Delete D-Bus object */ |
| 160 | std::unique_ptr<Delete> deleteObject; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 161 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 162 | /** @brief The parent's erase callback. */ |
| 163 | eraseFunc eraseCallback; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 164 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 165 | private: |
| 166 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 167 | sdbusplus::bus::bus& bus; |
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 DBus object path */ |
| 170 | std::string objPath; |
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 Parent Object. */ |
| 173 | ItemUpdater& parent; |
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 | /** @brief This Version's version Id */ |
| 176 | const std::string versionId; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 177 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 178 | /** @brief This Version's version string */ |
| 179 | const std::string versionStr; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 180 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 181 | /** @brief Used to subscribe to chassis power state changes **/ |
| 182 | sdbusplus::bus::match_t chassisStateSignals; |
Saqib Khan | ce14870 | 2017-06-11 12:01:58 -0500 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | } // namespace updater |
| 186 | } // namespace software |
| 187 | } // namespace openpower |