Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 3 | #include "binarystore.hpp" |
| 4 | |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 5 | #include <blobs-ipmid/blobs.hpp> |
| 6 | #include <cstdint> |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 7 | #include <map> |
| 8 | #include <memory> |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 9 | #include <string> |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 10 | #include <unordered_map> |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
| 13 | using std::size_t; |
| 14 | using std::uint16_t; |
| 15 | using std::uint32_t; |
| 16 | using std::uint64_t; |
| 17 | using std::uint8_t; |
| 18 | |
| 19 | namespace blobs |
| 20 | { |
| 21 | |
| 22 | class 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 Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 48 | |
| 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 Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace blobs |