blob: 68708d896b66ce64317bdf76fe14ceee90b6c2fa [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include "blob_interface.hpp"
4#include "ipmi_interface.hpp"
5
Patrick Venture786a5412019-05-13 07:40:22 -07006#include <memory>
7
Patrick Venture1470bec2019-03-06 07:33:12 -08008namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -08009{
10
11class BlobHandler : public BlobInterface
12{
13 public:
Patrick Venture22fcc842019-05-13 09:06:24 -070014 /**
15 * Create a BlobInterface pointer for use given an ipmi handler.
16 *
17 * @note This is a convenience method.
18 * @return a BlobHandler wrapped as a BlobInterface pointer.
19 */
20 static std::unique_ptr<BlobInterface>
21 CreateBlobHandler(std::unique_ptr<IpmiInterface> ipmi);
22
Patrick Venture786a5412019-05-13 07:40:22 -070023 explicit BlobHandler(std::unique_ptr<IpmiInterface> ipmi) :
24 ipmi(std::move(ipmi)){};
25
26 ~BlobHandler() = default;
27 BlobHandler(const BlobHandler&) = delete;
28 BlobHandler& operator=(const BlobHandler&) = delete;
29 BlobHandler(BlobHandler&&) = default;
30 BlobHandler& operator=(BlobHandler&&) = default;
Patrick Venture123b5c02019-03-05 14:01:00 -080031
32 /**
33 * Retrieve the blob count.
34 *
35 * @return the number of blob_ids found (0 on failure).
36 */
37 int getBlobCount();
38
39 /**
40 * Given an index into the list of blobs, return the name.
41 *
42 * @param[in] index - the index into the list of blob ids.
43 * @return the name as a string or empty on failure.
44 */
45 std::string enumerateBlob(std::uint32_t index);
46
47 /**
48 * @throws BlobException.
49 */
Patrick Venture8865e402019-05-14 13:29:10 -070050 void commit(std::uint16_t session,
Patrick Venture8752cdf2019-05-15 12:37:42 -070051 const std::vector<std::uint8_t>& bytes = {}) override;
Patrick Venture8865e402019-05-14 13:29:10 -070052
53 /**
54 * @throws BlobException.
55 */
Patrick Venture123b5c02019-03-05 14:01:00 -080056 void writeMeta(std::uint16_t session, std::uint32_t offset,
57 const std::vector<std::uint8_t>& bytes) override;
58
59 /**
60 * @throw BlobException.
61 */
62 void writeBytes(std::uint16_t session, std::uint32_t offset,
63 const std::vector<std::uint8_t>& bytes) override;
64
65 std::vector<std::string> getBlobList() override;
66
67 /**
68 * @throws BlobException.
69 */
70 StatResponse getStat(const std::string& id) override;
71
72 /**
73 * @throws BlobException.
74 */
Patrick Venture16a99a62019-05-03 17:21:30 -070075 StatResponse getStat(std::uint16_t session) override;
76
77 /**
78 * @throws BlobException.
79 */
Patrick Venture123b5c02019-03-05 14:01:00 -080080 std::uint16_t openBlob(const std::string& id,
81 std::uint16_t handlerFlags) override;
82
83 void closeBlob(std::uint16_t session) override;
84
85 /**
86 * @throws BlobException.
87 */
88 std::vector<std::uint8_t> readBytes(std::uint16_t session,
89 std::uint32_t offset,
90 std::uint32_t length) override;
91
92 private:
93 /**
94 * Send the contents of the payload to IPMI, this method handles wrapping
95 * with the OEN, subcommand and CRC.
96 *
97 * @param[in] command - the blob command.
98 * @param[in] payload - the payload bytes.
99 * @return the bytes returned from the ipmi interface.
100 * @throws BlobException.
101 */
102 std::vector<std::uint8_t>
103 sendIpmiPayload(BlobOEMCommands command,
104 const std::vector<std::uint8_t>& payload);
105
106 /**
107 * Generic blob byte writer.
108 *
109 * @param[in] command - the command associated with this write.
110 * @param[in] session - the session id.
111 * @param[in] offset - the offset for the metadata to write.
112 * @param[in] bytes - the bytes to send.
113 * @throws BlobException on failure.
114 */
115 void writeGeneric(BlobOEMCommands command, std::uint16_t session,
116 std::uint32_t offset,
117 const std::vector<std::uint8_t>& bytes);
118
Patrick Venture17186ae2019-05-06 10:30:55 -0700119 /**
120 * Generic stat reader.
121 *
122 * @param[in] command - the command associated with this write.
123 * @param[in] request - the bytes of the request
124 * @return the metadata StatResponse
125 * @throws BlobException on failure.
126 */
127 StatResponse statGeneric(BlobOEMCommands command,
128 const std::vector<std::uint8_t>& request);
129
Patrick Venture786a5412019-05-13 07:40:22 -0700130 std::unique_ptr<IpmiInterface> ipmi;
Patrick Venture123b5c02019-03-05 14:01:00 -0800131};
132
Patrick Venture1470bec2019-03-06 07:33:12 -0800133} // namespace ipmiblob