xref: /openbmc/phosphor-ipmi-flash/bmc/firmware-handler/data_handler.hpp (revision 42a44c281cce08be0ca6251955f4fb73d30c8ced)
1 #pragma once
2 
3 #include <cstdint>
4 #include <memory>
5 #include <vector>
6 
7 namespace ipmi_flash
8 {
9 
10 /**
11  * Each data transport mechanism must implement the DataInterface.
12  */
13 class DataInterface
14 {
15   public:
16     virtual ~DataInterface() = default;
17 
18     /**
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     /**
27      * Close the data transport mechanism.
28      *
29      * @return true if successful
30      */
31     virtual bool close() = 0;
32 
33     /**
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;
40 
41     /**
42      * set configuration.
43      *
44      * @param[in] configuration - byte vector of data.
45      * @return bool - returns true on success.
46      */
47     virtual bool writeMeta(const std::vector<std::uint8_t>& configuration) = 0;
48 
49     /**
50      * read configuration.
51      *
52      * @return bytes - whatever bytes are required configuration information for
53      * the mechanism.
54      */
55     virtual std::vector<std::uint8_t> readMeta() = 0;
56 };
57 
58 struct DataHandlerPack
59 {
60     std::uint16_t bitmask;
61     std::unique_ptr<DataInterface> handler;
62 
DataHandlerPackipmi_flash::DataHandlerPack63     DataHandlerPack(std::uint16_t bitmask,
64                     std::unique_ptr<DataInterface> handler) :
65         bitmask(bitmask), handler(std::move(handler))
66     {}
67 
68     /* Don't allow copying, assignment or move assignment, only moving. */
69     DataHandlerPack(const DataHandlerPack&) = delete;
70     DataHandlerPack& operator=(const DataHandlerPack&) = delete;
71     DataHandlerPack(DataHandlerPack&&) = default;
72     DataHandlerPack& operator=(DataHandlerPack&&) = delete;
73 };
74 
75 } // namespace ipmi_flash
76