Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 7 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 8 | { |
| 9 | |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame^] | 10 | enum 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 Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 25 | struct StatResponse |
| 26 | { |
| 27 | std::uint16_t blob_state; |
| 28 | std::uint32_t size; |
| 29 | std::vector<std::uint8_t> metadata; |
Patrick Venture | 99400c8 | 2019-05-15 15:26:48 -0700 | [diff] [blame] | 30 | |
| 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 Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | class BlobInterface |
| 39 | { |
| 40 | public: |
| 41 | virtual ~BlobInterface() = default; |
| 42 | |
| 43 | /** |
Patrick Venture | 8865e40 | 2019-05-14 13:29:10 -0700 | [diff] [blame] | 44 | * 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 Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 54 | * 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 Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 91 | * 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 Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 99 | * 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 | /** |
| 117 | * Read bytes from a blob. |
| 118 | * |
| 119 | * @param[in] session - the session id. |
| 120 | * @param[in] offset - the offset to which to write the bytes. |
| 121 | * @param[in] length - the number of bytes to read. |
| 122 | * @return the bytes read |
| 123 | * @throws BlobException on failure. |
| 124 | */ |
| 125 | virtual std::vector<std::uint8_t> readBytes(std::uint16_t session, |
| 126 | std::uint32_t offset, |
| 127 | std::uint32_t length) = 0; |
| 128 | }; |
| 129 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 130 | } // namespace ipmiblob |