blob: 4166bd85804a92de2a0e1146313e6083b7190ac7 [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "pib.hpp"
23
24#include <ndn-cxx/util/io.hpp>
25#include <ndn-cxx/util/config-file.hpp>
26#include <ndn-cxx/security/key-chain.hpp>
27
28#include <boost/program_options/options_description.hpp>
29#include <boost/program_options/variables_map.hpp>
30#include <boost/program_options/parsers.hpp>
31#include <boost/filesystem.hpp>
32
33namespace ndn {
34namespace pib {
35
36int
37main(int argc, char** argv)
38{
39 namespace po = boost::program_options;
40 namespace fs = boost::filesystem;
41
42 std::string owner;
43 std::string dbDir;
44 std::string tpmLocator;
45 Face face;
46
47 std::cerr << "hello" << std::endl;
48
49 po::options_description description(
50 "General Usage\n"
51 " ndn-pib [-h] -o owner -d database_dir -t tpm_locator\n"
52 "General options");
53
54 description.add_options()
55 ("help,h", "produce help message")
56 ("owner,o", po::value<std::string>(&owner),
57 "Name of the owner, PIB will listen to /localhost/pib/[owner].")
58 ("database,d", po::value<std::string>(&dbDir),
59 "Absolute path to the directory of PIB database, /<database_dir>/pib.db")
60 ("tpm,t", po::value<std::string>(&tpmLocator),
61 "URI of the tpm. e.g., tpm-file:/var")
62 ;
63
64 po::variables_map vm;
65 try {
66 po::store(po::parse_command_line(argc, argv, description), vm);
67 po::notify(vm);
68 }
69 catch (const std::exception& e) {
70 std::cerr << "ERROR: " << e.what() << std::endl;
71 std::cerr << description << std::endl;
72 return 1;
73 }
74
75 if (vm.count("help") != 0) {
76 std::cerr << description << std::endl;
77 return 0;
78 }
79
80 try {
81 if (vm.count("owner") == 0 && vm.count("database") == 0 && vm.count("tpm") == 0) {
82 if (std::getenv("HOME")) {
83 fs::path pibDir(std::getenv("HOME"));
84 pibDir /= ".ndn/pib";
85 dbDir = pibDir.string();
86 }
87 else {
88 std::cerr << "ERROR: HOME variable is not set" << std::endl;
89 return 1;
90 }
91
92 tpmLocator = KeyChain::getDefaultTpmLocator();
93
94 if (std::getenv("USER")) {
95 owner = std::string(std::getenv("USER"));
96 }
97 else {
98 std::cerr << "ERROR: HOME variable is not set" << std::endl;
99 return 1;
100 }
101 }
102 else if (vm.count("owner") == 0 || vm.count("database") == 0 ||
103 vm.count("tpm") == 0) {
104 std::cerr << description << std::endl;
105 return 1;
106 }
107
108 Pib pib(face, dbDir, tpmLocator, owner);
109 face.processEvents();
110 }
111 catch (std::runtime_error& e) {
112 std::cerr << "ERROR: " << e.what() << std::endl;
113 return 1;
114 }
115
116
117 return 0;
118}
119
120} // namespace pib
121} // namespace ndn
122
123int
124main(int argc, char** argv)
125{
126 ndn::pib::main(argc, argv);
127}