29 #include "core/version.hpp" 33 #include <boost/program_options/options_description.hpp> 34 #include <boost/program_options/parsers.hpp> 35 #include <boost/program_options/variables_map.hpp> 36 #include <ndn-cxx/net/network-monitor.hpp> 37 #include <ndn-cxx/util/scheduler.hpp> 38 #include <ndn-cxx/util/scheduler-scoped-event-id.hpp> 39 #include <ndn-cxx/util/time.hpp> 43 #pragma clang diagnostic ignored "-Wundefined-func-template" 48 namespace autoconfig {
56 namespace po = boost::program_options;
60 const po::options_description& optionsDescription,
61 const char* programName)
64 <<
" " << programName <<
" [options]\n" 66 os << optionsDescription;
72 boost::asio::signal_set terminateSignals(proc.
getIoService());
73 terminateSignals.add(SIGINT);
74 terminateSignals.add(SIGTERM);
75 terminateSignals.async_wait([&] (
const boost::system::error_code& error,
int signalNo) {
79 const char* signalName = ::strsignal(signalNo);
80 std::cerr <<
"Exit on signal ";
81 if (signalName ==
nullptr) {
82 std::cerr << signalNo;
85 std::cerr << signalName;
87 std::cerr << std::endl;
92 util::scheduler::ScopedEventId runEvt(sched);
93 auto scheduleRerun = [&] (time::nanoseconds delay) {
94 runEvt = sched.scheduleEvent(delay, [&] { proc.
runOnce(); });
98 scheduleRerun(DAEMON_UNCONDITIONAL_INTERVAL);
102 netmon.onNetworkStateChanged.connect([&] { scheduleRerun(NETMON_DAMPEN_PERIOD); });
104 scheduleRerun(DAEMON_INITIAL_DELAY);
112 bool isDaemon =
false;
113 std::string configFile;
115 po::options_description optionsDescription(
"Options");
116 optionsDescription.add_options()
117 (
"help,h",
"print this message and exit")
118 (
"version,V",
"display version and exit")
119 (
"daemon,d", po::bool_switch(&isDaemon)->default_value(isDaemon),
120 "run in daemon mode, detecting network change events and re-running auto-discovery procedure. " 121 "In addition, the auto-discovery procedure is unconditionally re-run every hour.\n" 122 "NOTE: if connection to NFD fails, the daemon will be terminated.")
123 (
"ndn-fch-url", po::value<std::string>(&options.
ndnFchUrl)->default_value(options.
ndnFchUrl),
124 "URL for NDN-FCH (Find Closest Hub) service")
125 (
"config,c", po::value<std::string>(&configFile),
126 "configuration file. Exit immediately if `enabled = true` is not specified in config file.")
129 po::variables_map vm;
131 po::store(po::parse_command_line(argc, argv, optionsDescription), vm);
134 catch (
const std::exception& e) {
135 std::cerr <<
"ERROR: " << e.what() <<
"\n" <<
"\n\n";
136 usage(std::cerr, optionsDescription, argv[0]);
140 if (vm.count(
"help")) {
141 usage(std::cout, optionsDescription, argv[0]);
145 if (vm.count(
"version")) {
146 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
150 if (vm.count(
"config")) {
151 po::options_description configFileOptions;
152 configFileOptions.add_options()
153 (
"enabled", po::value<bool>()->default_value(
false))
156 po::store(po::parse_config_file<char>(configFile.data(), configFileOptions), vm);
159 catch (
const std::exception& e) {
160 std::cerr <<
"ERROR in config: " << e.what() <<
"\n\n";
163 if (!vm[
"enabled"].as<bool>()) {
180 proc.
onComplete.connect([&exitCode] (
bool isSuccess) { exitCode = isSuccess ? 0 : 3; });
182 face.processEvents();
185 catch (
const std::exception& e) {
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
std::string getExtendedErrorMessage(const E &exception)