blob: d5cb653b3750dd4cfd48dc218a2754b8e3d310f2 [file] [log] [blame]
Shuo Chen478204c2014-03-18 18:27:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef REPO_SERVER_REPO_HPP
8#define REPO_SERVER_REPO_HPP
9
10#include "../storage/storage-handle.hpp"
11#include "../storage/sqlite/sqlite-handle.hpp"
12#include "../ndn-handle/read-handle.hpp"
13#include "../ndn-handle/write-handle.hpp"
14#include "../ndn-handle/delete-handle.hpp"
15#include "../ndn-handle/tcp-bulk-insert-handle.hpp"
16
17#include <string>
18#include <iostream>
19#include <fstream>
20#include <vector>
21#include <ndn-cpp-dev/face.hpp>
22#include <ndn-cpp-dev/util/command-interest-validator.hpp>
23#include <boost/property_tree/ptree.hpp>
24#include <boost/property_tree/info_parser.hpp>
25
26namespace repo {
27
28using std::string;
29using std::vector;
30using std::pair;
31
32struct RepoConfig
33{
34 //StorageMethod storageMethod; This will be implemtented if there is other method.
35 std::string dbPath;
36 vector<ndn::Name> dataPrefixes;
37 vector<ndn::Name> repoPrefixes;
38 vector<pair<string, string> > tcpBulkInsertEndpoints;
39
40 //@todo validator should be configured in config file
41 boost::property_tree::ptree validatorNode;
42};
43
44RepoConfig
45parseConfig(const std::string& confPath);
46
47class Repo : noncopyable
48{
49
50public:
51 class Error : public std::runtime_error
52 {
53 public:
54 explicit
55 Error(const std::string& what)
56 : std::runtime_error(what)
57 {
58 }
59 };
60
61public:
62 Repo(boost::asio::io_service& ioService, const RepoConfig& config);
63
64 void
65 enableListening();
66
67private:
68 static shared_ptr<StorageHandle>
69 openStorage(const RepoConfig& config);
70
71private:
72 RepoConfig m_config;
73 ndn::Scheduler m_scheduler;
74 ndn::Face m_face;
75 shared_ptr<StorageHandle> m_storageHandle;
76 KeyChain m_keyChain;
77 CommandInterestValidator m_validator;
78 ReadHandle m_readHandle;
79 WriteHandle m_writeHandle;
80 DeleteHandle m_deleteHandle;
81 TcpBulkInsertHandle m_tcpBulkInsertHandle;
82};
83
84} // namespace repo
85
86#endif // REPO_SERVER_REPO_HPP