summaryrefslogtreecommitdiffstats
path: root/bmc/file_handler.hpp
blob: 9cb2819dad976ffac15d6fa88af996f255b46d3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "image_handler.hpp"

#include <cstdint>
#include <fstream>
#include <memory>
#include <string>
#include <vector>

namespace ipmi_flash
{

class FileHandler : public ImageHandlerInterface
{
  public:
    /**
     * Create a FileHandler.  This object is basically a filewriter.
     *
     * @param[in] filename - file to use for the contents, fully
     * qualified file system path.
     */
    explicit FileHandler(const std::string& filename) : filename(filename)
    {
    }

    bool open(const std::string& path) override;
    void close() override;
    bool write(std::uint32_t offset,
               const std::vector<std::uint8_t>& data) override;
    int getSize() override;

  private:
    /** the active hash path, ignore. */
    std::string path;

    /** The file handle. */
    std::ofstream file;

    /** The filename (including path) to use to write bytes. */
    std::string filename;
};

} // namespace ipmi_flash
OpenPOWER on IntegriCloud