Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "server_options.h"
00012
00013 #include <algorithm>
00014 #include <boost/program_options/options_description.hpp>
00015 #include <boost/program_options/parsers.hpp>
00016 #include <boost/program_options/variables_map.hpp>
00017 #include <functional>
00018 #include <iostream>
00019
00020
00021 #ifndef CONFIG_PATH
00022 #define CONFIG_PATH "/etc/opcua/server"
00023 #endif
00024
00025 namespace
00026 {
00027 namespace po = boost::program_options;
00028 using namespace OpcUa;
00029
00030 const char* DefaultLogFilePath = "/var/log/opcua/server.log";
00031
00032 const char* OPTION_HELP = "help";
00033 const char* OPTION_CONFIG = "config-dir";
00034 const char* OPTION_DAEMON = "daemon";
00035 const char* OPTION_LOGFILE = "log-file";
00036
00037 std::string GetConfigOptionValue(const po::variables_map& vm)
00038 {
00039 if (vm.count(OPTION_CONFIG))
00040 {
00041 return vm[OPTION_CONFIG].as<std::string>();
00042 }
00043 return CONFIG_PATH;
00044 }
00045
00046
00047 bool GetDaemonMode(const po::variables_map& vm)
00048 {
00049 return vm.count(OPTION_DAEMON) != 0;
00050 }
00051
00052 std::string GetLogFile(const po::variables_map& vm)
00053 {
00054 if (vm.count(OPTION_LOGFILE))
00055 {
00056 return vm[OPTION_LOGFILE].as<std::string>();
00057 }
00058 return DefaultLogFilePath;
00059 }
00060
00061 }
00062
00063
00064 namespace OpcUa
00065 {
00066 namespace Server
00067 {
00068
00069 CommandLine::CommandLine(int argc, const char** argv)
00070 : StartPossible(true)
00071 , IsDaemon(false)
00072 {
00073
00074 po::options_description desc("Parameters");
00075 desc.add_options()
00076 (OPTION_HELP, "Print help message and exit.")
00077 (OPTION_CONFIG, po::value<std::string>(), (std::string("Path to directory with configuration files. Default: ") + CONFIG_PATH).c_str())
00078 (OPTION_LOGFILE, po::value<std::string>(), "Set path to the log file. Default 'var/log/opcua/server.log")
00079 (OPTION_DAEMON, "Start in daemon mode.")
00080 ;
00081
00082 po::variables_map vm;
00083 po::store(po::parse_command_line(argc, argv, desc), vm);
00084 po::notify(vm);
00085
00086 if (vm.count(OPTION_HELP))
00087 {
00088 desc.print(std::cout);
00089 StartPossible = false;
00090 return;
00091 }
00092
00093 IsDaemon = GetDaemonMode(vm);
00094 ConfigDir = GetConfigOptionValue(vm);
00095 LogFile = ::GetLogFile(vm);
00096 }
00097
00098 }
00099 }
00100