1 #pragma once 2 3 #include <blobs-ipmid/blobs.hpp> 4 #include <string> 5 #include <unordered_map> 6 #include <vector> 7 8 namespace blobs 9 { 10 11 constexpr int kBufferSize = 1024; 12 13 struct ExampleBlob 14 { 15 ExampleBlob() = default; 16 ExampleBlob(uint16_t id, uint16_t flags) : 17 sessionId(id), flags(flags), 18 state(StateFlags::open_read | StateFlags::open_write), length(0) 19 { 20 } 21 22 /* The blob handler session id. */ 23 uint16_t sessionId; 24 25 /* The flags passed into open. */ 26 uint16_t flags; 27 28 /* The current state. */ 29 uint16_t state; 30 31 /* The buffer is a fixed size, but length represents the number of bytes 32 * expected to be used contiguously from offset 0. 33 */ 34 uint32_t length; 35 36 /* The staging buffer. */ 37 uint8_t buffer[kBufferSize]; 38 }; 39 40 class ExampleBlobHandler : public GenericBlobInterface 41 { 42 public: 43 /* We want everything explicitly default. */ 44 ExampleBlobHandler() = default; 45 ~ExampleBlobHandler() = default; 46 ExampleBlobHandler(const ExampleBlobHandler&) = default; 47 ExampleBlobHandler& operator=(const ExampleBlobHandler&) = default; 48 ExampleBlobHandler(ExampleBlobHandler&&) = default; 49 ExampleBlobHandler& operator=(ExampleBlobHandler&&) = default; 50 51 bool canHandleBlob(const std::string& path) override; 52 std::vector<std::string> getBlobIds() override; 53 bool deleteBlob(const std::string& path) override; 54 bool stat(const std::string& path, struct BlobMeta* meta) override; 55 bool open(uint16_t session, uint16_t flags, 56 const std::string& path) override; 57 std::vector<uint8_t> read(uint16_t session, uint32_t offset, 58 uint32_t requestedSize) override; 59 bool write(uint16_t session, uint32_t offset, 60 const std::vector<uint8_t>& data) override; 61 bool writeMeta(uint16_t session, uint32_t offset, 62 const std::vector<uint8_t>& data) override; 63 bool commit(uint16_t session, const std::vector<uint8_t>& data) override; 64 bool close(uint16_t session) override; 65 bool stat(uint16_t session, struct BlobMeta* meta) override; 66 bool expire(uint16_t session) override; 67 68 constexpr static char supportedPath[] = "/dev/fake/command"; 69 70 private: 71 ExampleBlob* getSession(uint16_t id); 72 73 std::unordered_map<uint16_t, ExampleBlob> sessions; 74 }; 75 76 } // namespace blobs 77