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-2017, 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"
28 #include "core/version.hpp"
29 
30 #include <iostream>
31 #include <unistd.h>
32 
33 namespace ndn {
34 namespace tools {
35 namespace autoconfig_server {
36 
37 static void
38 usage(const char* programName)
39 {
40  std::cout << "Usage:\n" << programName << " [-h] [-V] [-p prefix] [-p prefix] ... hub-face\n"
41  << " -h - print usage and exit\n"
42  << " -V - print version number and exit\n"
43  << " -p prefix - a local prefix of the HUB\n"
44  << "\n"
45  << " hub-face - a FaceUri to reach the HUB\n"
46  << std::endl;
47 }
48 
49 int
50 main(int argc, char** argv)
51 {
52  Options options;
53 
54  int opt = -1;
55  while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
56  switch (opt) {
57  case 'h':
58  usage(argv[0]);
59  return 0;
60  case 'V':
61  std::cout << NFD_VERSION_BUILD_STRING << std::endl;
62  return 0;
63  case 'p':
64  options.routablePrefixes.emplace_back(::optarg);
65  break;
66  default:
67  usage(argv[0]);
68  return 2;
69  }
70  }
71 
72  if (argc != ::optind + 1) {
73  usage(argv[0]);
74  return 2;
75  }
76 
77  if (!options.hubFaceUri.parse(argv[::optind])) {
78  std::cerr << "ERROR: cannot parse HUB FaceUri\n";
79  return 2;
80  }
81 
82  try {
83  Face face;
84  KeyChain keyChain;
85  Program program(options, face, keyChain);
86  program.run();
87  }
88  catch (const std::exception& e) {
89  std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
90  return 1;
91  }
92  return 0;
93 }
94 
95 } // namespace autoconfig_server
96 } // namespace tools
97 } // namespace ndn
98 
99 int
100 main(int argc, char** argv)
101 {
102  return ndn::tools::autoconfig_server::main(argc, argv);
103 }
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
std::string getExtendedErrorMessage(const E &exception)
static void usage(const char *programName)
Definition: main.cpp:38
std::vector< Name > routablePrefixes
Definition: program.hpp:41
int main(int argc, char **argv)
Definition: main.cpp:50