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> |
Willy Tu | 3f59628 | 2024-04-12 16:27:17 +0000 | [diff] [blame] | 6 | #include <stdplus/function_view.hpp> |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 7 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | namespace host_tool |
| 11 | { |
| 12 | |
| 13 | class 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 Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 41 | * @param[in] ignoreStatus - determines whether to ignore the verification |
| 42 | * status. |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 43 | * @return true if verified, false if verification errors. |
| 44 | */ |
Brandon Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 45 | virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0; |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 48 | * 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 Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 57 | * Cleanup the artifacts by triggering this action. |
| 58 | */ |
| 59 | virtual void cleanArtifacts() = 0; |
| 60 | }; |
| 61 | |
| 62 | /** Object that actually handles the update itself. */ |
| 63 | class UpdateHandler : public UpdateHandlerInterface |
| 64 | { |
| 65 | public: |
| 66 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 67 | blob(blob), handler(handler) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 68 | {} |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 69 | |
| 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 Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 82 | bool verifyFile(const std::string& target, bool ignoreStatus) override; |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 83 | |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 84 | std::vector<uint8_t> readVersion(const std::string& versionBlob) override; |
| 85 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 86 | void cleanArtifacts() override; |
| 87 | |
| 88 | private: |
| 89 | ipmiblob::BlobInterface* blob; |
| 90 | DataInterface* handler; |
Willy Tu | 3f59628 | 2024-04-12 16:27:17 +0000 | [diff] [blame] | 91 | |
| 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 Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace host_tool |