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