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 * @param[in] ignoreStatus - determines whether to ignore the verification 40 * status. 41 * @return true if verified, false if verification errors. 42 */ 43 virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0; 44 45 /** 46 * Cleanup the artifacts by triggering this action. 47 */ 48 virtual void cleanArtifacts() = 0; 49 }; 50 51 /** Object that actually handles the update itself. */ 52 class UpdateHandler : public UpdateHandlerInterface 53 { 54 public: 55 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : 56 blob(blob), handler(handler) 57 { 58 } 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 */ 72 bool verifyFile(const std::string& target, bool ignoreStatus) override; 73 74 void cleanArtifacts() override; 75 76 private: 77 ipmiblob::BlobInterface* blob; 78 DataInterface* handler; 79 }; 80 81 } // namespace host_tool 82