blob: a0dae5662f8dff4c58aa419f3c92f203d2a56bd8 [file] [log] [blame]
Patrick Venture01123b22019-06-20 13:49:06 -07001#pragma once
2
3#include "interface.hpp"
4
5#include <ipmiblob/blob_interface.hpp>
6#include <string>
7
8namespace host_tool
9{
10
11class UpdateHandlerInterface
12{
13 public:
14 virtual ~UpdateHandlerInterface() = default;
15
16 /**
17 * Check if the goal firmware is listed in the blob_list and that the
18 * handler's supported data type is available.
19 *
20 * @param[in] goalFirmware - the firmware to check /flash/image
21 * /flash/tarball, etc.
22 */
23 virtual bool checkAvailable(const std::string& goalFirmware) = 0;
24
25 /**
26 * Send the file contents at path to the blob id, target.
27 *
28 * @param[in] target - the blob id
29 * @param[in] path - the source file path
30 */
31 virtual void sendFile(const std::string& target,
32 const std::string& path) = 0;
33
34 /**
35 * Trigger verification.
36 *
37 * @param[in] target - the verification blob id (may support multiple in the
38 * future.
Brandon Kim6749ba12019-09-19 13:31:37 -070039 * @param[in] ignoreStatus - determines whether to ignore the verification
40 * status.
Patrick Venture01123b22019-06-20 13:49:06 -070041 * @return true if verified, false if verification errors.
42 */
Brandon Kim6749ba12019-09-19 13:31:37 -070043 virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0;
Patrick Venture01123b22019-06-20 13:49:06 -070044
45 /**
46 * Cleanup the artifacts by triggering this action.
47 */
48 virtual void cleanArtifacts() = 0;
49};
50
51/** Object that actually handles the update itself. */
52class UpdateHandler : public UpdateHandlerInterface
53{
54 public:
55 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
56 blob(blob), handler(handler)
57 {
58 }
59
60 ~UpdateHandler() = default;
61
62 bool checkAvailable(const std::string& goalFirmware) override;
63
64 /**
65 * @throw ToolException on failure.
66 */
67 void sendFile(const std::string& target, const std::string& path) override;
68
69 /**
70 * @throw ToolException on failure (TODO: throw on timeout.)
71 */
Brandon Kim6749ba12019-09-19 13:31:37 -070072 bool verifyFile(const std::string& target, bool ignoreStatus) override;
Patrick Venture01123b22019-06-20 13:49:06 -070073
74 void cleanArtifacts() override;
75
76 private:
77 ipmiblob::BlobInterface* blob;
78 DataInterface* handler;
79};
80
81} // namespace host_tool