1 #pragma once
2 #include <sdbusplus/server.hpp>
3 #include "version.hpp"
4 
5 namespace phosphor
6 {
7 namespace software
8 {
9 namespace manager
10 {
11 
12 namespace MatchRules = sdbusplus::bus::match::rules;
13 
14 /** @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.
18  */
19 class Manager
20 {
21     public:
22         /** @brief Constructs Manager Class
23          *
24          * @param[in] bus - The Dbus bus object
25          */
26         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)){};
36 
37         /**
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 
46         /**
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 
54     private:
55         /** @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 
62         /** @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 
69         /** @brief sdbusplus signal match for Software.Version */
70         sdbusplus::bus::match_t versionMatch;
71 
72         /**
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);
81 };
82 
83 } // namespace manager
84 } // namespace software
85 } // namespace phosphor
86