Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "interface.hpp" |
| 4 | |
| 5 | #include <ipmiblob/blob_interface.hpp> |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 6 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
| 9 | namespace host_tool |
| 10 | { |
| 11 | |
| 12 | class 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 Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 40 | * @param[in] ignoreStatus - determines whether to ignore the verification |
| 41 | * status. |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 42 | * @return true if verified, false if verification errors. |
| 43 | */ |
Brandon Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 44 | virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0; |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 47 | * 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 Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 56 | * Cleanup the artifacts by triggering this action. |
| 57 | */ |
| 58 | virtual void cleanArtifacts() = 0; |
| 59 | }; |
| 60 | |
| 61 | /** Object that actually handles the update itself. */ |
| 62 | class UpdateHandler : public UpdateHandlerInterface |
| 63 | { |
| 64 | public: |
| 65 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 66 | blob(blob), handler(handler) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 67 | {} |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 68 | |
| 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 Tu | 1b23b77 | 2023-03-15 01:33:03 -0700 | [diff] [blame] | 79 | * @throw ToolException on failure. |
| 80 | */ |
| 81 | void retrySendFile(const std::string& target, const std::string& path); |
| 82 | |
| 83 | /** |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 84 | * @throw ToolException on failure (TODO: throw on timeout.) |
| 85 | */ |
Brandon Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 86 | bool verifyFile(const std::string& target, bool ignoreStatus) override; |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 87 | |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 88 | std::vector<uint8_t> readVersion(const std::string& versionBlob) override; |
| 89 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 90 | void cleanArtifacts() override; |
| 91 | |
| 92 | private: |
| 93 | ipmiblob::BlobInterface* blob; |
| 94 | DataInterface* handler; |
| 95 | }; |
| 96 | |
| 97 | } // namespace host_tool |