1*cab87e9cSJagpal Singh Gill #pragma once 2*cab87e9cSJagpal Singh Gill #include "version.hpp" 3*cab87e9cSJagpal Singh Gill 4*cab87e9cSJagpal Singh Gill #include <sdbusplus/server.hpp> 5*cab87e9cSJagpal Singh Gill 6*cab87e9cSJagpal Singh Gill #include <chrono> 7*cab87e9cSJagpal Singh Gill #include <random> 8*cab87e9cSJagpal Singh Gill #include <string> 9*cab87e9cSJagpal Singh Gill 10*cab87e9cSJagpal Singh Gill namespace phosphor 11*cab87e9cSJagpal Singh Gill { 12*cab87e9cSJagpal Singh Gill namespace software 13*cab87e9cSJagpal Singh Gill { 14*cab87e9cSJagpal Singh Gill namespace manager 15*cab87e9cSJagpal Singh Gill { 16*cab87e9cSJagpal Singh Gill 17*cab87e9cSJagpal Singh Gill /** @class Manager 18*cab87e9cSJagpal Singh Gill * @brief Contains a map of Version dbus objects. 19*cab87e9cSJagpal Singh Gill * @details The software image manager class that contains the Version dbus 20*cab87e9cSJagpal Singh Gill * objects and their version ids. 21*cab87e9cSJagpal Singh Gill */ 22*cab87e9cSJagpal Singh Gill class Manager 23*cab87e9cSJagpal Singh Gill { 24*cab87e9cSJagpal Singh Gill public: 25*cab87e9cSJagpal Singh Gill /** @brief Constructs Manager Class 26*cab87e9cSJagpal Singh Gill * 27*cab87e9cSJagpal Singh Gill * @param[in] bus - The Dbus bus object 28*cab87e9cSJagpal Singh Gill */ Manager(sdbusplus::bus_t & bus)29*cab87e9cSJagpal Singh Gill explicit Manager(sdbusplus::bus_t& bus) : bus(bus) {}; 30*cab87e9cSJagpal Singh Gill 31*cab87e9cSJagpal Singh Gill /** 32*cab87e9cSJagpal Singh Gill * @brief Verify and untar the tarball. Verify the manifest file. 33*cab87e9cSJagpal Singh Gill * Create and populate the version and filepath interfaces. 34*cab87e9cSJagpal Singh Gill * 35*cab87e9cSJagpal Singh Gill * @param[in] tarballFilePath - Tarball path. 36*cab87e9cSJagpal Singh Gill * @param[out] result - 0 if successful. 37*cab87e9cSJagpal Singh Gill */ 38*cab87e9cSJagpal Singh Gill int processImage(const std::string& tarballFilePath); 39*cab87e9cSJagpal Singh Gill 40*cab87e9cSJagpal Singh Gill /** 41*cab87e9cSJagpal Singh Gill * @brief Erase specified entry d-bus object 42*cab87e9cSJagpal Singh Gill * and deletes the image file. 43*cab87e9cSJagpal Singh Gill * 44*cab87e9cSJagpal Singh Gill * @param[in] entryId - unique identifier of the entry 45*cab87e9cSJagpal Singh Gill */ 46*cab87e9cSJagpal Singh Gill void erase(const std::string& entryId); 47*cab87e9cSJagpal Singh Gill 48*cab87e9cSJagpal Singh Gill private: 49*cab87e9cSJagpal Singh Gill /** @brief Persistent map of Version dbus objects and their 50*cab87e9cSJagpal Singh Gill * version id */ 51*cab87e9cSJagpal Singh Gill std::map<std::string, std::unique_ptr<Version>> versions; 52*cab87e9cSJagpal Singh Gill 53*cab87e9cSJagpal Singh Gill /** @brief Persistent sdbusplus DBus bus connection. */ 54*cab87e9cSJagpal Singh Gill sdbusplus::bus_t& bus; 55*cab87e9cSJagpal Singh Gill 56*cab87e9cSJagpal Singh Gill /** @brief The random generator to get the version salt */ 57*cab87e9cSJagpal Singh Gill std::mt19937 randomGen{static_cast<unsigned>( 58*cab87e9cSJagpal Singh Gill std::chrono::system_clock::now().time_since_epoch().count())}; 59*cab87e9cSJagpal Singh Gill 60*cab87e9cSJagpal Singh Gill /** 61*cab87e9cSJagpal Singh Gill * @brief Untar the tarball. 62*cab87e9cSJagpal Singh Gill * 63*cab87e9cSJagpal Singh Gill * @param[in] tarballFilePath - Tarball path. 64*cab87e9cSJagpal Singh Gill * @param[in] extractDirPath - Dir path to extract tarball ball to. 65*cab87e9cSJagpal Singh Gill * @param[out] result - 0 if successful. 66*cab87e9cSJagpal Singh Gill */ 67*cab87e9cSJagpal Singh Gill static int unTar(const std::string& tarballFilePath, 68*cab87e9cSJagpal Singh Gill const std::string& extractDirPath); 69*cab87e9cSJagpal Singh Gill }; 70*cab87e9cSJagpal Singh Gill 71*cab87e9cSJagpal Singh Gill } // namespace manager 72*cab87e9cSJagpal Singh Gill } // namespace software 73*cab87e9cSJagpal Singh Gill } // namespace phosphor 74