blob: 5820fbab1a37b8cd142d336520b63d5e6da949e6 [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 /**
47 * Cleanup the artifacts by triggering this action.
48 */
49 virtual void cleanArtifacts() = 0;
50};
51
52/** Object that actually handles the update itself. */
53class UpdateHandler : public UpdateHandlerInterface
54{
55 public:
56 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
57 blob(blob), handler(handler)
Patrick Venture9b37b092020-05-28 20:58:57 -070058 {}
Patrick Venture01123b22019-06-20 13:49:06 -070059
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