blob: 25f0cedf11fe973bba7238465bfed37ec7e4f205 [file] [log] [blame]
Gunnar Millse91d3212017-04-19 15:42:47 -05001#pragma once
Gunnar Mills3027bba2017-04-27 15:49:03 -05002#include "version.hpp"
Gunnar Millse91d3212017-04-19 15:42:47 -05003
Gunnar Millsb0ce9962018-09-07 13:39:10 -05004#include <sdbusplus/server.hpp>
Adriana Kobylak58aa7502020-06-08 11:12:11 -05005
Adriana Kobylak59b640b2022-01-21 19:45:22 +00006#include <chrono>
7#include <random>
Andrew Geissler9155b712020-05-16 13:04:44 -05008#include <string>
Gunnar Millsb0ce9962018-09-07 13:39:10 -05009
Gunnar Millse91d3212017-04-19 15:42:47 -050010namespace phosphor
11{
12namespace software
13{
14namespace manager
15{
16
Gunnar Mills3027bba2017-04-27 15:49:03 -050017/** @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.
Gunnar Millse91d3212017-04-19 15:42:47 -050021 */
Gunnar Mills3027bba2017-04-27 15:49:03 -050022class Manager
23{
Adriana Kobylak2285fe02018-02-27 15:36:59 -060024 public:
25 /** @brief Constructs Manager Class
26 *
27 * @param[in] bus - The Dbus bus object
28 */
Lei YU0cd6d842021-12-27 11:56:02 +080029 explicit Manager(sdbusplus::bus::bus& bus) : bus(bus){};
Gunnar Millse91d3212017-04-19 15:42:47 -050030
Adriana Kobylak2285fe02018-02-27 15:36:59 -060031 /**
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);
Gunnar Mills3027bba2017-04-27 15:49:03 -050039
Adriana Kobylak2285fe02018-02-27 15:36:59 -060040 /**
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);
Leonel Gonzalez50d559c2017-07-07 14:38:25 -050047
Adriana Kobylak2285fe02018-02-27 15:36:59 -060048 private:
49 /** @brief Persistent map of Version dbus objects and their
50 * version id */
51 std::map<std::string, std::unique_ptr<Version>> versions;
Gunnar Mills3027bba2017-04-27 15:49:03 -050052
Adriana Kobylak2285fe02018-02-27 15:36:59 -060053 /** @brief Persistent sdbusplus DBus bus connection. */
54 sdbusplus::bus::bus& bus;
Gunnar Mills3027bba2017-04-27 15:49:03 -050055
Adriana Kobylak59b640b2022-01-21 19:45:22 +000056 /** @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
Adriana Kobylak2285fe02018-02-27 15:36:59 -060060 /**
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);
Gunnar Mills3027bba2017-04-27 15:49:03 -050069};
Gunnar Mills19e4ce52017-04-27 11:24:19 -050070
Gunnar Millse91d3212017-04-19 15:42:47 -050071} // namespace manager
72} // namespace software
73} // namespace phosphor