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 | /** |
| 47 | * Cleanup the artifacts by triggering this action. |
| 48 | */ |
| 49 | virtual void cleanArtifacts() = 0; |
| 50 | }; |
| 51 | |
| 52 | /** Object that actually handles the update itself. */ |
| 53 | class UpdateHandler : public UpdateHandlerInterface |
| 54 | { |
| 55 | public: |
| 56 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 57 | blob(blob), handler(handler) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 58 | {} |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 59 | |
| 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 Kim | 6749ba1 | 2019-09-19 13:31:37 -0700 | [diff] [blame] | 72 | bool verifyFile(const std::string& target, bool ignoreStatus) override; |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 73 | |
| 74 | void cleanArtifacts() override; |
| 75 | |
| 76 | private: |
| 77 | ipmiblob::BlobInterface* blob; |
| 78 | DataInterface* handler; |
| 79 | }; |
| 80 | |
| 81 | } // namespace host_tool |