]> git.stg.codes - ssmd.git/blob - include/settings.h
Initial adding
[ssmd.git] / include / settings.h
1 #ifndef __GTS_SETTINGS_H__
2 #define __GTS_SETTINGS_H__
3
4 #include <string>
5
6 #include <boost/noncopyable.hpp>
7 #include <boost/program_options.hpp>
8
9 namespace po = boost::program_options;
10
11 namespace GTS {
12
13 class SettingsParser;
14 class Settings {
15     public:
16         // Construction / destruction
17         Settings();
18         Settings(const Settings & rvalue);
19         ~Settings();
20
21         const Settings & operator=(const Settings & rvalue);
22         
23         // Accessors
24         bool isHelp() const throw() { return _isHelp; }
25         bool isVersion() const throw() { return _isVersion; }
26         bool isDebug() const throw() { return _isDebug; }
27         bool isDaemon() const throw() { return _isDaemon; }
28
29         const std::string & configFile() const throw() { return _configFile; }
30         const std::string & logFile() const throw() { return _logFile; }
31         const std::string & PIDFile() const throw() { return _PIDFile; }
32
33         time_t switchSyncInterval() const throw() { return _switchSyncInterval; }
34         time_t infoSyncInterval() const throw() { return _infoSyncInterval; }
35
36         unsigned upProfileId() const throw() { return _upProfileId; }
37         unsigned downProfileId() const throw() { return _downProfileId; }
38
39         const std::string & dataURL() const throw() { return _dataURL; }
40
41         // Setters
42         void setIsHelp(bool value) throw() { _isHelp = value; }
43         void setIsVersion(bool value) throw() { _isVersion = value; }
44         void setIsDebug(bool value) throw() { _isDebug = value; }
45         void setIsDaemon(bool value) throw() { _isDaemon = value; }
46
47         void setConfigFile(const std::string & value) throw() { _configFile = value; }
48         void setLogFile(const std::string & value) throw() { _logFile = value; }
49         void setPIDFile(const std::string & value) throw() { _PIDFile = value; }
50
51         void setSwitchSyncInterval(time_t value) throw() { _switchSyncInterval = value; }
52         void setInfoSyncInterval(time_t value) throw() { _infoSyncInterval = value; }
53
54         void setUpProfileId(unsigned value) throw() { _upProfileId = value; }
55         void setDownProfileId(unsigned value) throw() { _downProfileId = value; }
56
57         void setDataURL(const std::string & value) throw() { _dataURL = value; }
58
59     private:
60         bool _isHelp;
61         bool _isVersion;
62         bool _isDebug;
63         bool _isDaemon;
64
65         std::string _configFile;
66         std::string _logFile;
67         std::string _PIDFile;
68
69         time_t _switchSyncInterval;
70         time_t _infoSyncInterval;
71
72         unsigned _upProfileId;
73         unsigned _downProfileId;
74
75         std::string _dataURL;
76
77         friend class SettingsParser;
78 };
79
80 class SettingsParser : private boost::noncopyable {
81     public:
82         SettingsParser();
83         ~SettingsParser();
84
85         void init(int argc, char * argv[]);
86         void reloadConfig();
87         void printHelp() const;
88
89         const Settings & settings() const { return _settings; };
90     private:
91         po::options_description _desc;
92         Settings _settings;
93
94         void parseFile(const std::string & fileName);
95 };
96
97 }
98
99 #include "settings.inl.h"
100
101 #endif