1*f0c71df2SPatrick Venture #pragma once 2*f0c71df2SPatrick Venture 3*f0c71df2SPatrick Venture #include "image_handler.hpp" 4*f0c71df2SPatrick Venture 5*f0c71df2SPatrick Venture #include <cstdint> 6*f0c71df2SPatrick Venture #include <fstream> 7*f0c71df2SPatrick Venture #include <memory> 8*f0c71df2SPatrick Venture #include <string> 9*f0c71df2SPatrick Venture #include <vector> 10*f0c71df2SPatrick Venture 11*f0c71df2SPatrick Venture namespace ipmi_flash 12*f0c71df2SPatrick Venture { 13*f0c71df2SPatrick Venture 14*f0c71df2SPatrick Venture class FileHandler : public ImageHandlerInterface 15*f0c71df2SPatrick Venture { 16*f0c71df2SPatrick Venture public: 17*f0c71df2SPatrick Venture /** 18*f0c71df2SPatrick Venture * Create a FileHandler. This object is basically a filewriter. 19*f0c71df2SPatrick Venture * 20*f0c71df2SPatrick Venture * @param[in] filename - file to use for the contents, fully 21*f0c71df2SPatrick Venture * qualified file system path. 22*f0c71df2SPatrick Venture */ 23*f0c71df2SPatrick Venture explicit FileHandler(const std::string& filename) : filename(filename) 24*f0c71df2SPatrick Venture { 25*f0c71df2SPatrick Venture } 26*f0c71df2SPatrick Venture 27*f0c71df2SPatrick Venture bool open(const std::string& path) override; 28*f0c71df2SPatrick Venture void close() override; 29*f0c71df2SPatrick Venture bool write(std::uint32_t offset, 30*f0c71df2SPatrick Venture const std::vector<std::uint8_t>& data) override; 31*f0c71df2SPatrick Venture int getSize() override; 32*f0c71df2SPatrick Venture 33*f0c71df2SPatrick Venture private: 34*f0c71df2SPatrick Venture /** the active hash path, ignore. */ 35*f0c71df2SPatrick Venture std::string path; 36*f0c71df2SPatrick Venture 37*f0c71df2SPatrick Venture /** The file handle. */ 38*f0c71df2SPatrick Venture std::ofstream file; 39*f0c71df2SPatrick Venture 40*f0c71df2SPatrick Venture /** The filename (including path) to use to write bytes. */ 41*f0c71df2SPatrick Venture std::string filename; 42*f0c71df2SPatrick Venture }; 43*f0c71df2SPatrick Venture 44*f0c71df2SPatrick Venture } // namespace ipmi_flash 45