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