blob: 25dc2f58ea20192b81e663828edd90846482a93e [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>
Willy Tu3f596282024-04-12 16:27:17 +00006#include <stdplus/function_view.hpp>
Patrick Venture9b37b092020-05-28 20:58:57 -07007
Patrick Venture01123b22019-06-20 13:49:06 -07008#include <string>
9
10namespace host_tool
11{
12
13class UpdateHandlerInterface
14{
15 public:
16 virtual ~UpdateHandlerInterface() = default;
17
18 /**
19 * Check if the goal firmware is listed in the blob_list and that the
20 * handler's supported data type is available.
21 *
22 * @param[in] goalFirmware - the firmware to check /flash/image
23 * /flash/tarball, etc.
24 */
25 virtual bool checkAvailable(const std::string& goalFirmware) = 0;
26
27 /**
28 * Send the file contents at path to the blob id, target.
29 *
30 * @param[in] target - the blob id
31 * @param[in] path - the source file path
32 */
33 virtual void sendFile(const std::string& target,
34 const std::string& path) = 0;
35
36 /**
37 * Trigger verification.
38 *
39 * @param[in] target - the verification blob id (may support multiple in the
40 * future.
Brandon Kim6749ba12019-09-19 13:31:37 -070041 * @param[in] ignoreStatus - determines whether to ignore the verification
42 * status.
Patrick Venture01123b22019-06-20 13:49:06 -070043 * @return true if verified, false if verification errors.
44 */
Brandon Kim6749ba12019-09-19 13:31:37 -070045 virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0;
Patrick Venture01123b22019-06-20 13:49:06 -070046
47 /**
Jie Yang328f5202021-03-16 00:52:07 -070048 * Read the active firmware version.
49 *
50 * @param[in] versionBlob - the version blob id within the version handler.
51 * @return firmware version
52 */
53 virtual std::vector<uint8_t>
54 readVersion(const std::string& versionBlob) = 0;
55
56 /**
Patrick Venture01123b22019-06-20 13:49:06 -070057 * Cleanup the artifacts by triggering this action.
58 */
59 virtual void cleanArtifacts() = 0;
60};
61
62/** Object that actually handles the update itself. */
63class UpdateHandler : public UpdateHandlerInterface
64{
65 public:
66 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
67 blob(blob), handler(handler)
Patrick Venture9b37b092020-05-28 20:58:57 -070068 {}
Patrick Venture01123b22019-06-20 13:49:06 -070069
70 ~UpdateHandler() = default;
71
72 bool checkAvailable(const std::string& goalFirmware) override;
73
74 /**
75 * @throw ToolException on failure.
76 */
77 void sendFile(const std::string& target, const std::string& path) override;
78
79 /**
80 * @throw ToolException on failure (TODO: throw on timeout.)
81 */
Brandon Kim6749ba12019-09-19 13:31:37 -070082 bool verifyFile(const std::string& target, bool ignoreStatus) override;
Patrick Venture01123b22019-06-20 13:49:06 -070083
Jie Yang328f5202021-03-16 00:52:07 -070084 std::vector<uint8_t> readVersion(const std::string& versionBlob) override;
85
Patrick Venture01123b22019-06-20 13:49:06 -070086 void cleanArtifacts() override;
87
88 private:
89 ipmiblob::BlobInterface* blob;
90 DataInterface* handler;
Willy Tu3f596282024-04-12 16:27:17 +000091
92 /**
93 * @throw ToolException on failure.
94 */
95 void retrySendFile(const std::string& target, const std::string& path);
96
97 /**
98 * @throw ToolException on failure (TODO: throw on timeout.)
99 */
100 void retryVerifyFile(const std::string& target, bool ignoreStatus);
101
102 /**
103 * @throw ToolException on failure.
104 */
105 std::vector<uint8_t> retryReadVersion(const std::string& versionBlob);
106
107 /**
108 * @throw ToolException on failure.
109 */
110 std::vector<uint8_t>
111 retryIfFailed(stdplus::function_view<std::vector<uint8_t>()> callback);
Patrick Venture01123b22019-06-20 13:49:06 -0700112};
113
114} // namespace host_tool