1 #pragma once 2 3 #include "interface.hpp" 4 5 #include <ipmiblob/blob_interface.hpp> 6 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. 40 * @param[in] ignoreStatus - determines whether to ignore the verification 41 * status. 42 * @return true if verified, false if verification errors. 43 */ 44 virtual bool verifyFile(const std::string& target, bool ignoreStatus) = 0; 45 46 /** 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 /** 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) 67 {} 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 /** 79 * @throw ToolException on failure. 80 */ 81 void retrySendFile(const std::string& target, const std::string& path); 82 83 /** 84 * @throw ToolException on failure (TODO: throw on timeout.) 85 */ 86 bool verifyFile(const std::string& target, bool ignoreStatus) override; 87 88 std::vector<uint8_t> readVersion(const std::string& versionBlob) override; 89 90 void cleanArtifacts() override; 91 92 private: 93 ipmiblob::BlobInterface* blob; 94 DataInterface* handler; 95 }; 96 97 } // namespace host_tool 98