| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2018-2019, Regents of the University of California. |
| * |
| * This file is part of NDN repo-ng (Next generation of NDN repository). |
| * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| * |
| * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #include "config.hpp" |
| #include "extended-error-message.hpp" |
| #include "repo.hpp" |
| |
| #include <string.h> // for strsignal() |
| |
| #include <boost/asio/io_service.hpp> |
| #include <boost/asio/signal_set.hpp> |
| #include <boost/program_options.hpp> |
| |
| #include <ndn-cxx/util/logger.hpp> |
| |
| NDN_LOG_INIT(repo.main); |
| |
| int |
| main(int argc, char** argv) |
| { |
| std::string configFile(DEFAULT_CONFIG_FILE); |
| |
| namespace po = boost::program_options; |
| po::options_description optsDesc("Options"); |
| optsDesc.add_options() |
| ("help,h", "print this help message and exit") |
| ("config-file,c", po::value<std::string>(&configFile)->default_value(configFile), |
| "path to configuration file") |
| ; |
| |
| po::variables_map vm; |
| try { |
| po::store(po::parse_command_line(argc, argv, optsDesc), vm); |
| po::notify(vm); |
| } |
| catch (const po::error& e) { |
| std::cerr << "ERROR: " << e.what() << std::endl; |
| return 2; |
| } |
| catch (const boost::bad_any_cast& e) { |
| std::cerr << "ERROR: " << e.what() << std::endl; |
| return 2; |
| } |
| |
| if (vm.count("help") != 0) { |
| std::cout << "Usage: " << argv[0] << " [options]\n" |
| << "\n" |
| << optsDesc; |
| return 0; |
| } |
| |
| boost::asio::io_service ioService; |
| |
| /// \todo reload config file on SIGHUP |
| boost::asio::signal_set signalSet(ioService, SIGINT, SIGTERM); |
| signalSet.async_wait([&ioService] (const boost::system::error_code& error, int signalNo) { |
| if (!error) { |
| NDN_LOG_FATAL("Exiting on signal " << signalNo << "/" << strsignal(signalNo)); |
| ioService.stop(); |
| } |
| }); |
| |
| try { |
| repo::Repo repo(ioService, repo::parseConfig(configFile)); |
| repo.initializeStorage(); |
| repo.enableValidation(); |
| repo.enableListening(); |
| |
| ioService.run(); |
| } |
| catch (const std::exception& e) { |
| NDN_LOG_FATAL(repo::getExtendedErrorMessage(e)); |
| return 1; |
| } |
| |
| return 0; |
| } |