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/time.hpp> 42 #pragma clang diagnostic ignored "-Wundefined-func-template" 49 namespace autoconfig {
55 namespace po = boost::program_options;
59 const po::options_description& opts,
60 const char* programName)
62 os <<
"Usage: " << programName <<
" [options]\n" 70 boost::asio::signal_set terminateSignals(proc.
getIoService());
71 terminateSignals.add(SIGINT);
72 terminateSignals.add(SIGTERM);
73 terminateSignals.async_wait([&] (
const boost::system::error_code& error,
int signalNo) {
77 const char* signalName = ::strsignal(signalNo);
78 std::cerr <<
"Exiting on signal ";
79 if (signalName ==
nullptr) {
80 std::cerr << signalNo;
83 std::cerr << signalName;
85 std::cerr << std::endl;
90 util::scheduler::ScopedEventId runEvt;
91 auto scheduleRerun = [&] (time::nanoseconds delay) {
92 runEvt = sched.scheduleEvent(delay, [&] { proc.
runOnce(); });
96 scheduleRerun(DAEMON_UNCONDITIONAL_INTERVAL);
100 netmon.onNetworkStateChanged.connect([&] { scheduleRerun(NETMON_DAMPEN_PERIOD); });
102 scheduleRerun(DAEMON_INITIAL_DELAY);
110 bool isDaemon =
false;
111 std::string configFile;
113 po::options_description optionsDescription(
"Options");
114 optionsDescription.add_options()
115 (
"help,h",
"print this message and exit")
116 (
"version,V",
"show version information and exit")
117 (
"daemon,d", po::bool_switch(&isDaemon)->default_value(isDaemon),
118 "Run in daemon mode, detecting network change events and re-running the auto-discovery procedure. " 119 "In addition, the auto-discovery procedure is unconditionally re-run every hour.\n" 120 "NOTE: if the connection to NFD fails, the daemon will exit.")
121 (
"ndn-fch-url", po::value<std::string>(&options.
ndnFchUrl)->default_value(options.
ndnFchUrl),
122 "URL for NDN-FCH (Find Closest Hub) service")
123 (
"config,c", po::value<std::string>(&configFile),
124 "Configuration file. Exit immediately unless 'enabled = true' is specified in the config file.")
127 po::variables_map vm;
129 po::store(po::parse_command_line(argc, argv, optionsDescription), vm);
132 catch (
const std::exception& e) {
133 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
134 usage(std::cerr, optionsDescription, argv[0]);
138 if (vm.count(
"help")) {
139 usage(std::cout, optionsDescription, argv[0]);
143 if (vm.count(
"version")) {
144 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
148 if (vm.count(
"config")) {
149 po::options_description configFileOptions;
150 configFileOptions.add_options()
151 (
"enabled", po::value<bool>()->default_value(
false))
154 po::store(po::parse_config_file<char>(configFile.data(), configFileOptions), vm);
157 catch (
const std::exception& e) {
158 std::cerr <<
"ERROR in config: " << e.what() <<
"\n\n";
161 if (!vm[
"enabled"].as<bool>()) {
178 proc.
onComplete.connect([&exitCode] (
bool isSuccess) { exitCode = isSuccess ? 0 : 1; });
180 face.processEvents();
183 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)