main.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include "program.hpp"
27 #include "core/version.hpp"
28 
29 #include <iostream>
30 #include <unistd.h>
31 
32 #include <boost/exception/diagnostic_information.hpp>
33 
34 namespace ndn {
35 namespace tools {
36 namespace autoconfig_server {
37 
38 static void
39 usage(const char* programName)
40 {
41  std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n"
42  << "\n"
43  << "Options:\n"
44  << " -h - print usage and exit\n"
45  << " -V - print version number and exit\n"
46  << " -p prefix - a local prefix of the hub\n"
47  << " hub-face - a FaceUri to reach the hub\n";
48 }
49 
50 static int
51 main(int argc, char** argv)
52 {
53  Options options;
54 
55  int opt = -1;
56  while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
57  switch (opt) {
58  case 'h':
59  usage(argv[0]);
60  return 0;
61  case 'V':
62  std::cout << NFD_VERSION_BUILD_STRING << std::endl;
63  return 0;
64  case 'p':
65  options.routablePrefixes.emplace_back(::optarg);
66  break;
67  default:
68  usage(argv[0]);
69  return 2;
70  }
71  }
72 
73  if (argc != ::optind + 1) {
74  usage(argv[0]);
75  return 2;
76  }
77 
78  if (!options.hubFaceUri.parse(argv[::optind])) {
79  std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl;
80  return 2;
81  }
82 
83  try {
84  Face face;
85  KeyChain keyChain;
86  Program program(options, face, keyChain);
87  program.run();
88  }
89  catch (const std::exception& e) {
90  std::cerr << "ERROR: " << boost::diagnostic_information(e);
91  return 1;
92  }
93  return 0;
94 }
95 
96 } // namespace autoconfig_server
97 } // namespace tools
98 } // namespace ndn
99 
100 int
101 main(int argc, char** argv)
102 {
103  return ndn::tools::autoconfig_server::main(argc, argv);
104 }
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
Definition: dns-srv.cpp:41
static int main(int argc, char **argv)
Definition: main.cpp:51
static void usage(const char *programName)
Definition: main.cpp:39
std::vector< Name > routablePrefixes
Definition: program.hpp:41
const char NFD_VERSION_BUILD_STRING[]
NFD version string, including git commit information, if NFD is build from specific git commit...