diff options
author | Patrick Venture <venture@google.com> | 2018-09-14 17:57:42 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-09-20 18:32:40 -0700 |
commit | c0f499b594b158bdb6c61764c27729fef6837cd3 (patch) | |
tree | 5fc12741ebe4ee272383fc6d71529ea237053729 /example/example.hpp | |
parent | f222cf51d4801f3bda3ba1e2e57a898d3da11bb1 (diff) | |
download | phosphor-ipmi-blobs-c0f499b594b158bdb6c61764c27729fef6837cd3.tar.gz phosphor-ipmi-blobs-c0f499b594b158bdb6c61764c27729fef6837cd3.zip |
add example handler
This adds an example handler to demonstrate how one can add a specific
type of BLOB handler.
Change-Id: Ib5421f1b945b45998b40d3939a4dab9cdf39aaa9
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'example/example.hpp')
-rw-r--r-- | example/example.hpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/example/example.hpp b/example/example.hpp new file mode 100644 index 0000000..0ea9572 --- /dev/null +++ b/example/example.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include "blobs.hpp" + +#include <string> +#include <unordered_map> +#include <vector> + +namespace blobs +{ + +constexpr int kBufferSize = 1024; + +struct ExampleBlob +{ + ExampleBlob() = default; + ExampleBlob(uint16_t id, uint16_t flags) : + sessionId(id), flags(flags), length(0) + { + } + + /* The blob handler session id. */ + uint16_t sessionId; + + /* The flags passed into open. */ + uint16_t flags; + + /* The buffer is a fixed size, but length represents the number of bytes + * expected to be used contiguously from offset 0. + */ + uint32_t length; + + /* The staging buffer. */ + uint8_t buffer[kBufferSize]; +}; + +class ExampleBlobHandler : public GenericBlobInterface +{ + public: + /* We want everything explicitly default. */ + ExampleBlobHandler() = default; + ~ExampleBlobHandler() = default; + ExampleBlobHandler(const ExampleBlobHandler&) = default; + ExampleBlobHandler& operator=(const ExampleBlobHandler&) = default; + ExampleBlobHandler(ExampleBlobHandler&&) = default; + ExampleBlobHandler& operator=(ExampleBlobHandler&&) = default; + + bool canHandleBlob(const std::string& path) override; + std::vector<std::string> getBlobIds() override; + bool deleteBlob(const std::string& path) override; + bool stat(const std::string& path, struct BlobMeta* meta) override; + bool open(uint16_t session, uint16_t flags, + const std::string& path) override; + std::vector<uint8_t> read(uint16_t session, uint32_t offset, + uint32_t requestedSize) override; + bool write(uint16_t session, uint32_t offset, + const std::vector<uint8_t>& data) override; + bool commit(uint16_t session, const std::vector<uint8_t>& data) override; + bool close(uint16_t session) override; + bool stat(uint16_t session, struct BlobMeta* meta) override; + bool expire(uint16_t session) override; + + constexpr static char supportedPath[] = "/dev/fake/command"; + + private: + ExampleBlob* getSession(uint16_t id); + + std::unordered_map<uint16_t, ExampleBlob> sessions; +}; + +} // namespace blobs |