blob: ca90cdf31df25936a82811d32ed7957f58d8e6ef [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
Patrick Venture123b5c02019-03-05 14:01:00 -080025struct StatResponse
26{
27 std::uint16_t blob_state;
28 std::uint32_t size;
29 std::vector<std::uint8_t> metadata;
Patrick Venture99400c82019-05-15 15:26:48 -070030
31 bool operator==(const StatResponse& rhs) const
32 {
33 return (this->blob_state == rhs.blob_state && this->size == rhs.size &&
34 this->metadata == rhs.metadata);
35 }
Patrick Venture123b5c02019-03-05 14:01:00 -080036};
37
38class BlobInterface
39{
40 public:
41 virtual ~BlobInterface() = default;
42
43 /**
Patrick Venture8865e402019-05-14 13:29:10 -070044 * Call commit on a blob. The behavior here is up to the blob itself.
45 *
46 * @param[in] session - the session id.
47 * @param[in] bytes - the bytes to send.
48 * @throws BlobException on failure.
49 */
50 virtual void commit(std::uint16_t session,
51 const std::vector<std::uint8_t>& bytes) = 0;
52
53 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080054 * Write metadata to a blob.
55 *
56 * @param[in] session - the session id.
57 * @param[in] offset - the offset for the metadata to write.
58 * @param[in] bytes - the bytes to send.
59 * @throws BlobException on failure.
60 */
61 virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
62 const std::vector<std::uint8_t>& bytes) = 0;
63
64 /**
65 * Write bytes to a blob.
66 *
67 * @param[in] session - the session id.
68 * @param[in] offset - the offset to which to write the bytes.
69 * @param[in] bytes - the bytes to send.
70 * @throws BlobException on failure.
71 */
72 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
73 const std::vector<std::uint8_t>& bytes) = 0;
74
75 /**
76 * Get a list of the blob_ids provided by the BMC.
77 *
78 * @return list of strings, each representing a blob_id returned.
79 */
80 virtual std::vector<std::string> getBlobList() = 0;
81
82 /**
83 * Get the stat() on the blob_id.
84 *
85 * @param[in] id - the blob_id.
86 * @return metadata structure.
87 */
88 virtual StatResponse getStat(const std::string& id) = 0;
89
90 /**
Patrick Venture16a99a62019-05-03 17:21:30 -070091 * Get the stat() on the blob session.
92 *
93 * @param[in] session - the blob session
94 * @return metadata structure
95 */
96 virtual StatResponse getStat(std::uint16_t session) = 0;
97
98 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080099 * Attempt to open the file using the specific data interface flag.
100 *
101 * @param[in] blob - the blob_id to open.
102 * @param[in] handlerFlags - the data interface flag, if relevant.
103 * @return the session id on success.
104 * @throws BlobException on failure.
105 */
106 virtual std::uint16_t openBlob(const std::string& id,
107 std::uint16_t handlerFlags) = 0;
108
109 /**
110 * Attempt to close the open session.
111 *
112 * @param[in] session - the session to close.
113 */
114 virtual void closeBlob(std::uint16_t session) = 0;
115
116 /**
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700117 * Attempt to delete a blobId.
118 *
119 * @param[in] path - the blobId path.
120 */
121 virtual void deleteBlob(const std::string& id) = 0;
122
123 /**
Patrick Venture123b5c02019-03-05 14:01:00 -0800124 * Read bytes from a blob.
125 *
126 * @param[in] session - the session id.
127 * @param[in] offset - the offset to which to write the bytes.
128 * @param[in] length - the number of bytes to read.
129 * @return the bytes read
130 * @throws BlobException on failure.
131 */
132 virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
133 std::uint32_t offset,
134 std::uint32_t length) = 0;
135};
136
Patrick Venture1470bec2019-03-06 07:33:12 -0800137} // namespace ipmiblob