blob: 4ea011a261e17c6ecc38d6a36c7f8742185da296 [file] [log] [blame]
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -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
Shuo Chen9c2477f2014-03-13 15:01:06 -07007#include <string>
8#include <iostream>
9#include <ndn-cpp-dev/face.hpp>
Shuo Chen29c77fe2014-03-18 11:29:41 -070010#include <ndn-cpp-dev/util/command-interest-validator.hpp>
Shuo Chen9c2477f2014-03-13 15:01:06 -070011
12#include "../storage/storage-handle.hpp"
13#include "../storage/sqlite/sqlite-handle.hpp"
14#include "../ndn-handle/read-handle.hpp"
Shuo Chen29c77fe2014-03-18 11:29:41 -070015#include "../ndn-handle/write-handle.hpp"
Shuo Chen09f09bb2014-03-18 15:37:11 -070016#include "../ndn-handle/delete-handle.hpp"
Shuo Chen9c2477f2014-03-13 15:01:06 -070017
18using namespace repo;
19
20static const string ndnRepoUsageMessage =
21 "ndn-repo - NDNx Repository Daemon\n"
22 "-d: set database path\n"
23 "-h: show help message\n"
24 "-c: set config file path\n"
25 ;
26
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070027int
Shuo Chen9c2477f2014-03-13 15:01:06 -070028main(int argc, char** argv) {
29 int opt;
30 string dbPath;
31 string confPath;
32 while ((opt = getopt(argc, argv, "d:hc:")) != -1) {
33 switch (opt) {
34 case 'd':
35 dbPath = string(optarg);
36 break;
37 case 'h':
38 std::cout << ndnRepoUsageMessage << std::endl;
39 return 1;
40 case 'c':
41 confPath = string(optarg);
42 break;
43 default:
44 break;
45 }
46 }
Shuo Chen9c2477f2014-03-13 15:01:06 -070047
Shuo Chen9c2477f2014-03-13 15:01:06 -070048 if (confPath.empty()) {
49 confPath = "./repo.conf";
50 }
Shuo Chen29c77fe2014-03-18 11:29:41 -070051
52 Name dataPrefix("ndn:/example/data");
53 Name repoPrefix("ndn:/example/repo");
54 /// @todo read from configuration
55
56 SqliteHandle sqliteHandle(dbPath);
57
58 shared_ptr<boost::asio::io_service> io =
59 ndn::make_shared<boost::asio::io_service>();
60
61 Face face(io);
62 Scheduler scheduler(*io);
63
64 /// @todo specify trust model
65 CommandInterestValidator validator;
66 KeyChain keyChain;
67
68 ReadHandle readHandle(face, sqliteHandle, keyChain, scheduler);
69 readHandle.listen(dataPrefix);
70 WriteHandle writeHandle(face, sqliteHandle, keyChain, scheduler, validator);
71 writeHandle.listen(repoPrefix);
Shuo Chen09f09bb2014-03-18 15:37:11 -070072 DeleteHandle deleteHandle(face, sqliteHandle, keyChain, scheduler, validator);
73 deleteHandle.listen(repoPrefix);
Shuo Chen9c2477f2014-03-13 15:01:06 -070074 face.processEvents();
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070075 return 0;
76}