summaryrefslogtreecommitdiffstats
path: root/image_manager.hpp
blob: 5c6953679ee9ee086da3d99c540bedcb33757cd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <sdbusplus/server.hpp>
#include "version.hpp"

namespace phosphor
{
namespace software
{
namespace manager
{

namespace MatchRules = sdbusplus::bus::match::rules;

/** @class Manager
 *  @brief Contains a map of Version dbus objects.
 *  @details The software image manager class that contains the Version dbus
 *           objects and their version ids.
 */
class Manager
{
    public:
        /** @brief Constructs Manager Class
         *
         * @param[in] bus - The Dbus bus object
         */
        Manager(sdbusplus::bus::bus& bus) :
                bus(bus),
                versionMatch(
                        bus,
                        MatchRules::interfacesRemoved() +
                        MatchRules::path(SOFTWARE_OBJPATH),
                        std::bind(
                                std::mem_fn(&Manager::removeVersion),
                                this,
                                std::placeholders::_1)){};

        /**
         * @brief Verify and untar the tarball. Verify the manifest file.
         *        Create and populate the version and filepath interfaces.
         *
         * @param[in]  tarballFilePath - Tarball path.
         * @param[out] result          - 0 if successful.
         */
         int processImage(const std::string& tarballFilePath);

        /**
         * @brief Erase specified entry d-bus object
         *        and deletes the image file.
         *
         * @param[in] entryId - unique identifier of the entry
         */
        void erase(std::string entryId);

    private:
        /** @brief Callback function for Software.Version match.
         *  @details Removes a version object.
         *
         * @param[in]  msg - Data associated with subscribed signal
         */
        void removeVersion(sdbusplus::message::message& msg);

        /** @brief Persistent map of Version dbus objects and their
          * version id */
        std::map<std::string, std::unique_ptr<Version>> versions;

        /** @brief Persistent sdbusplus DBus bus connection. */
        sdbusplus::bus::bus& bus;

        /** @brief sdbusplus signal match for Software.Version */
        sdbusplus::bus::match_t versionMatch;

        /**
         * @brief Untar the tarball.
         *
         * @param[in]  tarballFilePath - Tarball path.
         * @param[in]  extractDirPath  - Dir path to extract tarball ball to.
         * @param[out] result          - 0 if successful.
         */
        static int unTar(const std::string& tarballFilePath,
                         const std::string& extractDirPath);
};

} // namespace manager
} // namespace software
} // namespace phosphor
OpenPOWER on IntegriCloud