1 #pragma once 2 3 #include "config.h" 4 5 #include "xyz/openbmc_project/Common/FilePath/server.hpp" 6 #include "xyz/openbmc_project/Object/Delete/server.hpp" 7 #include "xyz/openbmc_project/Software/Version/server.hpp" 8 9 #include <sdbusplus/bus.hpp> 10 11 #include <string> 12 13 namespace openpower 14 { 15 namespace software 16 { 17 namespace updater 18 { 19 20 class ItemUpdater; 21 22 typedef std::function<void(std::string)> eraseFunc; 23 24 using VersionInherit = sdbusplus::server::object_t< 25 sdbusplus::xyz::openbmc_project::Software::server::Version, 26 sdbusplus::xyz::openbmc_project::Common::server::FilePath>; 27 using DeleteInherit = sdbusplus::server::object_t< 28 sdbusplus::xyz::openbmc_project::Object::server::Delete>; 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. 39 */ 40 class Delete : public DeleteInherit 41 { 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 */ Delete(sdbusplus::bus_t & bus,const std::string & path,Version & parent)49 Delete(sdbusplus::bus_t& bus, const std::string& path, Version& parent) : 50 DeleteInherit(bus, path.c_str(), action::emit_interface_added), 51 parent(parent) 52 {} 53 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; 60 61 private: 62 /** @brief Parent Object. */ 63 Version& parent; 64 }; 65 66 /** @class Version 67 * @brief OpenBMC version software management implementation. 68 * @details A concrete implementation for xyz.openbmc_project.Software.Version 69 * D-Bus API. 70 */ 71 class Version : public VersionInherit 72 { 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 */ Version(sdbusplus::bus_t & bus,const std::string & objPath,ItemUpdater & parent,const std::string & versionId,const std::string & versionString,VersionPurpose versionPurpose,const std::string & filePath,eraseFunc callback)85 Version(sdbusplus::bus_t& 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(), 90 VersionInherit::action::defer_emit), 91 eraseCallback(callback), bus(bus), objPath(objPath), parent(parent), 92 versionId(versionId), versionStr(versionString), 93 chassisStateSignals( 94 bus, 95 sdbusRule::type::signal() + sdbusRule::member("PropertiesChanged") + 96 sdbusRule::path(CHASSIS_STATE_PATH) + 97 sdbusRule::argN(0, CHASSIS_STATE_OBJ) + 98 sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE), 99 std::bind(std::mem_fn(&Version::updateDeleteInterface), this, 100 std::placeholders::_1)) 101 { 102 // Set properties. 103 purpose(versionPurpose); 104 version(versionString); 105 path(filePath); 106 107 // Emit deferred signal. 108 emit_object_added(); 109 } 110 111 /** 112 * @brief Update the Object.Delete interface for this activation 113 * 114 * Update the delete interface based on whether or not this 115 * activation is currently functional. A functional activation 116 * will have no Object.Delete, while a non-functional activation 117 * will have one. 118 * 119 * @param[in] msg - Data associated with subscribed signal 120 */ 121 void updateDeleteInterface(sdbusplus::message_t& msg); 122 123 /** 124 * @brief Read the manifest file to get the value of the key. 125 * 126 * @param[in] filePath - The path to the file which contains the value 127 * of keys. 128 * @param[in] keys - A map of keys with empty values. 129 * 130 * @return The map of keys with filled values. 131 **/ 132 static std::map<std::string, std::string> getValue( 133 const std::string& filePath, std::map<std::string, std::string> keys); 134 135 /** 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> getVersions( 143 const std::string& versionPart); 144 145 /** 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); 156 157 /** @brief Persistent Delete D-Bus object */ 158 std::unique_ptr<Delete> deleteObject; 159 160 /** @brief The parent's erase callback. */ 161 eraseFunc eraseCallback; 162 163 private: 164 /** @brief Persistent sdbusplus DBus bus connection */ 165 sdbusplus::bus_t& bus; 166 167 /** @brief Persistent DBus object path */ 168 std::string objPath; 169 170 /** @brief Parent Object. */ 171 ItemUpdater& parent; 172 173 /** @brief This Version's version Id */ 174 const std::string versionId; 175 176 /** @brief This Version's version string */ 177 const std::string versionStr; 178 179 /** @brief Used to subscribe to chassis power state changes **/ 180 sdbusplus::bus::match_t chassisStateSignals; 181 }; 182 183 } // namespace updater 184 } // namespace software 185 } // namespace openpower 186