Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California |
| 4 | * |
| 5 | * This file is part of NSL (NDN Signature Logger). |
| 6 | * See AUTHORS.md for complete list of NSL authors and contributors. |
| 7 | * |
| 8 | * NSL is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NSL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NSL, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * \author Yingdi Yu <yingdi@cs.ucla.edu> |
| 20 | */ |
| 21 | |
Yingdi Yu | 6ff3193 | 2015-03-23 13:30:07 -0700 | [diff] [blame^] | 22 | #include "../core/logger.hpp" |
| 23 | |
| 24 | #include <boost/program_options/options_description.hpp> |
| 25 | #include <boost/program_options/variables_map.hpp> |
| 26 | #include <boost/program_options/parsers.hpp> |
| 27 | #include <boost/filesystem.hpp> |
| 28 | |
| 29 | |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 30 | int |
| 31 | main(int argc, char** argv) |
| 32 | { |
Yingdi Yu | 6ff3193 | 2015-03-23 13:30:07 -0700 | [diff] [blame^] | 33 | namespace po = boost::program_options; |
| 34 | namespace fs = boost::filesystem; |
| 35 | |
| 36 | std::string configFile; |
| 37 | |
| 38 | po::options_description description("General Usage\n" |
| 39 | " nsl [-h] [-c config]\n" |
| 40 | "General options"); |
| 41 | description.add_options() |
| 42 | ("help,h", "produce help message") |
| 43 | ("config,c", po::value<std::string>(&configFile)) |
| 44 | ; |
| 45 | |
| 46 | po::variables_map vm; |
| 47 | try { |
| 48 | po::store(po::parse_command_line(argc, argv, description), vm); |
| 49 | po::notify(vm); |
| 50 | } |
| 51 | catch (const std::exception& e) { |
| 52 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 53 | std::cerr << description << std::endl; |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | if (vm.count("help") != 0) { |
| 58 | std::cerr << description << std::endl; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | if (vm.count("config") == 0) { |
| 63 | |
| 64 | if (!getenv("HOME")) { |
| 65 | configFile = "/usr/local/etc/ndn/nsl.conf"; |
| 66 | } |
| 67 | else { |
| 68 | configFile = getenv("HOME"); |
| 69 | configFile += "/.ndn/nsl.conf"; |
| 70 | } |
| 71 | |
| 72 | if (!fs::exists(fs::path(configFile))) { |
| 73 | std::cerr << "ERROR: config file is not available: " << configFile << std::endl; |
| 74 | return 1; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | try { |
| 79 | ndn::Face face; |
| 80 | nsl::Logger(face, configFile); |
| 81 | face.processEvents(); |
| 82 | } |
| 83 | catch (std::runtime_error& e) { |
| 84 | std::cerr << e.what() << std::endl; |
| 85 | return 1; |
| 86 | } |
| 87 | |
Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |