blob: 162347cdd7c69dd192b06b4e779d8596ce085593 [file] [log] [blame]
Patrick Venture33bf1692018-11-06 20:19:17 -08001#pragma once
2
Patrick Venture1cde5f92018-11-07 08:26:47 -08003#include <cstdint>
Patrick Venture4934daa2020-09-22 16:37:44 -07004#include <memory>
Patrick Venture1cde5f92018-11-07 08:26:47 -08005#include <vector>
6
Patrick Venture1d5a31c2019-05-20 11:38:22 -07007namespace ipmi_flash
Patrick Venture33bf1692018-11-06 20:19:17 -08008{
9
10/**
11 * Each data transport mechanism must implement the DataInterface.
12 */
13class DataInterface
14{
15 public:
16 virtual ~DataInterface() = default;
Patrick Venture1cde5f92018-11-07 08:26:47 -080017
18 /**
Patrick Venture0d2a8132018-11-09 11:34:21 -080019 * 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 Venture0fbabf22018-11-09 11:54:12 -080027 * Close the data transport mechanism.
28 *
29 * @return true if successful
30 */
31 virtual bool close() = 0;
32
33 /**
Patrick Venture1cde5f92018-11-07 08:26:47 -080034 * 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 Venture8c535332018-11-08 15:58:00 -080040
41 /**
42 * set configuration.
43 *
44 * @param[in] configuration - byte vector of data.
45 * @return bool - returns true on success.
46 */
Patrick Venture74304642019-01-17 09:31:04 -080047 virtual bool writeMeta(const std::vector<std::uint8_t>& configuration) = 0;
Patrick Venture8c535332018-11-08 15:58:00 -080048
49 /**
50 * read configuration.
51 *
52 * @return bytes - whatever bytes are required configuration information for
53 * the mechanism.
54 */
Patrick Venture74304642019-01-17 09:31:04 -080055 virtual std::vector<std::uint8_t> readMeta() = 0;
Patrick Venture1cde5f92018-11-07 08:26:47 -080056};
57
58struct DataHandlerPack
59{
60 std::uint16_t bitmask;
Patrick Venture4934daa2020-09-22 16:37:44 -070061 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 Venture33bf1692018-11-06 20:19:17 -080074};
75
Patrick Venture1d5a31c2019-05-20 11:38:22 -070076} // namespace ipmi_flash