summaryrefslogtreecommitdiffstats
path: root/tools/handler.hpp
blob: 2335977949954725b088bc2040de7339f1f7876b (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
#pragma once

#include "interface.hpp"

#include <ipmiblob/blob_interface.hpp>
#include <string>

namespace host_tool
{

class UpdateHandlerInterface
{
  public:
    virtual ~UpdateHandlerInterface() = default;

    /**
     * Check if the goal firmware is listed in the blob_list and that the
     * handler's supported data type is available.
     *
     * @param[in] goalFirmware - the firmware to check /flash/image
     * /flash/tarball, etc.
     */
    virtual bool checkAvailable(const std::string& goalFirmware) = 0;

    /**
     * Send the file contents at path to the blob id, target.
     *
     * @param[in] target - the blob id
     * @param[in] path - the source file path
     */
    virtual void sendFile(const std::string& target,
                          const std::string& path) = 0;

    /**
     * Trigger verification.
     *
     * @param[in] target - the verification blob id (may support multiple in the
     * future.
     * @return true if verified, false if verification errors.
     */
    virtual bool verifyFile(const std::string& target) = 0;

    /**
     * Cleanup the artifacts by triggering this action.
     */
    virtual void cleanArtifacts() = 0;
};

/** Object that actually handles the update itself. */
class UpdateHandler : public UpdateHandlerInterface
{
  public:
    UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
        blob(blob), handler(handler)
    {
    }

    ~UpdateHandler() = default;

    bool checkAvailable(const std::string& goalFirmware) override;

    /**
     * @throw ToolException on failure.
     */
    void sendFile(const std::string& target, const std::string& path) override;

    /**
     * @throw ToolException on failure (TODO: throw on timeout.)
     */
    bool verifyFile(const std::string& target) override;

    void cleanArtifacts() override;

  private:
    ipmiblob::BlobInterface* blob;
    DataInterface* handler;
};

} // namespace host_tool
OpenPOWER on IntegriCloud