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