Rev 1939 | Rev 1989 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1939 | Rev 1961 | ||
|---|---|---|---|
| Line 22... | Line 22... | ||
| 22 | 22 | ||
| 23 | #include <iostream> |
23 | #include <iostream> |
| 24 | #include <fstream> |
24 | #include <fstream> |
| 25 | 25 | ||
| 26 | #include <boost/filesystem.hpp> |
26 | #include <boost/filesystem.hpp> |
| - | 27 | ||
| - | 28 | #include "common/log.h" |
|
| 27 | 29 | ||
| 28 | namespace atom { |
30 | namespace atom { |
| 29 | namespace config { |
31 | namespace config { |
| 30 | 32 | ||
| - | 33 | static const std::string log_module_ = "config"; |
|
| 31 | Manager::Pointer Manager::instance_; |
34 | Manager::Pointer Manager::instance_; |
| 32 | 35 | ||
| 33 | Manager::Manager() : command_line_("Command line options"), configuration_file_("Configuration file options") |
36 | Manager::Manager() : command_line_("Command line options"), configuration_file_("Configuration file options") |
| 34 | { |
37 | { |
| 35 | std::string default_config_file = "/etc/atom/atom.conf"; |
38 | std::string default_config_file = "/etc/atom/atom.conf"; |
| Line 44... | Line 47... | ||
| 44 | ("CommandPort", boost::program_options::value<int>()->default_value(1202), "TCP port to open for command input") |
47 | ("CommandPort", boost::program_options::value<int>()->default_value(1202), "TCP port to open for command input") |
| 45 | ("DaemonPort", boost::program_options::value<int>()->default_value(1200), "TCP port to open for canDaemon input/output") |
48 | ("DaemonPort", boost::program_options::value<int>()->default_value(1200), "TCP port to open for canDaemon input/output") |
| 46 | ("MbbPort", boost::program_options::value<int>()->default_value(1212), "TCP port to open for MBB clients") |
49 | ("MbbPort", boost::program_options::value<int>()->default_value(1212), "TCP port to open for MBB clients") |
| 47 | ("LogFile", boost::program_options::value<std::string>(), "File to log output to") |
50 | ("LogFile", boost::program_options::value<std::string>(), "File to log output to") |
| 48 | ("LogLevel", boost::program_options::value<int>()->default_value(4), "Level of logging") |
51 | ("LogLevel", boost::program_options::value<int>()->default_value(4), "Level of logging") |
| - | 52 | ("LogLevelMask", boost::program_options::value<std::string>(), "Level of logging") |
|
| 49 | ("ScriptPath", boost::program_options::value<std::string>(), "Path to where the scripts are") |
53 | ("ScriptPath", boost::program_options::value<std::string>(), "Path to where the scripts are") |
| 50 | ("UserScriptPath",boost::program_options::value<std::string>(), "Path to where the user scripts are") |
54 | ("UserScriptPath",boost::program_options::value<std::string>(), "Path to where the user scripts are") |
| 51 | ("StoragePath", boost::program_options::value<std::string>(), "Path to where the storage files are") |
55 | ("StoragePath", boost::program_options::value<std::string>(), "Path to where the storage files are") |
| 52 | ("ProtocolFile", boost::program_options::value<std::string>(), "File to read the protocol form") |
56 | ("ProtocolFile", boost::program_options::value<std::string>(), "File to read the protocol form") |
| 53 | ("CanNet", boost::program_options::value<common::StringList>(), "Information on where to locate the CAN networks") |
57 | ("CanNet", boost::program_options::value<common::StringList>(), "Information on where to locate the CAN networks") |
| Line 55... | Line 59... | ||
| 55 | 59 | ||
| 56 | this->command_line_.add_options() |
60 | this->command_line_.add_options() |
| 57 | ("help,h", "produce help message") |
61 | ("help,h", "produce help message") |
| 58 | ("daemon,d", "start in daemon mode") |
62 | ("daemon,d", "start in daemon mode") |
| 59 | ("file,f", boost::program_options::value<std::string>()->default_value(default_config_file), "configuration file"); |
63 | ("file,f", boost::program_options::value<std::string>()->default_value(default_config_file), "configuration file"); |
| 60 | 64 | ||
| 61 | this->command_line_.add(this->configuration_file_); |
65 | this->command_line_.add(this->configuration_file_); |
| 62 | } |
66 | } |
| 63 | 67 | ||
| 64 | Manager::~Manager() |
68 | Manager::~Manager() |
| 65 | { |
69 | { |
| 66 | } |
70 | } |
| 67 | 71 | ||
| 68 | Manager::Pointer Manager::Instance() |
72 | Manager::Pointer Manager::Instance() |
| 69 | { |
73 | { |
| 70 | return Manager::instance_; |
74 | return Manager::instance_; |
| 71 | } |
75 | } |
| 72 | 76 | ||
| 73 | void Manager::Create() |
77 | void Manager::Create() |
| 74 | { |
78 | { |
| 75 | Manager::instance_ = Manager::Pointer(new Manager()); |
79 | Manager::instance_ = Manager::Pointer(new Manager()); |
| 76 | } |
80 | } |
| 77 | 81 | ||
| 78 | void Manager::Delete() |
82 | void Manager::Delete() |
| 79 | { |
83 | { |
| 80 | Manager::instance_.reset(); |
84 | Manager::instance_.reset(); |
| 81 | } |
85 | } |
| 82 | 86 | ||
| 83 | bool Manager::Set(int argument_count, char** argument_vector) |
87 | bool Manager::Set(int argument_count, char** argument_vector) |
| 84 | { |
88 | { |
| 85 | try |
89 | try |
| 86 | { |
90 | { |
| 87 | boost::program_options::store(boost::program_options::command_line_parser(argument_count, argument_vector).options(this->command_line_).run(), this->variable_map_); |
91 | boost::program_options::store(boost::program_options::command_line_parser(argument_count, argument_vector).options(this->command_line_).run(), this->variable_map_); |
| 88 | } |
92 | } |
| 89 | catch (boost::program_options::unknown_option e) |
93 | catch (boost::program_options::unknown_option e) |
| 90 | { |
94 | { |
| 91 |
|
95 | log::Error(log_module_, e.what()); |
| 92 | std::cout << this->command_line_ << std::endl; |
96 | std::cout << this->command_line_ << std::endl; |
| 93 | return false; |
97 | return false; |
| 94 | } |
98 | } |
| 95 | catch (boost::program_options::invalid_syntax e) |
99 | catch (boost::program_options::invalid_syntax e) |
| 96 | { |
100 | { |
| 97 |
|
101 | log::Error(log_module_, e.what()); |
| 98 | std::cout << this->command_line_ << std::endl; |
102 | std::cout << this->command_line_ << std::endl; |
| 99 | return false; |
103 | return false; |
| 100 | } |
104 | } |
| 101 | 105 | ||
| 102 | std::ifstream ifs(this->GetAsString("file").data()); |
106 | std::ifstream ifs(this->GetAsString("file").data()); |
| 103 | 107 | ||
| 104 | if (!ifs.is_open()) |
108 | if (!ifs.is_open()) |
| 105 | { |
109 | { |
| 106 |
|
110 | log::Error(log_module_, "Could not find %s!", this->GetAsString("file").c_str()); |
| 107 | return false; |
111 | return false; |
| 108 | } |
112 | } |
| 109 | 113 | ||
| 110 | try |
114 | try |
| 111 | { |
115 | { |
| 112 | boost::program_options::store(boost::program_options::parse_config_file(ifs, this->configuration_file_), this->variable_map_); |
116 | boost::program_options::store(boost::program_options::parse_config_file(ifs, this->configuration_file_), this->variable_map_); |
| 113 | } |
117 | } |
| 114 | catch (boost::program_options::unknown_option e) |
118 | catch (boost::program_options::unknown_option e) |
| 115 | { |
119 | { |
| 116 | ifs.close(); |
120 | ifs.close(); |
| 117 |
|
121 | log::Error(log_module_, e.what()); |
| 118 | std::cout << this->configuration_file_ << std::endl; |
122 | std::cout << this->configuration_file_ << std::endl; |
| 119 | return false; |
123 | return false; |
| 120 | } |
124 | } |
| 121 | catch (boost::program_options::invalid_syntax e) |
125 | catch (boost::program_options::invalid_syntax e) |
| 122 | { |
126 | { |
| 123 |
|
127 | log::Error(log_module_, "%s found in %s!", e.what(), this->GetAsString("file").c_str()); |
| 124 | std::cout << this->command_line_ << std::endl; |
128 | std::cout << this->command_line_ << std::endl; |
| 125 | return false; |
129 | return false; |
| 126 | } |
130 | } |
| 127 | 131 | ||
| 128 | ifs.close(); |
132 | ifs.close(); |
| 129 | 133 | ||
| 130 | if (this->Exist("help")) |
134 | if (this->Exist("help")) |
| 131 | { |
135 | { |
| 132 | std::cout << this->command_line_ << std::endl; |
136 | std::cout << this->command_line_ << std::endl; |
| 133 | return false; |
137 | return false; |
| 134 | } |
138 | } |
| 135 | 139 | ||
| 136 |
|
140 | log::Info(log_module_, "Using %s as configuraiton file.", this->GetAsString("file").c_str()); |
| 137 | 141 | ||
| 138 | return true; |
142 | return true; |
| 139 | } |
143 | } |
| 140 | 144 | ||
| 141 | bool Manager::Exist(std::string name) |
145 | bool Manager::Exist(std::string name) |
| Line 159... | Line 163... | ||
| 159 | } |
163 | } |
| 160 | 164 | ||
| 161 | 165 | ||
| 162 | }; // namespace config |
166 | }; // namespace config |
| 163 | }; // namespace atom |
167 | }; // namespace atom |
| 164 | - | ||