add logger
Change-Id: If41d6d94086ec9fffb954a52e1529ccfad7f42fe
diff --git a/daemon/main.cpp b/daemon/main.cpp
index d172f7d..d0b6bd0 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -19,8 +19,71 @@
* \author Yingdi Yu <yingdi@cs.ucla.edu>
*/
+#include "../core/logger.hpp"
+
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options/parsers.hpp>
+#include <boost/filesystem.hpp>
+
+
int
main(int argc, char** argv)
{
+ namespace po = boost::program_options;
+ namespace fs = boost::filesystem;
+
+ std::string configFile;
+
+ po::options_description description("General Usage\n"
+ " nsl [-h] [-c config]\n"
+ "General options");
+ description.add_options()
+ ("help,h", "produce help message")
+ ("config,c", po::value<std::string>(&configFile))
+ ;
+
+ po::variables_map vm;
+ try {
+ po::store(po::parse_command_line(argc, argv, description), vm);
+ po::notify(vm);
+ }
+ catch (const std::exception& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ std::cerr << description << std::endl;
+ return 1;
+ }
+
+ if (vm.count("help") != 0) {
+ std::cerr << description << std::endl;
+ return 0;
+ }
+
+ if (vm.count("config") == 0) {
+
+ if (!getenv("HOME")) {
+ configFile = "/usr/local/etc/ndn/nsl.conf";
+ }
+ else {
+ configFile = getenv("HOME");
+ configFile += "/.ndn/nsl.conf";
+ }
+
+ if (!fs::exists(fs::path(configFile))) {
+ std::cerr << "ERROR: config file is not available: " << configFile << std::endl;
+ return 1;
+ }
+ }
+
+ try {
+ ndn::Face face;
+ nsl::Logger(face, configFile);
+ face.processEvents();
+ }
+ catch (std::runtime_error& e) {
+ std::cerr << e.what() << std::endl;
+ return 1;
+ }
+
return 0;
}