blob: 75f7660ff76c4a493354b83c7fb55f98f24bed08 [file] [log] [blame]
Patrick Venture33bf1692018-11-06 20:19:17 -08001#pragma once
2
Patrick Venture1cde5f92018-11-07 08:26:47 -08003#include <cstdint>
4#include <vector>
5
Patrick Venture33bf1692018-11-06 20:19:17 -08006namespace blobs
7{
8
9/**
10 * Each data transport mechanism must implement the DataInterface.
11 */
12class DataInterface
13{
14 public:
15 virtual ~DataInterface() = default;
Patrick Venture1cde5f92018-11-07 08:26:47 -080016
17 /**
Patrick Venture0d2a8132018-11-09 11:34:21 -080018 * 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 Venture0fbabf22018-11-09 11:54:12 -080026 * Close the data transport mechanism.
27 *
28 * @return true if successful
29 */
30 virtual bool close() = 0;
31
32 /**
Patrick Venture1cde5f92018-11-07 08:26:47 -080033 * 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 Venture8c535332018-11-08 15:58:00 -080039
40 /**
41 * set configuration.
42 *
43 * @param[in] configuration - byte vector of data.
44 * @return bool - returns true on success.
45 */
Patrick Venture74304642019-01-17 09:31:04 -080046 virtual bool writeMeta(const std::vector<std::uint8_t>& configuration) = 0;
Patrick Venture8c535332018-11-08 15:58:00 -080047
48 /**
49 * read configuration.
50 *
51 * @return bytes - whatever bytes are required configuration information for
52 * the mechanism.
53 */
Patrick Venture74304642019-01-17 09:31:04 -080054 virtual std::vector<std::uint8_t> readMeta() = 0;
Patrick Venture1cde5f92018-11-07 08:26:47 -080055};
56
57struct DataHandlerPack
58{
59 std::uint16_t bitmask;
60 DataInterface* handler;
Patrick Venture33bf1692018-11-06 20:19:17 -080061};
62
63} // namespace blobs