1 #pragma once 2 3 #include <cstdint> 4 #include <functional> 5 #include <memory> 6 #include <string> 7 #include <vector> 8 9 namespace ipmi_flash 10 { 11 12 /** 13 * Each image update mechanism must implement the ImageHandlerInterface. 14 */ 15 class ImageHandlerInterface 16 { 17 public: 18 virtual ~ImageHandlerInterface() = default; 19 20 /** 21 * open the firmware update mechanism. 22 * 23 * @param[in] path - the path passed to the handler (the blob_id). 24 * @return bool - returns true on success. 25 */ 26 virtual bool open(const std::string& path) = 0; 27 28 /** 29 * close the image. 30 */ 31 virtual void close() = 0; 32 33 /** 34 * write data to the staged file. 35 * 36 * @param[in] offset - 0-based offset into the file. 37 * @param[in] data - the data to write. 38 * @return bool - returns true on success. 39 */ 40 virtual bool write(std::uint32_t offset, 41 const std::vector<std::uint8_t>& data) = 0; 42 43 /** 44 * return the size of the file (if that notion makes sense). 45 * 46 * @return the size in bytes of the image staged. 47 */ 48 virtual int getSize() = 0; 49 }; 50 51 class HandlerPack 52 { 53 public: 54 HandlerPack(const std::string& name, 55 std::unique_ptr<ImageHandlerInterface> handler) : 56 blobName(name), 57 handler(std::move(handler)) 58 {} 59 60 HandlerPack() = default; 61 ~HandlerPack() = default; 62 HandlerPack(const HandlerPack&) = delete; 63 HandlerPack& operator=(const HandlerPack&) = delete; 64 HandlerPack(HandlerPack&&) = default; 65 HandlerPack& operator=(HandlerPack&&) = default; 66 67 std::string blobName; 68 std::unique_ptr<ImageHandlerInterface> handler; 69 }; 70 71 } // namespace ipmi_flash 72