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