blob: 9338ef782ff65306b7a44a3aeb512764e679f311 [file] [log] [blame]
Shuo Chen478204c2014-03-18 18:27:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Shuo Chen478204c2014-03-18 18:27:04 -070018 */
19
20#ifndef REPO_SERVER_REPO_HPP
21#define REPO_SERVER_REPO_HPP
22
23#include "../storage/storage-handle.hpp"
24#include "../storage/sqlite/sqlite-handle.hpp"
25#include "../ndn-handle/read-handle.hpp"
26#include "../ndn-handle/write-handle.hpp"
27#include "../ndn-handle/delete-handle.hpp"
28#include "../ndn-handle/tcp-bulk-insert-handle.hpp"
29
30#include <string>
31#include <iostream>
32#include <fstream>
33#include <vector>
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070034#include <ndn-cxx/face.hpp>
35#include <ndn-cxx/util/command-interest-validator.hpp>
Shuo Chen478204c2014-03-18 18:27:04 -070036#include <boost/property_tree/ptree.hpp>
37#include <boost/property_tree/info_parser.hpp>
38
39namespace repo {
40
41using std::string;
42using std::vector;
43using std::pair;
44
45struct RepoConfig
46{
47 //StorageMethod storageMethod; This will be implemtented if there is other method.
48 std::string dbPath;
49 vector<ndn::Name> dataPrefixes;
50 vector<ndn::Name> repoPrefixes;
51 vector<pair<string, string> > tcpBulkInsertEndpoints;
52
53 //@todo validator should be configured in config file
54 boost::property_tree::ptree validatorNode;
55};
56
57RepoConfig
58parseConfig(const std::string& confPath);
59
60class Repo : noncopyable
61{
62
63public:
64 class Error : public std::runtime_error
65 {
66 public:
67 explicit
68 Error(const std::string& what)
69 : std::runtime_error(what)
70 {
71 }
72 };
73
74public:
75 Repo(boost::asio::io_service& ioService, const RepoConfig& config);
76
77 void
78 enableListening();
79
80private:
81 static shared_ptr<StorageHandle>
82 openStorage(const RepoConfig& config);
83
84private:
85 RepoConfig m_config;
86 ndn::Scheduler m_scheduler;
87 ndn::Face m_face;
88 shared_ptr<StorageHandle> m_storageHandle;
89 KeyChain m_keyChain;
90 CommandInterestValidator m_validator;
91 ReadHandle m_readHandle;
92 WriteHandle m_writeHandle;
93 DeleteHandle m_deleteHandle;
94 TcpBulkInsertHandle m_tcpBulkInsertHandle;
95};
96
97} // namespace repo
98
99#endif // REPO_SERVER_REPO_HPP