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