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