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> |
Jason Ling | ded66d0 | 2020-10-23 14:13:03 -0700 | [diff] [blame^] | 4 | #include <fstream> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 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 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 51 | class HandlerPack |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 52 | { |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 53 | public: |
| 54 | HandlerPack(const std::string& name, |
| 55 | std::unique_ptr<ImageHandlerInterface> handler) : |
| 56 | blobName(name), |
| 57 | handler(std::move(handler)) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 58 | {} |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 59 | |
| 60 | HandlerPack() = default; |
| 61 | ~HandlerPack() = default; |
| 62 | HandlerPack(const HandlerPack&) = delete; |
| 63 | HandlerPack& operator=(const HandlerPack&) = delete; |
| 64 | HandlerPack(HandlerPack&&) = default; |
| 65 | HandlerPack& operator=(HandlerPack&&) = default; |
| 66 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 67 | std::string blobName; |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 68 | std::unique_ptr<ImageHandlerInterface> handler; |
Patrick Venture | 25528b4 | 2018-11-06 18:29:43 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 71 | } // namespace ipmi_flash |