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