blob: 26ca8374c36562895b5366d187aae214190238ad [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
10struct StatResponse
11{
12 std::uint16_t blob_state;
13 std::uint32_t size;
14 std::vector<std::uint8_t> metadata;
Patrick Venture99400c82019-05-15 15:26:48 -070015
16 bool operator==(const StatResponse& rhs) const
17 {
18 return (this->blob_state == rhs.blob_state && this->size == rhs.size &&
19 this->metadata == rhs.metadata);
20 }
Patrick Venture123b5c02019-03-05 14:01:00 -080021};
22
23class BlobInterface
24{
25 public:
26 virtual ~BlobInterface() = default;
27
28 /**
Patrick Venture8865e402019-05-14 13:29:10 -070029 * Call commit on a blob. The behavior here is up to the blob itself.
30 *
31 * @param[in] session - the session id.
32 * @param[in] bytes - the bytes to send.
33 * @throws BlobException on failure.
34 */
35 virtual void commit(std::uint16_t session,
36 const std::vector<std::uint8_t>& bytes) = 0;
37
38 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080039 * Write metadata to a blob.
40 *
41 * @param[in] session - the session id.
42 * @param[in] offset - the offset for the metadata to write.
43 * @param[in] bytes - the bytes to send.
44 * @throws BlobException on failure.
45 */
46 virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
47 const std::vector<std::uint8_t>& bytes) = 0;
48
49 /**
50 * Write bytes to a blob.
51 *
52 * @param[in] session - the session id.
53 * @param[in] offset - the offset to which to write the bytes.
54 * @param[in] bytes - the bytes to send.
55 * @throws BlobException on failure.
56 */
57 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
58 const std::vector<std::uint8_t>& bytes) = 0;
59
60 /**
61 * Get a list of the blob_ids provided by the BMC.
62 *
63 * @return list of strings, each representing a blob_id returned.
64 */
65 virtual std::vector<std::string> getBlobList() = 0;
66
67 /**
68 * Get the stat() on the blob_id.
69 *
70 * @param[in] id - the blob_id.
71 * @return metadata structure.
72 */
73 virtual StatResponse getStat(const std::string& id) = 0;
74
75 /**
Patrick Venture16a99a62019-05-03 17:21:30 -070076 * Get the stat() on the blob session.
77 *
78 * @param[in] session - the blob session
79 * @return metadata structure
80 */
81 virtual StatResponse getStat(std::uint16_t session) = 0;
82
83 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080084 * Attempt to open the file using the specific data interface flag.
85 *
86 * @param[in] blob - the blob_id to open.
87 * @param[in] handlerFlags - the data interface flag, if relevant.
88 * @return the session id on success.
89 * @throws BlobException on failure.
90 */
91 virtual std::uint16_t openBlob(const std::string& id,
92 std::uint16_t handlerFlags) = 0;
93
94 /**
95 * Attempt to close the open session.
96 *
97 * @param[in] session - the session to close.
98 */
99 virtual void closeBlob(std::uint16_t session) = 0;
100
101 /**
102 * Read bytes from a blob.
103 *
104 * @param[in] session - the session id.
105 * @param[in] offset - the offset to which to write the bytes.
106 * @param[in] length - the number of bytes to read.
107 * @return the bytes read
108 * @throws BlobException on failure.
109 */
110 virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
111 std::uint32_t offset,
112 std::uint32_t length) = 0;
113};
114
Patrick Venture1470bec2019-03-06 07:33:12 -0800115} // namespace ipmiblob