Patrick Venture | 25528b4 | 2018-11-06 18:29:43 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 400c636 | 2018-11-06 20:06:11 -0800 | [diff] [blame] | 3 | #include <cstdint> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 4 | #include <functional> |
| 5 | #include <memory> |
| 6 | #include <string> |
Patrick Venture | 400c636 | 2018-11-06 20:06:11 -0800 | [diff] [blame] | 7 | #include <vector> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 8 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 9 | namespace ipmi_flash |
Patrick Venture | 25528b4 | 2018-11-06 18:29:43 -0800 | [diff] [blame] | 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 | * |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 23 | * @param[in] path - the path passed to the handler (the blob_id). |
Patrick Venture | 25528b4 | 2018-11-06 18:29:43 -0800 | [diff] [blame] | 24 | * @return bool - returns true on success. |
| 25 | */ |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 26 | virtual bool open(const std::string& path) = 0; |
Patrick Venture | 400c636 | 2018-11-06 20:06:11 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 29 | * close the image. |
| 30 | */ |
| 31 | virtual void close() = 0; |
| 32 | |
| 33 | /** |
Patrick Venture | 400c636 | 2018-11-06 20:06:11 -0800 | [diff] [blame] | 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; |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 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; |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct HandlerPack |
| 52 | { |
| 53 | std::string blobName; |
| 54 | ImageHandlerInterface* handler; |
Patrick Venture | 25528b4 | 2018-11-06 18:29:43 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 57 | } // namespace ipmi_flash |