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