Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 1 | #include "handler.hpp" |
| 2 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 3 | #include <algorithm> |
| 4 | |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 5 | namespace blobs |
| 6 | { |
| 7 | |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 8 | void BinaryStoreBlobHandler::addNewBinaryStore( |
| 9 | std::unique_ptr<binstore::BinaryStoreInterface> store) |
| 10 | { |
| 11 | // TODO: this is a very rough measure to test the mock interface for now. |
| 12 | stores_[store->getBaseBlobId()] = std::move(store); |
| 13 | } |
| 14 | |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 15 | bool BinaryStoreBlobHandler::canHandleBlob(const std::string& path) |
| 16 | { |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 17 | return std::any_of(stores_.begin(), stores_.end(), |
| 18 | [&](const auto& baseStorePair) { |
| 19 | return baseStorePair.second->canHandleBlob(path); |
| 20 | }); |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | std::vector<std::string> BinaryStoreBlobHandler::getBlobIds() |
| 24 | { |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 25 | std::vector<std::string> result; |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 26 | |
| 27 | for (const auto& baseStorePair : stores_) |
| 28 | { |
| 29 | const auto& ids = baseStorePair.second->getBlobIds(); |
| 30 | result.insert(result.end(), ids.begin(), ids.end()); |
| 31 | } |
| 32 | |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 33 | return result; |
| 34 | } |
| 35 | |
| 36 | bool BinaryStoreBlobHandler::deleteBlob(const std::string& path) |
| 37 | { |
| 38 | // TODO: implement |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | bool BinaryStoreBlobHandler::stat(const std::string& path, |
| 43 | struct BlobMeta* meta) |
| 44 | { |
| 45 | // TODO: implement |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | bool BinaryStoreBlobHandler::open(uint16_t session, uint16_t flags, |
| 50 | const std::string& path) |
| 51 | { |
Kun Yi | 68c8114 | 2018-12-18 11:17:14 -0800 | [diff] [blame^] | 52 | if (!canHandleBlob(path)) |
| 53 | { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | auto found = sessions_.find(session); |
| 58 | if (found != sessions_.end()) |
| 59 | { |
| 60 | /* This session is already active */ |
| 61 | return false; |
| 62 | } |
| 63 | |
Kun Yi | 91beea6 | 2018-11-26 15:23:14 -0800 | [diff] [blame] | 64 | // TODO: implement |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | std::vector<uint8_t> BinaryStoreBlobHandler::read(uint16_t session, |
| 69 | uint32_t offset, |
| 70 | uint32_t requestedSize) |
| 71 | { |
| 72 | // TODO: implement |
| 73 | std::vector<uint8_t> result; |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | bool BinaryStoreBlobHandler::write(uint16_t session, uint32_t offset, |
| 78 | const std::vector<uint8_t>& data) |
| 79 | { |
| 80 | // TODO: implement |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | bool BinaryStoreBlobHandler::writeMeta(uint16_t session, uint32_t offset, |
| 85 | const std::vector<uint8_t>& data) |
| 86 | { |
| 87 | /* Binary store handler doesn't support write meta */ |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | bool BinaryStoreBlobHandler::commit(uint16_t session, |
| 92 | const std::vector<uint8_t>& data) |
| 93 | { |
| 94 | // TODO: implement |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool BinaryStoreBlobHandler::close(uint16_t session) |
| 99 | { |
| 100 | // TODO: implement |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | bool BinaryStoreBlobHandler::stat(uint16_t session, struct BlobMeta* meta) |
| 105 | { |
| 106 | // TODO: implement |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | bool BinaryStoreBlobHandler::expire(uint16_t session) |
| 111 | { |
| 112 | /* Binary store handler doesn't support expire */ |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | } // namespace blobs |