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