blob: 4e6e6ea664f544a792338b8dfbb459dc2686eb46 [file] [log] [blame]
Kun Yi91beea62018-11-26 15:23:14 -08001#include "handler.hpp"
2
Kun Yi68c81142018-12-18 11:17:14 -08003#include <algorithm>
4
Kun Yi91beea62018-11-26 15:23:14 -08005namespace blobs
6{
7
Kun Yi68c81142018-12-18 11:17:14 -08008void 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 Yi91beea62018-11-26 15:23:14 -080015bool BinaryStoreBlobHandler::canHandleBlob(const std::string& path)
16{
Kun Yi68c81142018-12-18 11:17:14 -080017 return std::any_of(stores_.begin(), stores_.end(),
18 [&](const auto& baseStorePair) {
19 return baseStorePair.second->canHandleBlob(path);
20 });
Kun Yi91beea62018-11-26 15:23:14 -080021}
22
23std::vector<std::string> BinaryStoreBlobHandler::getBlobIds()
24{
Kun Yi91beea62018-11-26 15:23:14 -080025 std::vector<std::string> result;
Kun Yi68c81142018-12-18 11:17:14 -080026
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 Yi91beea62018-11-26 15:23:14 -080033 return result;
34}
35
36bool BinaryStoreBlobHandler::deleteBlob(const std::string& path)
37{
38 // TODO: implement
39 return false;
40}
41
42bool BinaryStoreBlobHandler::stat(const std::string& path,
43 struct BlobMeta* meta)
44{
45 // TODO: implement
46 return false;
47}
48
49bool BinaryStoreBlobHandler::open(uint16_t session, uint16_t flags,
50 const std::string& path)
51{
Kun Yi68c81142018-12-18 11:17:14 -080052 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 Yi91beea62018-11-26 15:23:14 -080064 // TODO: implement
65 return false;
66}
67
68std::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
77bool BinaryStoreBlobHandler::write(uint16_t session, uint32_t offset,
78 const std::vector<uint8_t>& data)
79{
80 // TODO: implement
81 return false;
82}
83
84bool 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
91bool BinaryStoreBlobHandler::commit(uint16_t session,
92 const std::vector<uint8_t>& data)
93{
94 // TODO: implement
95 return false;
96}
97
98bool BinaryStoreBlobHandler::close(uint16_t session)
99{
100 // TODO: implement
101 return false;
102}
103
104bool BinaryStoreBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
105{
106 // TODO: implement
107 return false;
108}
109
110bool BinaryStoreBlobHandler::expire(uint16_t session)
111{
112 /* Binary store handler doesn't support expire */
113 return false;
114}
115
116} // namespace blobs