blob: 61ded3659b0f26b990372ee837d1fd6f7a98185e [file] [log] [blame]
Kun Yi91beea62018-11-26 15:23:14 -08001#pragma once
2
Kun Yi68c81142018-12-18 11:17:14 -08003#include "binarystore.hpp"
4
Kun Yi91beea62018-11-26 15:23:14 -08005#include <blobs-ipmid/blobs.hpp>
6#include <cstdint>
Kun Yi68c81142018-12-18 11:17:14 -08007#include <map>
8#include <memory>
Kun Yi91beea62018-11-26 15:23:14 -08009#include <string>
Kun Yi68c81142018-12-18 11:17:14 -080010#include <unordered_map>
Kun Yi91beea62018-11-26 15:23:14 -080011#include <vector>
12
13using std::size_t;
14using std::uint16_t;
15using std::uint32_t;
16using std::uint64_t;
17using std::uint8_t;
18
19namespace blobs
20{
21
22class BinaryStoreBlobHandler : public GenericBlobInterface
23{
24 public:
25 BinaryStoreBlobHandler() = default;
26 ~BinaryStoreBlobHandler() = default;
27 BinaryStoreBlobHandler(const BinaryStoreBlobHandler&) = delete;
28 BinaryStoreBlobHandler& operator=(const BinaryStoreBlobHandler&) = delete;
29 BinaryStoreBlobHandler(BinaryStoreBlobHandler&&) = default;
30 BinaryStoreBlobHandler& operator=(BinaryStoreBlobHandler&&) = default;
31
32 bool canHandleBlob(const std::string& path) override;
33 std::vector<std::string> getBlobIds() override;
34 bool deleteBlob(const std::string& path) override;
35 bool stat(const std::string& path, struct BlobMeta* meta) override;
36 bool open(uint16_t session, uint16_t flags,
37 const std::string& path) override;
38 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
39 uint32_t requestedSize) override;
40 bool write(uint16_t session, uint32_t offset,
41 const std::vector<uint8_t>& data) override;
42 bool writeMeta(uint16_t session, uint32_t offset,
43 const std::vector<uint8_t>& data) override;
44 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
45 bool close(uint16_t session) override;
46 bool stat(uint16_t session, struct BlobMeta* meta) override;
47 bool expire(uint16_t session) override;
Kun Yi68c81142018-12-18 11:17:14 -080048
49 /**
50 * Registers a binarystore in the main handler. Once called, handler will
51 * take over the ownership of of enclosed binary store.
52 *
53 * @param store: pointer to a valid BinaryStore.
54 * TODO: a minimal amount of error checking would be better
55 */
56 void addNewBinaryStore(
57 std::unique_ptr<binstore::BinaryStoreInterface> store);
58
59 private:
60 /* map of baseId: binaryStore, which has a 1:1 relationship. */
61 std::map<std::string, std::unique_ptr<binstore::BinaryStoreInterface>>
62 stores_;
63
64 /* map of sessionId: open binaryStore base, which has a 1:1 relationship. */
65 std::unordered_map<uint16_t, std::string> sessions_;
Kun Yi91beea62018-11-26 15:23:14 -080066};
67
68} // namespace blobs