101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 501539e7eSLei YU #include <sdbusplus/bus.hpp> 601539e7eSLei YU #include <xyz/openbmc_project/Object/Delete/server.hpp> 701539e7eSLei YU #include <xyz/openbmc_project/Software/Version/server.hpp> 801539e7eSLei YU 901539e7eSLei YU namespace phosphor 1001539e7eSLei YU { 1101539e7eSLei YU namespace software 1201539e7eSLei YU { 1301539e7eSLei YU namespace updater 1401539e7eSLei YU { 1501539e7eSLei YU 1601539e7eSLei YU using eraseFunc = std::function<void(std::string)>; 1701539e7eSLei YU 18374fae56SPatrick Williams using VersionInherit = sdbusplus::server::object_t< 199930137bSLei YU sdbusplus::xyz::openbmc_project::Software::server::Version>; 20374fae56SPatrick Williams using DeleteInherit = sdbusplus::server::object_t< 2101539e7eSLei YU sdbusplus::xyz::openbmc_project::Object::server::Delete>; 2201539e7eSLei YU 2301539e7eSLei YU namespace sdbusRule = sdbusplus::bus::match::rules; 2401539e7eSLei YU 2501539e7eSLei YU class Version; 2601539e7eSLei YU 2701539e7eSLei YU /** @class Delete 2801539e7eSLei YU * @brief OpenBMC Delete implementation. 2901539e7eSLei YU * @details A concrete implementation for xyz.openbmc_project.Object.Delete 3001539e7eSLei YU * D-Bus API. 3101539e7eSLei YU */ 3201539e7eSLei YU class Delete : public DeleteInherit 3301539e7eSLei YU { 3401539e7eSLei YU public: 3501539e7eSLei YU /** @brief Constructs Delete. 3601539e7eSLei YU * 3701539e7eSLei YU * @param[in] bus - The D-Bus bus object 3801539e7eSLei YU * @param[in] path - The D-Bus object path 3901539e7eSLei YU * @param[in] version - The Version object. 4001539e7eSLei YU */ Delete(sdbusplus::bus_t & bus,const std::string & path,Version & version)41374fae56SPatrick Williams Delete(sdbusplus::bus_t& bus, const std::string& path, Version& version) : 42f356fdc9SAlbert Zhang DeleteInherit(bus, path.c_str(), action::emit_interface_added), 43f356fdc9SAlbert Zhang version(version) 445670b188SPatrick Williams {} 4501539e7eSLei YU 4601539e7eSLei YU /** 4701539e7eSLei YU * @brief Delete the D-Bus object. 4801539e7eSLei YU * Overrides the default delete function by calling 4901539e7eSLei YU * Version class erase Method. 5001539e7eSLei YU **/ 5101539e7eSLei YU void delete_() override; 5201539e7eSLei YU 5301539e7eSLei YU private: 5401539e7eSLei YU /** @brief The Version Object. */ 5501539e7eSLei YU Version& version; 5601539e7eSLei YU }; 5701539e7eSLei YU 5801539e7eSLei YU /** @class Version 5901539e7eSLei YU * @brief OpenBMC version software management implementation. 6001539e7eSLei YU * @details A concrete implementation for xyz.openbmc_project.Software.Version 6101539e7eSLei YU * D-Bus API. 6201539e7eSLei YU */ 6301539e7eSLei YU class Version : public VersionInherit 6401539e7eSLei YU { 6501539e7eSLei YU public: 6601539e7eSLei YU /** @brief Constructs Version Software Manager. 6701539e7eSLei YU * 6801539e7eSLei YU * @param[in] bus - The D-Bus bus object 6901539e7eSLei YU * @param[in] objPath - The D-Bus object path 7001539e7eSLei YU * @param[in] versionId - The version Id 7101539e7eSLei YU * @param[in] versionString - The version string 7201539e7eSLei YU * @param[in] versionPurpose - The version purpose 7301539e7eSLei YU * @param[in] callback - The eraseFunc callback 7401539e7eSLei YU */ Version(sdbusplus::bus_t & bus,const std::string & objPath,const std::string & versionId,const std::string & versionString,VersionPurpose versionPurpose,eraseFunc callback)75374fae56SPatrick Williams Version(sdbusplus::bus_t& bus, const std::string& objPath, 7601539e7eSLei YU const std::string& versionId, const std::string& versionString, 779930137bSLei YU VersionPurpose versionPurpose, eraseFunc callback) : 78434ae483STang Yiwei VersionInherit(bus, (objPath).c_str(), 79434ae483STang Yiwei VersionInherit::action::defer_emit), 80a31e568eSGeorge Liu eraseCallback(std::move(callback)), bus(bus), objPath(objPath), 8101539e7eSLei YU versionId(versionId), versionStr(versionString) 8201539e7eSLei YU { 8301539e7eSLei YU // Set properties. 8401539e7eSLei YU purpose(versionPurpose); 8501539e7eSLei YU version(versionString); 8601539e7eSLei YU 8701539e7eSLei YU deleteObject = std::make_unique<Delete>(bus, objPath, *this); 8801539e7eSLei YU 8901539e7eSLei YU // Emit deferred signal. 9001539e7eSLei YU emit_object_added(); 9101539e7eSLei YU } 9201539e7eSLei YU 9301539e7eSLei YU /** 9401539e7eSLei YU * @brief Return the version id 9501539e7eSLei YU */ getVersionId() const9601539e7eSLei YU std::string getVersionId() const 9701539e7eSLei YU { 9801539e7eSLei YU return versionId; 9901539e7eSLei YU } 10001539e7eSLei YU 10101539e7eSLei YU /** 10258c26e3fSLei YU * @brief Read the manifest file to get the values of the keys. 10301539e7eSLei YU * 10401539e7eSLei YU * @param[in] filePath - The path to the file which contains the value 10501539e7eSLei YU * of keys. 106fda15a33SLei YU * @param[in] keys - A vector of keys. 10701539e7eSLei YU * 10801539e7eSLei YU * @return The map of keys with filled values. 10901539e7eSLei YU **/ 110bab5ed99SPatrick Williams static std::map<std::string, std::string> getValues( 111bab5ed99SPatrick Williams const std::string& filePath, const std::vector<std::string>& keys); 11201539e7eSLei YU 11358c26e3fSLei YU /** 11458c26e3fSLei YU * @brief Read the manifest file to get the value of the key. 11558c26e3fSLei YU * 11658c26e3fSLei YU * @param[in] filePath - The path to the file which contains the value 11758c26e3fSLei YU * of keys. 11858c26e3fSLei YU * @param[in] key - The string of the key. 11958c26e3fSLei YU * 12058c26e3fSLei YU * @return The string of the value. 12158c26e3fSLei YU **/ 12258c26e3fSLei YU static std::string getValue(const std::string& filePath, 12358c26e3fSLei YU const std::string& key); 12458c26e3fSLei YU 1259edb7330SLei YU /** @brief Get information from extVersion 1269edb7330SLei YU * 1279edb7330SLei YU * @param[in] extVersion - The extended version string that contains 1289edb7330SLei YU * key/value pairs separated by comma. 1299edb7330SLei YU * 1309edb7330SLei YU * @return The map of key/value pairs 1319edb7330SLei YU */ 132*638b84aeSPatrick Williams static std::map<std::string, std::string> getExtVersionInfo( 133*638b84aeSPatrick Williams const std::string& extVersion); 1349edb7330SLei YU 13501539e7eSLei YU /** @brief The temUpdater's erase callback. */ 13601539e7eSLei YU eraseFunc eraseCallback; 13701539e7eSLei YU 1381517f5f6SLei YU /** @brief Get the version string. */ getVersionString() const1391517f5f6SLei YU const std::string& getVersionString() const 1401517f5f6SLei YU { 1411517f5f6SLei YU return versionStr; 1421517f5f6SLei YU } 1431517f5f6SLei YU 14401539e7eSLei YU private: 14501539e7eSLei YU /** @brief Persistent sdbusplus DBus bus connection */ 146374fae56SPatrick Williams sdbusplus::bus_t& bus; 14701539e7eSLei YU 14801539e7eSLei YU /** @brief Persistent DBus object path */ 14901539e7eSLei YU std::string objPath; 15001539e7eSLei YU 15101539e7eSLei YU /** @brief This Version's version Id */ 15201539e7eSLei YU const std::string versionId; 15301539e7eSLei YU 15401539e7eSLei YU /** @brief This Version's version string */ 15501539e7eSLei YU const std::string versionStr; 156f77189f7SLei YU 157f77189f7SLei YU /** @brief Persistent Delete D-Bus object */ 158f77189f7SLei YU std::unique_ptr<Delete> deleteObject; 15901539e7eSLei YU }; 16001539e7eSLei YU 16101539e7eSLei YU } // namespace updater 16201539e7eSLei YU } // namespace software 16301539e7eSLei YU } // namespace phosphor 164