blob: c527fbad8a6bbeae68367fb5e569f1883d868f9d [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
Patrick Venture1470bec2019-03-06 07:33:12 -08007namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08008{
9
Patrick Venture44474642019-05-20 19:11:04 -070010enum class BlobOEMCommands : std::uint8_t
11{
12 bmcBlobGetCount = 0,
13 bmcBlobEnumerate = 1,
14 bmcBlobOpen = 2,
15 bmcBlobRead = 3,
16 bmcBlobWrite = 4,
17 bmcBlobCommit = 5,
18 bmcBlobClose = 6,
19 bmcBlobDelete = 7,
20 bmcBlobStat = 8,
21 bmcBlobSessionStat = 9,
22 bmcBlobWriteMeta = 10,
23};
24
Vivekanand Veeracholan2ca843c2021-08-26 12:29:59 -070025enum StateFlags
26{
27 open_read = (1 << 0),
28 open_write = (1 << 1),
29 committing = (1 << 2),
30 committed = (1 << 3),
31 commit_error = (1 << 4),
32};
33
Patrick Venture123b5c02019-03-05 14:01:00 -080034struct StatResponse
35{
36 std::uint16_t blob_state;
37 std::uint32_t size;
38 std::vector<std::uint8_t> metadata;
Patrick Venture99400c82019-05-15 15:26:48 -070039
40 bool operator==(const StatResponse& rhs) const
41 {
42 return (this->blob_state == rhs.blob_state && this->size == rhs.size &&
43 this->metadata == rhs.metadata);
44 }
Patrick Venture123b5c02019-03-05 14:01:00 -080045};
46
47class BlobInterface
48{
49 public:
50 virtual ~BlobInterface() = default;
51
52 /**
Patrick Venture8865e402019-05-14 13:29:10 -070053 * Call commit on a blob. The behavior here is up to the blob itself.
54 *
55 * @param[in] session - the session id.
56 * @param[in] bytes - the bytes to send.
57 * @throws BlobException on failure.
58 */
59 virtual void commit(std::uint16_t session,
60 const std::vector<std::uint8_t>& bytes) = 0;
61
62 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080063 * Write metadata to a blob.
64 *
65 * @param[in] session - the session id.
66 * @param[in] offset - the offset for the metadata to write.
67 * @param[in] bytes - the bytes to send.
68 * @throws BlobException on failure.
69 */
70 virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
71 const std::vector<std::uint8_t>& bytes) = 0;
72
73 /**
74 * Write bytes to a blob.
75 *
76 * @param[in] session - the session id.
77 * @param[in] offset - the offset to which to write the bytes.
78 * @param[in] bytes - the bytes to send.
79 * @throws BlobException on failure.
80 */
81 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
82 const std::vector<std::uint8_t>& bytes) = 0;
83
84 /**
85 * Get a list of the blob_ids provided by the BMC.
86 *
87 * @return list of strings, each representing a blob_id returned.
88 */
89 virtual std::vector<std::string> getBlobList() = 0;
90
91 /**
92 * Get the stat() on the blob_id.
93 *
94 * @param[in] id - the blob_id.
95 * @return metadata structure.
96 */
97 virtual StatResponse getStat(const std::string& id) = 0;
98
99 /**
Patrick Venture16a99a62019-05-03 17:21:30 -0700100 * Get the stat() on the blob session.
101 *
102 * @param[in] session - the blob session
103 * @return metadata structure
104 */
105 virtual StatResponse getStat(std::uint16_t session) = 0;
106
107 /**
Patrick Venture123b5c02019-03-05 14:01:00 -0800108 * Attempt to open the file using the specific data interface flag.
109 *
110 * @param[in] blob - the blob_id to open.
111 * @param[in] handlerFlags - the data interface flag, if relevant.
112 * @return the session id on success.
113 * @throws BlobException on failure.
114 */
115 virtual std::uint16_t openBlob(const std::string& id,
116 std::uint16_t handlerFlags) = 0;
117
118 /**
119 * Attempt to close the open session.
120 *
121 * @param[in] session - the session to close.
122 */
123 virtual void closeBlob(std::uint16_t session) = 0;
124
125 /**
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700126 * Attempt to delete a blobId.
127 *
128 * @param[in] path - the blobId path.
129 */
William A. Kennington IIId46530f2021-11-06 17:12:07 -0700130 virtual bool deleteBlob(const std::string& id) = 0;
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700131
132 /**
Patrick Venture123b5c02019-03-05 14:01:00 -0800133 * Read bytes from a blob.
134 *
135 * @param[in] session - the session id.
136 * @param[in] offset - the offset to which to write the bytes.
137 * @param[in] length - the number of bytes to read.
138 * @return the bytes read
139 * @throws BlobException on failure.
140 */
141 virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
142 std::uint32_t offset,
143 std::uint32_t length) = 0;
144};
145
Patrick Venture1470bec2019-03-06 07:33:12 -0800146} // namespace ipmiblob