blob: ece5c3492e2ba322c1b0636b1340b6df190d1642 [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;
15};
16
17class BlobInterface
18{
19 public:
20 virtual ~BlobInterface() = default;
21
22 /**
23 * Write metadata to a blob.
24 *
25 * @param[in] session - the session id.
26 * @param[in] offset - the offset for the metadata to write.
27 * @param[in] bytes - the bytes to send.
28 * @throws BlobException on failure.
29 */
30 virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
31 const std::vector<std::uint8_t>& bytes) = 0;
32
33 /**
34 * Write bytes to a blob.
35 *
36 * @param[in] session - the session id.
37 * @param[in] offset - the offset to which to write the bytes.
38 * @param[in] bytes - the bytes to send.
39 * @throws BlobException on failure.
40 */
41 virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
42 const std::vector<std::uint8_t>& bytes) = 0;
43
44 /**
45 * Get a list of the blob_ids provided by the BMC.
46 *
47 * @return list of strings, each representing a blob_id returned.
48 */
49 virtual std::vector<std::string> getBlobList() = 0;
50
51 /**
52 * Get the stat() on the blob_id.
53 *
54 * @param[in] id - the blob_id.
55 * @return metadata structure.
56 */
57 virtual StatResponse getStat(const std::string& id) = 0;
58
59 /**
Patrick Venture16a99a62019-05-03 17:21:30 -070060 * Get the stat() on the blob session.
61 *
62 * @param[in] session - the blob session
63 * @return metadata structure
64 */
65 virtual StatResponse getStat(std::uint16_t session) = 0;
66
67 /**
Patrick Venture123b5c02019-03-05 14:01:00 -080068 * Attempt to open the file using the specific data interface flag.
69 *
70 * @param[in] blob - the blob_id to open.
71 * @param[in] handlerFlags - the data interface flag, if relevant.
72 * @return the session id on success.
73 * @throws BlobException on failure.
74 */
75 virtual std::uint16_t openBlob(const std::string& id,
76 std::uint16_t handlerFlags) = 0;
77
78 /**
79 * Attempt to close the open session.
80 *
81 * @param[in] session - the session to close.
82 */
83 virtual void closeBlob(std::uint16_t session) = 0;
84
85 /**
86 * Read bytes from a blob.
87 *
88 * @param[in] session - the session id.
89 * @param[in] offset - the offset to which to write the bytes.
90 * @param[in] length - the number of bytes to read.
91 * @return the bytes read
92 * @throws BlobException on failure.
93 */
94 virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
95 std::uint32_t offset,
96 std::uint32_t length) = 0;
97};
98
Patrick Venture1470bec2019-03-06 07:33:12 -080099} // namespace ipmiblob