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