blob: 5c6953679ee9ee086da3d99c540bedcb33757cd6 [file] [log] [blame]
Gunnar Millse91d3212017-04-19 15:42:47 -05001#pragma once
Eddie James9440f492017-08-30 11:34:16 -05002#include <sdbusplus/server.hpp>
Gunnar Mills3027bba2017-04-27 15:49:03 -05003#include "version.hpp"
Gunnar Millse91d3212017-04-19 15:42:47 -05004
5namespace phosphor
6{
7namespace software
8{
9namespace manager
10{
11
Eddie James9440f492017-08-30 11:34:16 -050012namespace MatchRules = sdbusplus::bus::match::rules;
13
Gunnar Mills3027bba2017-04-27 15:49:03 -050014/** @class Manager
15 * @brief Contains a map of Version dbus objects.
16 * @details The software image manager class that contains the Version dbus
17 * objects and their version ids.
Gunnar Millse91d3212017-04-19 15:42:47 -050018 */
Gunnar Mills3027bba2017-04-27 15:49:03 -050019class Manager
20{
21 public:
22 /** @brief Constructs Manager Class
23 *
24 * @param[in] bus - The Dbus bus object
25 */
Eddie James9440f492017-08-30 11:34:16 -050026 Manager(sdbusplus::bus::bus& bus) :
27 bus(bus),
28 versionMatch(
29 bus,
30 MatchRules::interfacesRemoved() +
31 MatchRules::path(SOFTWARE_OBJPATH),
32 std::bind(
33 std::mem_fn(&Manager::removeVersion),
34 this,
35 std::placeholders::_1)){};
Gunnar Millse91d3212017-04-19 15:42:47 -050036
Gunnar Mills3027bba2017-04-27 15:49:03 -050037 /**
38 * @brief Verify and untar the tarball. Verify the manifest file.
39 * Create and populate the version and filepath interfaces.
40 *
41 * @param[in] tarballFilePath - Tarball path.
42 * @param[out] result - 0 if successful.
43 */
44 int processImage(const std::string& tarballFilePath);
45
Leonel Gonzalez50d559c2017-07-07 14:38:25 -050046 /**
47 * @brief Erase specified entry d-bus object
48 * and deletes the image file.
49 *
50 * @param[in] entryId - unique identifier of the entry
51 */
52 void erase(std::string entryId);
53
Gunnar Mills3027bba2017-04-27 15:49:03 -050054 private:
Eddie James9440f492017-08-30 11:34:16 -050055 /** @brief Callback function for Software.Version match.
56 * @details Removes a version object.
57 *
58 * @param[in] msg - Data associated with subscribed signal
59 */
60 void removeVersion(sdbusplus::message::message& msg);
61
Gunnar Mills3027bba2017-04-27 15:49:03 -050062 /** @brief Persistent map of Version dbus objects and their
63 * version id */
64 std::map<std::string, std::unique_ptr<Version>> versions;
65
66 /** @brief Persistent sdbusplus DBus bus connection. */
67 sdbusplus::bus::bus& bus;
68
Eddie James9440f492017-08-30 11:34:16 -050069 /** @brief sdbusplus signal match for Software.Version */
70 sdbusplus::bus::match_t versionMatch;
71
Gunnar Mills3027bba2017-04-27 15:49:03 -050072 /**
73 * @brief Untar the tarball.
74 *
75 * @param[in] tarballFilePath - Tarball path.
76 * @param[in] extractDirPath - Dir path to extract tarball ball to.
77 * @param[out] result - 0 if successful.
78 */
79 static int unTar(const std::string& tarballFilePath,
80 const std::string& extractDirPath);
Gunnar Mills3027bba2017-04-27 15:49:03 -050081};
Gunnar Mills19e4ce52017-04-27 11:24:19 -050082
Gunnar Millse91d3212017-04-19 15:42:47 -050083} // namespace manager
84} // namespace software
85} // namespace phosphor