1 #pragma once 2 3 #include "config.h" 4 5 #include <sdbusplus/bus.hpp> 6 #include <xyz/openbmc_project/Common/FilePath/server.hpp> 7 #include <xyz/openbmc_project/Object/Delete/server.hpp> 8 #include <xyz/openbmc_project/Software/Version/server.hpp> 9 10 namespace phosphor 11 { 12 namespace software 13 { 14 namespace updater 15 { 16 17 using eraseFunc = std::function<void(std::string)>; 18 19 using VersionInherit = sdbusplus::server::object::object< 20 sdbusplus::xyz::openbmc_project::Software::server::Version, 21 sdbusplus::xyz::openbmc_project::Common::server::FilePath>; 22 using DeleteInherit = sdbusplus::server::object::object< 23 sdbusplus::xyz::openbmc_project::Object::server::Delete>; 24 25 namespace sdbusRule = sdbusplus::bus::match::rules; 26 27 class Version; 28 29 /** @class Delete 30 * @brief OpenBMC Delete implementation. 31 * @details A concrete implementation for xyz.openbmc_project.Object.Delete 32 * D-Bus API. 33 */ 34 class Delete : public DeleteInherit 35 { 36 public: 37 /** @brief Constructs Delete. 38 * 39 * @param[in] bus - The D-Bus bus object 40 * @param[in] path - The D-Bus object path 41 * @param[in] version - The Version object. 42 */ 43 Delete(sdbusplus::bus::bus& bus, const std::string& path, 44 Version& version) : 45 DeleteInherit(bus, path.c_str(), true), 46 version(version), bus(bus), path(path) 47 { 48 std::vector<std::string> interfaces({interface}); 49 bus.emit_interfaces_added(path.c_str(), interfaces); 50 } 51 52 ~Delete() 53 { 54 std::vector<std::string> interfaces({interface}); 55 bus.emit_interfaces_removed(path.c_str(), interfaces); 56 } 57 58 /** 59 * @brief Delete the D-Bus object. 60 * Overrides the default delete function by calling 61 * Version class erase Method. 62 **/ 63 void delete_() override; 64 65 private: 66 /** @brief The Version Object. */ 67 Version& version; 68 69 static constexpr auto interface = "xyz.openbmc_project.Object.Delete"; 70 sdbusplus::bus::bus& bus; 71 std::string path; 72 }; 73 74 /** @class Version 75 * @brief OpenBMC version software management implementation. 76 * @details A concrete implementation for xyz.openbmc_project.Software.Version 77 * D-Bus API. 78 */ 79 class Version : public VersionInherit 80 { 81 public: 82 /** @brief Constructs Version Software Manager. 83 * 84 * @param[in] bus - The D-Bus bus object 85 * @param[in] objPath - The D-Bus object path 86 * @param[in] versionId - The version Id 87 * @param[in] versionString - The version string 88 * @param[in] versionPurpose - The version purpose 89 * @param[in] filePath - The image filesystem path 90 * @param[in] callback - The eraseFunc callback 91 */ 92 Version(sdbusplus::bus::bus& bus, const std::string& objPath, 93 const std::string& versionId, const std::string& versionString, 94 VersionPurpose versionPurpose, const std::string& filePath, 95 eraseFunc callback) : 96 VersionInherit(bus, (objPath).c_str(), true), 97 eraseCallback(callback), bus(bus), objPath(objPath), 98 versionId(versionId), versionStr(versionString) 99 { 100 // Set properties. 101 purpose(versionPurpose); 102 version(versionString); 103 path(filePath); 104 105 deleteObject = std::make_unique<Delete>(bus, objPath, *this); 106 107 // Emit deferred signal. 108 emit_object_added(); 109 } 110 111 /** 112 * @brief Return the version id 113 */ 114 std::string getVersionId() const 115 { 116 return versionId; 117 } 118 119 /** 120 * @brief Read the manifest file to get the value of the key. 121 * 122 * @param[in] filePath - The path to the file which contains the value 123 * of keys. 124 * @param[in] keys - A vector of keys. 125 * 126 * @return The map of keys with filled values. 127 **/ 128 static std::map<std::string, std::string> 129 getValues(const std::string& filePath, 130 const std::vector<std::string>& keys); 131 132 /** @brief Get information from extVersion 133 * 134 * @param[in] extVersion - The extended version string that contains 135 * key/value pairs separated by comma. 136 * 137 * @return The map of key/value pairs 138 */ 139 static std::map<std::string, std::string> 140 getExtVersionInfo(const std::string& extVersion); 141 142 /** @brief The temUpdater's erase callback. */ 143 eraseFunc eraseCallback; 144 145 private: 146 /** @brief Persistent sdbusplus DBus bus connection */ 147 sdbusplus::bus::bus& bus; 148 149 /** @brief Persistent DBus object path */ 150 std::string objPath; 151 152 /** @brief This Version's version Id */ 153 const std::string versionId; 154 155 /** @brief This Version's version string */ 156 const std::string versionStr; 157 158 /** @brief Persistent Delete D-Bus object */ 159 std::unique_ptr<Delete> deleteObject; 160 }; 161 162 } // namespace updater 163 } // namespace software 164 } // namespace phosphor 165