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> |
| 6 | #include <string> |
| 7 | |
| 8 | namespace host_tool |
| 9 | { |
| 10 | |
| 11 | class UpdateHandlerInterface |
| 12 | { |
| 13 | public: |
| 14 | virtual ~UpdateHandlerInterface() = default; |
| 15 | |
| 16 | /** |
| 17 | * Check if the goal firmware is listed in the blob_list and that the |
| 18 | * handler's supported data type is available. |
| 19 | * |
| 20 | * @param[in] goalFirmware - the firmware to check /flash/image |
| 21 | * /flash/tarball, etc. |
| 22 | */ |
| 23 | virtual bool checkAvailable(const std::string& goalFirmware) = 0; |
| 24 | |
| 25 | /** |
| 26 | * Send the file contents at path to the blob id, target. |
| 27 | * |
| 28 | * @param[in] target - the blob id |
| 29 | * @param[in] path - the source file path |
| 30 | */ |
| 31 | virtual void sendFile(const std::string& target, |
| 32 | const std::string& path) = 0; |
| 33 | |
| 34 | /** |
| 35 | * Trigger verification. |
| 36 | * |
| 37 | * @param[in] target - the verification blob id (may support multiple in the |
| 38 | * future. |
| 39 | * @return true if verified, false if verification errors. |
| 40 | */ |
| 41 | virtual bool verifyFile(const std::string& target) = 0; |
| 42 | |
| 43 | /** |
| 44 | * Cleanup the artifacts by triggering this action. |
| 45 | */ |
| 46 | virtual void cleanArtifacts() = 0; |
| 47 | }; |
| 48 | |
| 49 | /** Object that actually handles the update itself. */ |
| 50 | class UpdateHandler : public UpdateHandlerInterface |
| 51 | { |
| 52 | public: |
| 53 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 54 | blob(blob), handler(handler) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | ~UpdateHandler() = default; |
| 59 | |
| 60 | bool checkAvailable(const std::string& goalFirmware) override; |
| 61 | |
| 62 | /** |
| 63 | * @throw ToolException on failure. |
| 64 | */ |
| 65 | void sendFile(const std::string& target, const std::string& path) override; |
| 66 | |
| 67 | /** |
| 68 | * @throw ToolException on failure (TODO: throw on timeout.) |
| 69 | */ |
| 70 | bool verifyFile(const std::string& target) override; |
| 71 | |
| 72 | void cleanArtifacts() override; |
| 73 | |
| 74 | private: |
| 75 | ipmiblob::BlobInterface* blob; |
| 76 | DataInterface* handler; |
| 77 | }; |
| 78 | |
| 79 | } // namespace host_tool |