blob: a92eb7d2a5118617c2dca077e893a064c032bd0c [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
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#ifndef REPO_REPO_HPP
21#define REPO_REPO_HPP
Shuo Chen478204c2014-03-18 18:27:04 -070022
Alexander Afanasyev39d98072014-05-04 12:46:29 -070023#include "storage/storage-handle.hpp"
24#include "storage/sqlite-handle.hpp"
Shuo Chen478204c2014-03-18 18:27:04 -070025
Alexander Afanasyev39d98072014-05-04 12:46:29 -070026#include "handles/read-handle.hpp"
27#include "handles/write-handle.hpp"
28#include "handles/delete-handle.hpp"
29#include "handles/tcp-bulk-insert-handle.hpp"
30
Alexander Afanasyeve291caf2014-04-25 11:17:36 -070031#include <ndn-cxx/face.hpp>
32#include <ndn-cxx/util/command-interest-validator.hpp>
Alexander Afanasyev39d98072014-05-04 12:46:29 -070033
Shuo Chen478204c2014-03-18 18:27:04 -070034#include <boost/property_tree/ptree.hpp>
35#include <boost/property_tree/info_parser.hpp>
36
37namespace repo {
38
39using std::string;
40using std::vector;
41using std::pair;
42
43struct RepoConfig
44{
45 //StorageMethod storageMethod; This will be implemtented if there is other method.
46 std::string dbPath;
47 vector<ndn::Name> dataPrefixes;
48 vector<ndn::Name> repoPrefixes;
49 vector<pair<string, string> > tcpBulkInsertEndpoints;
50
51 //@todo validator should be configured in config file
52 boost::property_tree::ptree validatorNode;
53};
54
55RepoConfig
56parseConfig(const std::string& confPath);
57
58class Repo : noncopyable
59{
60
61public:
62 class Error : public std::runtime_error
63 {
64 public:
65 explicit
66 Error(const std::string& what)
67 : std::runtime_error(what)
68 {
69 }
70 };
71
72public:
73 Repo(boost::asio::io_service& ioService, const RepoConfig& config);
74
75 void
76 enableListening();
77
78private:
79 static shared_ptr<StorageHandle>
80 openStorage(const RepoConfig& config);
81
82private:
83 RepoConfig m_config;
84 ndn::Scheduler m_scheduler;
85 ndn::Face m_face;
86 shared_ptr<StorageHandle> m_storageHandle;
87 KeyChain m_keyChain;
88 CommandInterestValidator m_validator;
89 ReadHandle m_readHandle;
90 WriteHandle m_writeHandle;
91 DeleteHandle m_deleteHandle;
92 TcpBulkInsertHandle m_tcpBulkInsertHandle;
93};
94
95} // namespace repo
96
Alexander Afanasyev39d98072014-05-04 12:46:29 -070097#endif // REPO_REPO_HPP