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