Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "blob_interface.hpp" |
| 4 | #include "ipmi_interface.hpp" |
| 5 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 6 | #include <memory> |
| 7 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 8 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 9 | { |
| 10 | |
| 11 | class BlobHandler : public BlobInterface |
| 12 | { |
| 13 | public: |
Patrick Venture | 22fcc84 | 2019-05-13 09:06:24 -0700 | [diff] [blame] | 14 | /** |
| 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 Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 23 | 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 Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 31 | |
| 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 Venture | 8865e40 | 2019-05-14 13:29:10 -0700 | [diff] [blame] | 50 | void commit(std::uint16_t session, |
Patrick Venture | 8752cdf | 2019-05-15 12:37:42 -0700 | [diff] [blame] | 51 | const std::vector<std::uint8_t>& bytes = {}) override; |
Patrick Venture | 8865e40 | 2019-05-14 13:29:10 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * @throws BlobException. |
| 55 | */ |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 56 | 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 Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 75 | StatResponse getStat(std::uint16_t session) override; |
| 76 | |
| 77 | /** |
| 78 | * @throws BlobException. |
| 79 | */ |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 80 | 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 Venture | 17186ae | 2019-05-06 10:30:55 -0700 | [diff] [blame] | 119 | /** |
| 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 Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 130 | std::unique_ptr<IpmiInterface> ipmi; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 133 | } // namespace ipmiblob |