| Patrick Venture | c0f499b | 2018-09-14 17:57:42 -0700 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
| Patrick Venture | aceb4ba | 2018-09-27 14:50:37 -0700 | [diff] [blame] | 3 | #include <blobs-ipmid/blobs.hpp> | 
| Patrick Venture | c0f499b | 2018-09-14 17:57:42 -0700 | [diff] [blame] | 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) : | 
| Patrick Venture | e01c0af | 2018-09-27 14:56:42 -0700 | [diff] [blame] | 17 | sessionId(id), flags(flags), | 
|  | 18 | state(StateFlags::open_read | StateFlags::open_write), length(0) | 
| Patrick Venture | c0f499b | 2018-09-14 17:57:42 -0700 | [diff] [blame] | 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 |  | 
| Patrick Venture | e01c0af | 2018-09-27 14:56:42 -0700 | [diff] [blame] | 28 | /* The current state. */ | 
|  | 29 | uint16_t state; | 
|  | 30 |  | 
| Patrick Venture | c0f499b | 2018-09-14 17:57:42 -0700 | [diff] [blame] | 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 commit(uint16_t session, const std::vector<uint8_t>& data) override; | 
|  | 62 | bool close(uint16_t session) override; | 
|  | 63 | bool stat(uint16_t session, struct BlobMeta* meta) override; | 
|  | 64 | bool expire(uint16_t session) override; | 
|  | 65 |  | 
|  | 66 | constexpr static char supportedPath[] = "/dev/fake/command"; | 
|  | 67 |  | 
|  | 68 | private: | 
|  | 69 | ExampleBlob* getSession(uint16_t id); | 
|  | 70 |  | 
|  | 71 | std::unordered_map<uint16_t, ExampleBlob> sessions; | 
|  | 72 | }; | 
|  | 73 |  | 
|  | 74 | } // namespace blobs |