1*cab87e9cSJagpal Singh Gill #pragma once 2*cab87e9cSJagpal Singh Gill 3*cab87e9cSJagpal Singh Gill #include "xyz/openbmc_project/Common/FilePath/server.hpp" 4*cab87e9cSJagpal Singh Gill #include "xyz/openbmc_project/Inventory/Decorator/Compatible/server.hpp" 5*cab87e9cSJagpal Singh Gill #include "xyz/openbmc_project/Object/Delete/server.hpp" 6*cab87e9cSJagpal Singh Gill #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" 7*cab87e9cSJagpal Singh Gill #include "xyz/openbmc_project/Software/Version/server.hpp" 8*cab87e9cSJagpal Singh Gill 9*cab87e9cSJagpal Singh Gill #include <sdbusplus/bus.hpp> 10*cab87e9cSJagpal Singh Gill 11*cab87e9cSJagpal Singh Gill #include <functional> 12*cab87e9cSJagpal Singh Gill #include <string> 13*cab87e9cSJagpal Singh Gill #include <vector> 14*cab87e9cSJagpal Singh Gill 15*cab87e9cSJagpal Singh Gill namespace phosphor 16*cab87e9cSJagpal Singh Gill { 17*cab87e9cSJagpal Singh Gill namespace software 18*cab87e9cSJagpal Singh Gill { 19*cab87e9cSJagpal Singh Gill namespace manager 20*cab87e9cSJagpal Singh Gill { 21*cab87e9cSJagpal Singh Gill 22*cab87e9cSJagpal Singh Gill typedef std::function<void(std::string)> eraseFunc; 23*cab87e9cSJagpal Singh Gill 24*cab87e9cSJagpal Singh Gill using VersionInherit = sdbusplus::server::object_t< 25*cab87e9cSJagpal Singh Gill sdbusplus::server::xyz::openbmc_project::software::ExtendedVersion, 26*cab87e9cSJagpal Singh Gill sdbusplus::server::xyz::openbmc_project::software::Version, 27*cab87e9cSJagpal Singh Gill sdbusplus::server::xyz::openbmc_project::common::FilePath, 28*cab87e9cSJagpal Singh Gill sdbusplus::server::xyz::openbmc_project::inventory::decorator::Compatible>; 29*cab87e9cSJagpal Singh Gill using DeleteInherit = sdbusplus::server::object_t< 30*cab87e9cSJagpal Singh Gill sdbusplus::server::xyz::openbmc_project::object::Delete>; 31*cab87e9cSJagpal Singh Gill 32*cab87e9cSJagpal Singh Gill class Version; 33*cab87e9cSJagpal Singh Gill class Delete; 34*cab87e9cSJagpal Singh Gill 35*cab87e9cSJagpal Singh Gill /** @class Delete 36*cab87e9cSJagpal Singh Gill * @brief OpenBMC Delete implementation. 37*cab87e9cSJagpal Singh Gill * @details A concrete implementation for xyz.openbmc_project.Object.Delete 38*cab87e9cSJagpal Singh Gill * D-Bus API. 39*cab87e9cSJagpal Singh Gill */ 40*cab87e9cSJagpal Singh Gill class Delete : public DeleteInherit 41*cab87e9cSJagpal Singh Gill { 42*cab87e9cSJagpal Singh Gill public: 43*cab87e9cSJagpal Singh Gill /** @brief Constructs Delete. 44*cab87e9cSJagpal Singh Gill * 45*cab87e9cSJagpal Singh Gill * @param[in] bus - The D-Bus bus object 46*cab87e9cSJagpal Singh Gill * @param[in] path - The D-Bus object path 47*cab87e9cSJagpal Singh Gill * @param[in] parent - Parent object. 48*cab87e9cSJagpal Singh Gill */ Delete(sdbusplus::bus_t & bus,const std::string & path,Version & parent)49*cab87e9cSJagpal Singh Gill Delete(sdbusplus::bus_t& bus, const std::string& path, Version& parent) : 50*cab87e9cSJagpal Singh Gill DeleteInherit(bus, path.c_str(), action::emit_interface_added), 51*cab87e9cSJagpal Singh Gill parent(parent) 52*cab87e9cSJagpal Singh Gill { 53*cab87e9cSJagpal Singh Gill // Empty 54*cab87e9cSJagpal Singh Gill } 55*cab87e9cSJagpal Singh Gill 56*cab87e9cSJagpal Singh Gill /** @brief delete the D-Bus object. */ 57*cab87e9cSJagpal Singh Gill void delete_() override; 58*cab87e9cSJagpal Singh Gill 59*cab87e9cSJagpal Singh Gill private: 60*cab87e9cSJagpal Singh Gill /** @brief Parent Object. */ 61*cab87e9cSJagpal Singh Gill Version& parent; 62*cab87e9cSJagpal Singh Gill }; 63*cab87e9cSJagpal Singh Gill 64*cab87e9cSJagpal Singh Gill /** @class Version 65*cab87e9cSJagpal Singh Gill * @brief OpenBMC version software management implementation. 66*cab87e9cSJagpal Singh Gill * @details A concrete implementation for xyz.openbmc_project.Software.Version 67*cab87e9cSJagpal Singh Gill * D-Bus API. 68*cab87e9cSJagpal Singh Gill */ 69*cab87e9cSJagpal Singh Gill class Version : public VersionInherit 70*cab87e9cSJagpal Singh Gill { 71*cab87e9cSJagpal Singh Gill public: 72*cab87e9cSJagpal Singh Gill /** @brief Constructs Version Software Manager 73*cab87e9cSJagpal Singh Gill * 74*cab87e9cSJagpal Singh Gill * @param[in] bus - The D-Bus bus object 75*cab87e9cSJagpal Singh Gill * @param[in] objPath - The D-Bus object path 76*cab87e9cSJagpal Singh Gill * @param[in] versionString - The version string 77*cab87e9cSJagpal Singh Gill * @param[in] versionPurpose - The version purpose 78*cab87e9cSJagpal Singh Gill * @param[in] extVersion - The extended version 79*cab87e9cSJagpal Singh Gill * @param[in] filePath - The image filesystem path 80*cab87e9cSJagpal Singh Gill * @param[in] compatibleNames - The device compatibility names 81*cab87e9cSJagpal Singh Gill * @param[in] callback - The eraseFunc callback 82*cab87e9cSJagpal Singh Gill */ Version(sdbusplus::bus_t & bus,const std::string & objPath,const std::string & versionString,VersionPurpose versionPurpose,const std::string & extVersion,const std::string & filePath,const std::vector<std::string> & compatibleNames,eraseFunc callback,const std::string & id)83*cab87e9cSJagpal Singh Gill Version(sdbusplus::bus_t& bus, const std::string& objPath, 84*cab87e9cSJagpal Singh Gill const std::string& versionString, VersionPurpose versionPurpose, 85*cab87e9cSJagpal Singh Gill const std::string& extVersion, const std::string& filePath, 86*cab87e9cSJagpal Singh Gill const std::vector<std::string>& compatibleNames, eraseFunc callback, 87*cab87e9cSJagpal Singh Gill const std::string& id) : 88*cab87e9cSJagpal Singh Gill VersionInherit(bus, (objPath).c_str(), 89*cab87e9cSJagpal Singh Gill VersionInherit::action::defer_emit), 90*cab87e9cSJagpal Singh Gill eraseCallback(std::move(callback)), id(id), objPath(objPath), 91*cab87e9cSJagpal Singh Gill versionStr(versionString) 92*cab87e9cSJagpal Singh Gill { 93*cab87e9cSJagpal Singh Gill // Set properties. 94*cab87e9cSJagpal Singh Gill extendedVersion(extVersion); 95*cab87e9cSJagpal Singh Gill purpose(versionPurpose); 96*cab87e9cSJagpal Singh Gill version(versionString); 97*cab87e9cSJagpal Singh Gill path(filePath); 98*cab87e9cSJagpal Singh Gill names(compatibleNames); 99*cab87e9cSJagpal Singh Gill // Emit deferred signal. 100*cab87e9cSJagpal Singh Gill emit_object_added(); 101*cab87e9cSJagpal Singh Gill } 102*cab87e9cSJagpal Singh Gill 103*cab87e9cSJagpal Singh Gill /** 104*cab87e9cSJagpal Singh Gill * @brief Read the manifest file to get the value of the key. 105*cab87e9cSJagpal Singh Gill * 106*cab87e9cSJagpal Singh Gill * @return The value of the key. 107*cab87e9cSJagpal Singh Gill **/ 108*cab87e9cSJagpal Singh Gill static std::string getValue(const std::string& manifestFilePath, 109*cab87e9cSJagpal Singh Gill std::string key); 110*cab87e9cSJagpal Singh Gill 111*cab87e9cSJagpal Singh Gill /** 112*cab87e9cSJagpal Singh Gill * @brief Read the manifest file to get the values of the repeated key. 113*cab87e9cSJagpal Singh Gill * 114*cab87e9cSJagpal Singh Gill * @return The values of the repeated key. 115*cab87e9cSJagpal Singh Gill **/ 116*cab87e9cSJagpal Singh Gill static std::vector<std::string> 117*cab87e9cSJagpal Singh Gill getRepeatedValues(const std::string& manifestFilePath, std::string key); 118*cab87e9cSJagpal Singh Gill 119*cab87e9cSJagpal Singh Gill /** 120*cab87e9cSJagpal Singh Gill * @brief Calculate the version id from the version string. 121*cab87e9cSJagpal Singh Gill * 122*cab87e9cSJagpal Singh Gill * @details The version id is a unique 8 hexadecimal digit id 123*cab87e9cSJagpal Singh Gill * calculated from the version string. 124*cab87e9cSJagpal Singh Gill * 125*cab87e9cSJagpal Singh Gill * @param[in] versionWithSalt - The image's version string 126*cab87e9cSJagpal Singh Gill * (e.g. v1.99.10-19) plus an optional salt 127*cab87e9cSJagpal Singh Gill * string. 128*cab87e9cSJagpal Singh Gill * 129*cab87e9cSJagpal Singh Gill * @return The id. 130*cab87e9cSJagpal Singh Gill */ 131*cab87e9cSJagpal Singh Gill static std::string getId(const std::string& versionWithSalt); 132*cab87e9cSJagpal Singh Gill 133*cab87e9cSJagpal Singh Gill /** 134*cab87e9cSJagpal Singh Gill * @brief Get the active BMC machine name string. 135*cab87e9cSJagpal Singh Gill * 136*cab87e9cSJagpal Singh Gill * @param[in] releaseFilePath - The path to the file which contains 137*cab87e9cSJagpal Singh Gill * the release machine string. 138*cab87e9cSJagpal Singh Gill * 139*cab87e9cSJagpal Singh Gill * @return The machine name string (e.g. romulus, tiogapass). 140*cab87e9cSJagpal Singh Gill */ 141*cab87e9cSJagpal Singh Gill static std::string getBMCMachine(const std::string& releaseFilePath); 142*cab87e9cSJagpal Singh Gill 143*cab87e9cSJagpal Singh Gill /** 144*cab87e9cSJagpal Singh Gill * @brief Get the BMC Extended Version string. 145*cab87e9cSJagpal Singh Gill * 146*cab87e9cSJagpal Singh Gill * @param[in] releaseFilePath - The path to the file which contains 147*cab87e9cSJagpal Singh Gill * the release machine string. 148*cab87e9cSJagpal Singh Gill * 149*cab87e9cSJagpal Singh Gill * @return The extended version string. 150*cab87e9cSJagpal Singh Gill */ 151*cab87e9cSJagpal Singh Gill static std::string 152*cab87e9cSJagpal Singh Gill getBMCExtendedVersion(const std::string& releaseFilePath); 153*cab87e9cSJagpal Singh Gill 154*cab87e9cSJagpal Singh Gill /** 155*cab87e9cSJagpal Singh Gill * @brief Get the active BMC version string. 156*cab87e9cSJagpal Singh Gill * 157*cab87e9cSJagpal Singh Gill * @param[in] releaseFilePath - The path to the file which contains 158*cab87e9cSJagpal Singh Gill * the release version string. 159*cab87e9cSJagpal Singh Gill * 160*cab87e9cSJagpal Singh Gill * @return The version string (e.g. v1.99.10-19). 161*cab87e9cSJagpal Singh Gill */ 162*cab87e9cSJagpal Singh Gill static std::string getBMCVersion(const std::string& releaseFilePath); 163*cab87e9cSJagpal Singh Gill 164*cab87e9cSJagpal Singh Gill /* @brief Check if this version is functional. 165*cab87e9cSJagpal Singh Gill * 166*cab87e9cSJagpal Singh Gill * @return - Returns the functional value. 167*cab87e9cSJagpal Singh Gill */ isFunctional() const168*cab87e9cSJagpal Singh Gill bool isFunctional() const 169*cab87e9cSJagpal Singh Gill { 170*cab87e9cSJagpal Singh Gill return functional; 171*cab87e9cSJagpal Singh Gill } 172*cab87e9cSJagpal Singh Gill 173*cab87e9cSJagpal Singh Gill /** @brief Set the functional value. 174*cab87e9cSJagpal Singh Gill * @param[in] value - True or False 175*cab87e9cSJagpal Singh Gill */ setFunctional(bool value)176*cab87e9cSJagpal Singh Gill void setFunctional(bool value) 177*cab87e9cSJagpal Singh Gill { 178*cab87e9cSJagpal Singh Gill functional = value; 179*cab87e9cSJagpal Singh Gill } 180*cab87e9cSJagpal Singh Gill 181*cab87e9cSJagpal Singh Gill /** @brief Persistent Delete D-Bus object */ 182*cab87e9cSJagpal Singh Gill std::unique_ptr<Delete> deleteObject; 183*cab87e9cSJagpal Singh Gill 184*cab87e9cSJagpal Singh Gill /** @brief The parent's erase callback. */ 185*cab87e9cSJagpal Singh Gill eraseFunc eraseCallback; 186*cab87e9cSJagpal Singh Gill 187*cab87e9cSJagpal Singh Gill /** @brief The version ID of the object */ 188*cab87e9cSJagpal Singh Gill const std::string id; 189*cab87e9cSJagpal Singh Gill 190*cab87e9cSJagpal Singh Gill /** @brief The path of the object */ 191*cab87e9cSJagpal Singh Gill std::string objPath; 192*cab87e9cSJagpal Singh Gill 193*cab87e9cSJagpal Singh Gill private: 194*cab87e9cSJagpal Singh Gill /** @brief This Version's version string */ 195*cab87e9cSJagpal Singh Gill const std::string versionStr; 196*cab87e9cSJagpal Singh Gill 197*cab87e9cSJagpal Singh Gill /** @brief If this version is the functional one */ 198*cab87e9cSJagpal Singh Gill bool functional = false; 199*cab87e9cSJagpal Singh Gill }; 200*cab87e9cSJagpal Singh Gill 201*cab87e9cSJagpal Singh Gill } // namespace manager 202*cab87e9cSJagpal Singh Gill } // namespace software 203*cab87e9cSJagpal Singh Gill } // namespace phosphor 204