blob: dbeac2130291ccf7a42546c18733eeb0eab8511f [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#pragma once
2
Patrick Venturedc82ab12019-01-10 10:15:50 -08003#include <memory>
Patrick Ventureef3aead2018-09-12 08:53:29 -07004#include <string>
5#include <vector>
6
7namespace blobs
8{
9
Patrick Venture4beac9a2019-02-11 08:21:10 -080010enum BlobOEMCommands
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
Patrick Ventureef3aead2018-09-12 08:53:29 -070025enum OpenFlags
26{
27 read = (1 << 0),
28 write = (1 << 1),
29 /* bits 3-7 reserved. */
30 /* bits 8-15 given blob-specific definitions */
31};
32
33enum StateFlags
34{
35 open_read = (1 << 0),
36 open_write = (1 << 1),
37 committing = (1 << 2),
38 committed = (1 << 3),
39 commit_error = (1 << 4),
40};
41
42struct BlobMeta
43{
44 uint16_t blobState;
45 uint32_t size;
46 std::vector<uint8_t> metadata;
Patrick Venture9260be32019-05-17 19:14:19 -070047
48 bool operator==(const BlobMeta& rhs) const
49 {
50 return (this->blobState == rhs.blobState && this->size == rhs.size &&
51 this->metadata == rhs.metadata);
52 }
Patrick Ventureef3aead2018-09-12 08:53:29 -070053};
54
55/*
56 * All blob specific objects implement this interface.
57 */
58class GenericBlobInterface
59{
60 public:
61 virtual ~GenericBlobInterface() = default;
62
63 /**
64 * Checks if the handler will manage this file path.
65 *
66 * @param[in] blobId.
67 * @return bool whether it will manage the file path.
68 */
69 virtual bool canHandleBlob(const std::string& path) = 0;
70
71 /**
72 * Return the name(s) of the blob(s). Used during GetCount.
73 *
74 * @return List of blobIds this handler manages.
75 */
76 virtual std::vector<std::string> getBlobIds() = 0;
77
78 /**
79 * Attempt to delete the blob specified by the path.
80 *
81 * @param[in] path - the blobId to try and delete.
82 * @return bool - whether it was able to delete the blob.
83 */
84 virtual bool deleteBlob(const std::string& path) = 0;
85
86 /**
87 * Return metadata about the blob.
88 *
89 * @param[in] path - the blobId for metadata.
90 * @param[in,out] meta - a pointer to a blobmeta.
91 * @return bool - true if it was successful.
92 */
93 virtual bool stat(const std::string& path, struct BlobMeta* meta) = 0;
94
95 /* The methods below are per session. */
96
97 /**
98 * Attempt to open a session from this path.
99 *
100 * @param[in] session - the session id.
101 * @param[in] flags - the open flags.
102 * @param[in] path - the blob path.
103 * @return bool - was able to open the session.
104 */
105 virtual bool open(uint16_t session, uint16_t flags,
106 const std::string& path) = 0;
107
108 /**
109 * Attempt to read from a blob.
110 *
111 * @param[in] session - the session id.
112 * @param[in] offset - offset into the blob.
113 * @param[in] requestedSize - number of bytes to read.
114 * @return Bytes read back (0 length on error).
115 */
116 virtual std::vector<uint8_t> read(uint16_t session, uint32_t offset,
117 uint32_t requestedSize) = 0;
118
119 /**
120 * Attempt to write to a blob.
121 *
122 * @param[in] session - the session id.
123 * @param[in] offset - offset into the blob.
124 * @param[in] data - the data to write.
125 * @return bool - was able to write.
126 */
127 virtual bool write(uint16_t session, uint32_t offset,
128 const std::vector<uint8_t>& data) = 0;
129
130 /**
Patrick Venture5c4b17b2018-10-04 10:32:22 -0700131 * Attempt to write metadata to a blob.
132 *
133 * @param[in] session - the session id.
134 * @param[in] offset - offset into the blob.
135 * @param[in] data - the data to write.
136 * @return bool - was able to write.
137 */
138 virtual bool writeMeta(uint16_t session, uint32_t offset,
139 const std::vector<uint8_t>& data) = 0;
140
141 /**
Patrick Ventureef3aead2018-09-12 08:53:29 -0700142 * Attempt to commit to a blob.
143 *
144 * @param[in] session - the session id.
145 * @param[in] data - optional commit data.
146 * @return bool - was able to start commit.
147 */
148 virtual bool commit(uint16_t session, const std::vector<uint8_t>& data) = 0;
149
150 /**
151 * Attempt to close your session.
152 *
153 * @param[in] session - the session id.
154 * @return bool - was able to close session.
155 */
156 virtual bool close(uint16_t session) = 0;
157
158 /**
159 * Attempt to return metadata for the session's view of the blob.
160 *
161 * @param[in] session - the session id.
162 * @param[in,out] meta - pointer to update with the BlobMeta.
163 * @return bool - wether it was successful.
164 */
165 virtual bool stat(uint16_t session, struct BlobMeta* meta) = 0;
166
167 /**
168 * Attempt to expire a session. This is called when a session has been
169 * inactive for at least 10 minutes.
170 *
171 * @param[in] session - the session id.
172 * @return bool - whether the session was able to be closed.
173 */
174 virtual bool expire(uint16_t session) = 0;
175};
176} // namespace blobs
Patrick Venturedc82ab12019-01-10 10:15:50 -0800177
178#ifdef __cplusplus
179extern "C" {
180#endif
181
182/**
183 * All Blob handlers need to implement this method. It is called after loading
184 * the library to then get a handle to the blob handler.
185 *
186 * @return a unique pointer to your blob handler instance.
187 */
188std::unique_ptr<blobs::GenericBlobInterface> createHandler();
189
190#ifdef __cplusplus
191}
192#endif