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