server_options.cpp
Go to the documentation of this file.
1 
11 #include "server_options.h"
12 
13 #include <algorithm>
14 #include <boost/program_options/options_description.hpp>
15 #include <boost/program_options/parsers.hpp>
16 #include <boost/program_options/variables_map.hpp>
17 #include <functional>
18 #include <iostream>
19 
20 
21 #ifndef CONFIG_PATH
22 #define CONFIG_PATH "/etc/opcua/server"
23 #endif
24 
25 namespace
26 {
27 namespace po = boost::program_options;
28 using namespace OpcUa;
29 
30 const char * DefaultLogFilePath = "/var/log/opcua/server.log";
31 
32 const char * OPTION_HELP = "help";
33 const char * OPTION_CONFIG = "config-dir";
34 const char * OPTION_DAEMON = "daemon";
35 const char * OPTION_LOGFILE = "log-file";
36 
37 std::string GetConfigOptionValue(const po::variables_map & vm)
38 {
39  if (vm.count(OPTION_CONFIG))
40  {
41  return vm[OPTION_CONFIG].as<std::string>();
42  }
43 
44  return CONFIG_PATH;
45 }
46 
47 
48 bool GetDaemonMode(const po::variables_map & vm)
49 {
50  return vm.count(OPTION_DAEMON) != 0;
51 }
52 
53 std::string GetLogFile(const po::variables_map & vm)
54 {
55  if (vm.count(OPTION_LOGFILE))
56  {
57  return vm[OPTION_LOGFILE].as<std::string>();
58  }
59 
60  return DefaultLogFilePath;
61 }
62 
63 }
64 
65 
66 namespace OpcUa
67 {
68 namespace Server
69 {
70 
71 CommandLine::CommandLine(int argc, const char ** argv)
72  : StartPossible(true)
73  , IsDaemon(false)
74 {
75  // Declare the supported options.
76  po::options_description desc("Parameters");
77  desc.add_options()
78  (OPTION_HELP, "Print help message and exit.")
79  (OPTION_CONFIG, po::value<std::string>(), (std::string("Path to directory with configuration files. Default: ") + CONFIG_PATH).c_str())
80  (OPTION_LOGFILE, po::value<std::string>(), "Set path to the log file. Default 'var/log/opcua/server.log")
81  (OPTION_DAEMON, "Start in daemon mode.")
82  ;
83 
84  po::variables_map vm;
85  po::store(po::parse_command_line(argc, argv, desc), vm);
86  po::notify(vm);
87 
88  if (vm.count(OPTION_HELP))
89  {
90  desc.print(std::cout);
91  StartPossible = false;
92  return;
93  }
94 
95  IsDaemon = GetDaemonMode(vm);
96  ConfigDir = GetConfigOptionValue(vm);
97  LogFile = ::GetLogFile(vm);
98 }
99 
100 } // namespace UaServer
101 } // namespace OpcUa
102 
std::string GetLogFile() const
OPC UA Address space part. GNU LGPL.
CommandLine(int argc, const char **argv)
#define CONFIG_PATH
OpcUa client command line options parser. GNU LGPL.
const char Server[]
Definition: strings.h:121


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:07