1*f0c71df2SPatrick Venture #pragma once
2*f0c71df2SPatrick Venture 
3*f0c71df2SPatrick Venture #include <cstdint>
4*f0c71df2SPatrick Venture #include <functional>
5*f0c71df2SPatrick Venture #include <memory>
6*f0c71df2SPatrick Venture #include <string>
7*f0c71df2SPatrick Venture #include <vector>
8*f0c71df2SPatrick Venture 
9*f0c71df2SPatrick Venture namespace ipmi_flash
10*f0c71df2SPatrick Venture {
11*f0c71df2SPatrick Venture 
12*f0c71df2SPatrick Venture /**
13*f0c71df2SPatrick Venture  * Each image update mechanism must implement the ImageHandlerInterface.
14*f0c71df2SPatrick Venture  */
15*f0c71df2SPatrick Venture class ImageHandlerInterface
16*f0c71df2SPatrick Venture {
17*f0c71df2SPatrick Venture   public:
18*f0c71df2SPatrick Venture     virtual ~ImageHandlerInterface() = default;
19*f0c71df2SPatrick Venture 
20*f0c71df2SPatrick Venture     /**
21*f0c71df2SPatrick Venture      * open the firmware update mechanism.
22*f0c71df2SPatrick Venture      *
23*f0c71df2SPatrick Venture      * @param[in] path - the path passed to the handler (the blob_id).
24*f0c71df2SPatrick Venture      * @return bool - returns true on success.
25*f0c71df2SPatrick Venture      */
26*f0c71df2SPatrick Venture     virtual bool open(const std::string& path) = 0;
27*f0c71df2SPatrick Venture 
28*f0c71df2SPatrick Venture     /**
29*f0c71df2SPatrick Venture      * close the image.
30*f0c71df2SPatrick Venture      */
31*f0c71df2SPatrick Venture     virtual void close() = 0;
32*f0c71df2SPatrick Venture 
33*f0c71df2SPatrick Venture     /**
34*f0c71df2SPatrick Venture      * write data to the staged file.
35*f0c71df2SPatrick Venture      *
36*f0c71df2SPatrick Venture      * @param[in] offset - 0-based offset into the file.
37*f0c71df2SPatrick Venture      * @param[in] data - the data to write.
38*f0c71df2SPatrick Venture      * @return bool - returns true on success.
39*f0c71df2SPatrick Venture      */
40*f0c71df2SPatrick Venture     virtual bool write(std::uint32_t offset,
41*f0c71df2SPatrick Venture                        const std::vector<std::uint8_t>& data) = 0;
42*f0c71df2SPatrick Venture 
43*f0c71df2SPatrick Venture     /**
44*f0c71df2SPatrick Venture      * return the size of the file (if that notion makes sense).
45*f0c71df2SPatrick Venture      *
46*f0c71df2SPatrick Venture      * @return the size in bytes of the image staged.
47*f0c71df2SPatrick Venture      */
48*f0c71df2SPatrick Venture     virtual int getSize() = 0;
49*f0c71df2SPatrick Venture };
50*f0c71df2SPatrick Venture 
51*f0c71df2SPatrick Venture struct HandlerPack
52*f0c71df2SPatrick Venture {
53*f0c71df2SPatrick Venture     std::string blobName;
54*f0c71df2SPatrick Venture     ImageHandlerInterface* handler;
55*f0c71df2SPatrick Venture };
56*f0c71df2SPatrick Venture 
57*f0c71df2SPatrick Venture } // namespace ipmi_flash
58