#pragma once #include #include #include #include #include #include namespace ipmi_flash { /** * Each image update mechanism must implement the ImageHandlerInterface. */ class ImageHandlerInterface { public: virtual ~ImageHandlerInterface() = default; /** * open the firmware update mechanism. * * @param[in] path - the path passed to the handler (the blob_id). * @return bool - returns true on success. */ virtual bool open(const std::string& path, std::ios_base::openmode mode) = 0; /** * close the image. */ virtual void close() = 0; /** * write data to the staged file. * * @param[in] offset - 0-based offset into the file. * @param[in] data - the data to write. * @return bool - returns true on success. */ virtual bool write(std::uint32_t offset, const std::vector& data) = 0; /** * read data from a file. * * @param[in] offset - 0-based offset into the file. * @param[in] size - the number of bytes * @return std::optional> - returns std::nullopt * on failure otherwise returns a vector filled with the bytes read. * */ virtual std::optional> read(std::uint32_t offset, std::uint32_t size) = 0; /** * return the size of the file (if that notion makes sense). * * @return the size in bytes of the image staged. */ virtual int getSize() = 0; }; class HandlerPack { public: HandlerPack(const std::string& name, std::unique_ptr handler) : blobName(name), handler(std::move(handler)) {} HandlerPack() = default; ~HandlerPack() = default; HandlerPack(const HandlerPack&) = delete; HandlerPack& operator=(const HandlerPack&) = delete; HandlerPack(HandlerPack&&) = default; HandlerPack& operator=(HandlerPack&&) = default; std::string blobName; std::unique_ptr handler; }; } // namespace ipmi_flash