32 #include <boost/exception/diagnostic_information.hpp> 33 #include <boost/program_options/options_description.hpp> 34 #include <boost/program_options/parsers.hpp> 35 #include <boost/program_options/variables_map.hpp> 37 #include <ndn-cxx/net/network-monitor.hpp> 38 #include <ndn-cxx/util/scheduler.hpp> 39 #include <ndn-cxx/util/time.hpp> 43 #pragma clang diagnostic ignored "-Wundefined-func-template" 50 namespace autoconfig {
52 namespace po = boost::program_options;
60 const po::options_description& opts,
61 const char* programName)
63 os <<
"Usage: " << programName <<
" [options]\n" 71 boost::asio::signal_set terminateSignals(proc.
getIoService());
72 terminateSignals.add(SIGINT);
73 terminateSignals.add(SIGTERM);
74 terminateSignals.async_wait([&] (
const boost::system::error_code& error,
int signalNo) {
78 const char* signalName = ::strsignal(signalNo);
79 std::cerr <<
"Exiting on signal ";
80 if (signalName ==
nullptr) {
81 std::cerr << signalNo;
84 std::cerr << signalName;
86 std::cerr << std::endl;
91 scheduler::ScopedEventId runEvt;
92 auto scheduleRerun = [&] (time::nanoseconds delay) {
93 runEvt = sched.schedule(delay, [&] { proc.
runOnce(); });
97 scheduleRerun(DAEMON_UNCONDITIONAL_INTERVAL);
101 netmon.onNetworkStateChanged.connect([&] { scheduleRerun(NETMON_DAMPEN_PERIOD); });
103 scheduleRerun(DAEMON_INITIAL_DELAY);
111 bool isDaemon =
false;
112 std::string configFile;
114 po::options_description optionsDescription(
"Options");
115 optionsDescription.add_options()
116 (
"help,h",
"print this message and exit")
117 (
"version,V",
"show version information and exit")
118 (
"daemon,d", po::bool_switch(&isDaemon)->default_value(isDaemon),
119 "Run in daemon mode, detecting network change events and re-running the auto-discovery procedure. " 120 "In addition, the auto-discovery procedure is unconditionally re-run every hour.\n" 121 "NOTE: if the connection to NFD fails, the daemon will exit.")
122 (
"ndn-fch-url", po::value<std::string>(&options.
ndnFchUrl)->default_value(options.
ndnFchUrl),
123 "URL for NDN-FCH (Find Closest Hub) service")
124 (
"config,c", po::value<std::string>(&configFile),
125 "Configuration file. Exit immediately unless 'enabled = true' is specified in the config file.")
128 po::variables_map vm;
130 po::store(po::parse_command_line(argc, argv, optionsDescription), vm);
133 catch (
const std::exception& e) {
134 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
135 usage(std::cerr, optionsDescription, argv[0]);
139 if (vm.count(
"help")) {
140 usage(std::cout, optionsDescription, argv[0]);
144 if (vm.count(
"version")) {
149 if (vm.count(
"config")) {
150 po::options_description configFileOptions;
151 configFileOptions.add_options()
152 (
"enabled", po::value<bool>()->default_value(
false))
155 po::store(po::parse_config_file<char>(configFile.data(), configFileOptions), vm);
158 catch (
const std::exception& e) {
159 std::cerr <<
"ERROR in config: " << e.what() <<
"\n\n";
162 if (!vm[
"enabled"].as<bool>()) {
179 proc.
onComplete.connect([&exitCode] (
bool isSuccess) { exitCode = isSuccess ? 0 : 1; });
181 face.processEvents();
184 catch (
const std::exception& e) {
185 std::cerr <<
"ERROR: " << boost::diagnostic_information(e);
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
const char NFD_VERSION_BUILD_STRING[]
NFD version string, including git commit information, if NFD is build from specific git commit...