]> git.stg.codes - ssmd.git/blob - src/settings.cpp
Fix compilation issues with new cURL
[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         ("data-url", po::value<std::string>(), "data access URL")
23         ("version,v", "show gssmd version and exit")
24     ;
25 }
26
27 void SettingsParser::init(int argc, char * argv[])
28 {
29     po::variables_map vm;
30     po::store(po::parse_command_line(argc, argv, _desc), vm);
31     po::notify(vm);    
32
33     _settings._isHelp = vm.count("help");
34     _settings._isVersion = vm.count("version");
35
36     if (vm.count("config")) {
37         _settings._configFile = vm["config"].as<std::string>();
38     }
39
40     if (!_settings._isHelp &&
41         !_settings._isVersion) {
42         try {
43             parseFile(_settings._configFile);
44         }
45         catch (std::exception & ex) {
46             logger << "Error parsing config file '" << _settings._configFile << "': " << ex.what() << std::endl;
47         }
48     }
49
50     if (vm.count("debug")) {
51         _settings._isDebug = true;
52     }
53     if (vm.count("daemon")) {
54         _settings._isDaemon = true;
55     }
56
57     if (vm.count("log-file")) {
58         _settings._logFile = vm["log-file"].as<std::string>();
59     }
60
61     if (vm.count("pid-file")) {
62         _settings._PIDFile = vm["pid-file"].as<std::string>();
63     }
64
65     if (vm.count("switch-sync-interval")) {
66         _settings._switchSyncInterval = vm["switch-sync-interval"].as<time_t>();
67     }
68
69     if (vm.count("info-sync-interval")) {
70         _settings._infoSyncInterval = vm["info-sync-interval"].as<time_t>();
71     }
72
73     if (vm.count("up-profile-id")) {
74         _settings._upProfileId = vm["up-profile-id"].as<unsigned>();
75     }
76
77     if (vm.count("down-profile-id")) {
78         _settings._downProfileId = vm["down-profile-id"].as<unsigned>();
79     }
80
81     if (vm.count("data-url")) {
82         _settings._dataURL = vm["data-url"].as<std::string>();
83     }
84 }
85
86 void SettingsParser::reloadConfig()
87 {
88     parseFile(_settings._configFile);
89 }