blob: a0c23aff7cef481d9e4fb6db8ce8034f167c3ab7 [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 */
Patrick Williams10388362023-05-10 07:51:09 -050023 explicit FileHandler(const std::string& filename) : filename(filename) {}
Patrick Venture64919ec2018-11-15 11:52:07 -080024
Jason Ling56a22732020-10-23 19:53:17 -070025 bool open(const std::string& path,
26 std::ios_base::openmode mode = std::ios::out) override;
Patrick Venture64919ec2018-11-15 11:52:07 -080027 void close() override;
28 bool write(std::uint32_t offset,
29 const std::vector<std::uint8_t>& data) override;
Jason Ling56a22732020-10-23 19:53:17 -070030 virtual std::optional<std::vector<uint8_t>>
31 read(std::uint32_t offset, std::uint32_t size) override;
Patrick Venturecc7d1602018-11-15 13:58:33 -080032 int getSize() override;
Patrick Venture64919ec2018-11-15 11:52:07 -080033
34 private:
35 /** the active hash path, ignore. */
36 std::string path;
37
38 /** The file handle. */
Jason Ling56a22732020-10-23 19:53:17 -070039 std::fstream file;
Patrick Venture64919ec2018-11-15 11:52:07 -080040
41 /** The filename (including path) to use to write bytes. */
42 std::string filename;
43};
44
Patrick Venture1d5a31c2019-05-20 11:38:22 -070045} // namespace ipmi_flash