2
#include <unity/storage/provider/ProviderBase.h>
3
#include <unity/storage/provider/Server.h>
7
using namespace unity::storage::provider;
9
class MyProvider : public ProviderBase
14
boost::future<std::vector<Item>> roots() override;
15
boost::future<std::tuple<std::vector<Item>,std::string>> list(
16
std::string const& item_id, std::string const& page_token) override;
17
boost::future<std::vector<Item>> lookup(
18
std::string const& parent_id, std::string const& name) override;
19
boost::future<Item> metadata(std::string const& item_id) override;
22
MyProvider::MyProvider()
26
boost::future<std::vector<Item>> MyProvider::roots()
28
std::vector<Item> roots = {
29
{"root_id", "", "Root", "etag", ItemType::root, {}},
31
return boost::make_ready_future<std::vector<Item>>(roots);
34
boost::future<std::tuple<std::vector<Item>,std::string>> MyProvider::list(
35
std::string const& item_id, std::string const& page_token)
37
if (item_id != "root_id")
39
return boost::make_exceptional_future<std::tuple<std::vector<Item>,std::string>>(std::runtime_error("unknown folder"));
43
return boost::make_exceptional_future<std::tuple<std::vector<Item>,std::string>>(std::runtime_error("unknown page token"));
45
std::vector<Item> children = {
46
{"child_id", "root_id", "Child", "etag", ItemType::file, {}}
48
boost::promise<std::tuple<std::vector<Item>,std::string>> p;
49
p.set_value(std::make_tuple(children, std::string()));
50
return p.get_future();
53
boost::future<std::vector<Item>> MyProvider::lookup(
54
std::string const& parent_id, std::string const& name)
56
if (parent_id != "root_id" || name != "Child")
58
return boost::make_exceptional_future<std::vector<Item>>(std::runtime_error("file not found"));
60
std::vector<Item> children = {
61
{"child_id", "root_id", "Child", "etag", ItemType::file, {}}
63
return boost::make_ready_future<std::vector<Item>>(children);
66
boost::future<Item> MyProvider::metadata(std::string const& item_id)
68
if (item_id == "root_id")
70
Item metadata{"root_id", "", "Root", "etag", ItemType::root, {}};
71
return boost::make_ready_future<Item>(metadata);
73
else if (item_id == "child_id")
75
Item metadata{"child_id", "root_id", "Child", "etag", ItemType::file, {}};
76
return boost::make_ready_future<Item>(metadata);
78
return boost::make_exceptional_future<Item>(std::runtime_error("no such file"));
81
int main(int argc, char **argv)
83
Server<MyProvider> server;
84
server.init(argc, argv);