blob: 4d2fe50caa079ab219e920ab00de58796ff85c8b [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>
Patrick Venture9b37b092020-05-28 20:58:57 -07006
Patrick Venture01123b22019-06-20 13:49:06 -07007#include <string>
8
9namespace host_tool
10{
11
12class UpdateHandlerInterface
13{
14 public:
15 virtual ~UpdateHandlerInterface() = default;
16
17 /**
18 * Check if the goal firmware is listed in the blob_list and that the
19 * handler's supported data type is available.
20 *
21 * @param[in] goalFirmware - the firmware to check /flash/image
22 * /flash/tarball, etc.
23 */
24 virtual bool checkAvailable(const std::string& goalFirmware) = 0;
25
26 /**
27 * Send the file contents at path to the blob id, target.
28 *
29 * @param[in] target - the blob id
30 * @param[in] path - the source file path
31 */
32 virtual void sendFile(const std::string& target,
33 const std::string& path) = 0;
34
35 /**
36 * Trigger verification.
37 *
38 * @param[in] target - the verification blob id (may support multiple in the
39 * future.
Brandon Kim6749ba12019-09-19 13:31:37 -070040 * @param[in] ignoreStatus - determines whether to ignore the verification
41 * status.
Patrick Venture01123b22019-06-20 13:49:06 -070042 * @return true if verified, false if verification errors.
43 */
Brandon Kim6749ba12019-09-19 13:31:37 -070044 virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0;
Patrick Venture01123b22019-06-20 13:49:06 -070045
46 /**
Jie Yang328f5202021-03-16 00:52:07 -070047 * Read the active firmware version.
48 *
49 * @param[in] versionBlob - the version blob id within the version handler.
50 * @return firmware version
51 */
52 virtual std::vector<uint8_t>
53 readVersion(const std::string& versionBlob) = 0;
54
55 /**
Patrick Venture01123b22019-06-20 13:49:06 -070056 * Cleanup the artifacts by triggering this action.
57 */
58 virtual void cleanArtifacts() = 0;
59};
60
61/** Object that actually handles the update itself. */
62class UpdateHandler : public UpdateHandlerInterface
63{
64 public:
65 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
66 blob(blob), handler(handler)
Patrick Venture9b37b092020-05-28 20:58:57 -070067 {}
Patrick Venture01123b22019-06-20 13:49:06 -070068
69 ~UpdateHandler() = default;
70
71 bool checkAvailable(const std::string& goalFirmware) override;
72
73 /**
74 * @throw ToolException on failure.
75 */
76 void sendFile(const std::string& target, const std::string& path) override;
77
78 /**
Willy Tu1b23b772023-03-15 01:33:03 -070079 * @throw ToolException on failure.
80 */
81 void retrySendFile(const std::string& target, const std::string& path);
82
83 /**
Patrick Venture01123b22019-06-20 13:49:06 -070084 * @throw ToolException on failure (TODO: throw on timeout.)
85 */
Brandon Kim6749ba12019-09-19 13:31:37 -070086 bool verifyFile(const std::string& target, bool ignoreStatus) override;
Patrick Venture01123b22019-06-20 13:49:06 -070087
Jie Yang328f5202021-03-16 00:52:07 -070088 std::vector<uint8_t> readVersion(const std::string& versionBlob) override;
89
Patrick Venture01123b22019-06-20 13:49:06 -070090 void cleanArtifacts() override;
91
92 private:
93 ipmiblob::BlobInterface* blob;
94 DataInterface* handler;
95};
96
97} // namespace host_tool