Patrick Venture | 33bf169 | 2018-11-06 20:19:17 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 3 | #include <cstdint> |
| 4 | #include <vector> |
| 5 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 6 | namespace ipmi_flash |
Patrick Venture | 33bf169 | 2018-11-06 20:19:17 -0800 | [diff] [blame] | 7 | { |
| 8 | |
| 9 | /** |
| 10 | * Each data transport mechanism must implement the DataInterface. |
| 11 | */ |
| 12 | class DataInterface |
| 13 | { |
| 14 | public: |
| 15 | virtual ~DataInterface() = default; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 16 | |
| 17 | /** |
Patrick Venture | 0d2a813 | 2018-11-09 11:34:21 -0800 | [diff] [blame] | 18 | * Initialize data transport mechanism. Calling this should be idempotent |
| 19 | * if possible. |
| 20 | * |
| 21 | * @return true if successful |
| 22 | */ |
| 23 | virtual bool open() = 0; |
| 24 | |
| 25 | /** |
Patrick Venture | 0fbabf2 | 2018-11-09 11:54:12 -0800 | [diff] [blame] | 26 | * Close the data transport mechanism. |
| 27 | * |
| 28 | * @return true if successful |
| 29 | */ |
| 30 | virtual bool close() = 0; |
| 31 | |
| 32 | /** |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 33 | * Copy bytes from external interface (blocking call). |
| 34 | * |
| 35 | * @param[in] length - number of bytes to copy |
| 36 | * @return the bytes read |
| 37 | */ |
| 38 | virtual std::vector<std::uint8_t> copyFrom(std::uint32_t length) = 0; |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * set configuration. |
| 42 | * |
| 43 | * @param[in] configuration - byte vector of data. |
| 44 | * @return bool - returns true on success. |
| 45 | */ |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 46 | virtual bool writeMeta(const std::vector<std::uint8_t>& configuration) = 0; |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * read configuration. |
| 50 | * |
| 51 | * @return bytes - whatever bytes are required configuration information for |
| 52 | * the mechanism. |
| 53 | */ |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 54 | virtual std::vector<std::uint8_t> readMeta() = 0; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct DataHandlerPack |
| 58 | { |
| 59 | std::uint16_t bitmask; |
| 60 | DataInterface* handler; |
Patrick Venture | 33bf169 | 2018-11-06 20:19:17 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 63 | } // namespace ipmi_flash |