]> git.stg.codes - ssmd.git/blob - src/settings.cpp
Ommit "too big" error
[ssmd.git] / src / settings.cpp
1 #include "logger.h"
2 #include "settings.h"
3
4 using GTS::Settings;
5 using GTS::SettingsParser;
6
7 SettingsParser::SettingsParser()
8     : _desc("Allowed options")
9 {
10     // Declare the supported options.
11     _desc.add_options()
12         ("help", "produce help message")
13         ("config,c", po::value<std::string>()->default_value("/etc/gssmd/gssmd.conf"), "config file location")
14         ("daemon,d", "daemonize after start")
15         ("debug", "gssmd debugging")
16         ("log-file", po::value<std::string>(), "log file location")
17         ("pid-file", po::value<std::string>(), "PID file location")
18         ("switch-sync-interval,s", po::value<time_t>(), "switch synchronization interval")
19         ("info-sync-interval,i", po::value<time_t>(), "info synchronization interval")
20         ("up-profile-id", po::value<unsigned>(), "switch's upload profile id")
21         ("down-profile-id", po::value<unsigned>(), "switch's download profile id")
22         ("max-acl-per-pdu", po::value<size_t>(), "maximum ACL's per PDU")
23         ("data-url", po::value<std::string>(), "data access URL")
24         ("version,v", "show gssmd version and exit")
25     ;
26 }
27
28 void SettingsParser::init(int argc, char * argv[])
29 {
30     po::variables_map vm;
31     po::store(po::parse_command_line(argc, argv, _desc), vm);
32     po::notify(vm);    
33
34     _settings._isHelp = vm.count("help");
35     _settings._isVersion = vm.count("version");
36
37     if (vm.count("config")) {
38         _settings._configFile = vm["config"].as<std::string>();
39     }
40
41     if (!_settings._isHelp &&
42         !_settings._isVersion) {
43         try {
44             parseFile(_settings._configFile);
45         }
46         catch (std::exception & ex) {
47             logger << "Error parsing config file '" << _settings._configFile << "': " << ex.what() << std::endl;
48         }
49     }
50
51     if (vm.count("debug")) {
52         _settings._isDebug = true;
53     }
54     if (vm.count("daemon")) {
55         _settings._isDaemon = true;
56     }
57
58     if (vm.count("log-file")) {
59         _settings._logFile = vm["log-file"].as<std::string>();
60     }
61
62     if (vm.count("pid-file")) {
63         _settings._PIDFile = vm["pid-file"].as<std::string>();
64     }
65
66     if (vm.count("switch-sync-interval")) {
67         _settings._switchSyncInterval = vm["switch-sync-interval"].as<time_t>();
68     }
69
70     if (vm.count("info-sync-interval")) {
71         _settings._infoSyncInterval = vm["info-sync-interval"].as<time_t>();
72     }
73
74     if (vm.count("up-profile-id")) {
75         _settings._upProfileId = vm["up-profile-id"].as<unsigned>();
76     }
77
78     if (vm.count("down-profile-id")) {
79         _settings._downProfileId = vm["down-profile-id"].as<unsigned>();
80     }
81
82     if (vm.count("max-acl-per-pdu")) {
83         _settings._downProfileId = vm["max-acl-per-pdu"].as<unsigned>();
84     }
85
86     if (vm.count("data-url")) {
87         _settings._dataURL = vm["data-url"].as<std::string>();
88     }
89 }
90
91 void SettingsParser::reloadConfig()
92 {
93     parseFile(_settings._configFile);
94 }