Removed using of namespaces from header files.
[bpdyndnsd] / src / updater.cpp
1 /** @file
2  * @brief The updater class implementation. This class implements the updater logic.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #include "updater.h"
11
12 #include <boost/foreach.hpp>
13
14 using namespace std;
15
16 /**
17  * Default constructor which initializes the member Conf.
18  */
19 Updater::Updater()
20 {
21     // initialize Logger
22     LoggerPtr _log(new Logger);
23     Log = _log;
24
25     // initialize Config
26     ConfigPtr _config(new Config(Log));
27     Conf = _config;
28
29     Log->print_constructor_call("Updater");
30 }
31
32
33 /**
34  * Default destructor.
35  */
36 Updater::~Updater()
37 {
38     Log->print_destructor_call("Updater");
39 }
40
41
42 /**
43  * Parse the command line arguments and initialize corresponding options.
44  * @param argc Number command line arguments.
45  * @param argv[] Array with arguments.
46  * @return 0 if cmd options successfully parsed, 1 if usage or version.
47  */
48 int Updater::init_config_from_cmd(int argc, char *argv[])
49 {
50     // Load the command line parameters
51     if( Conf->parse_cmd_line( argc, argv ) != 0)
52         return 1;
53
54     // successful parsed
55     Log->print_cmd_parsed();
56     return 0;
57 }
58
59
60 /**
61  * Load the main config and the service definition files in config path.
62  * @return 0 if all is fine, 
63  */
64 int Updater::init_config_from_files()
65 {
66     // Load the main and service config files in config path
67     if( Conf->load_config_from_files() != 0)
68         return 1;
69
70     // successful loaded
71     return 0;
72 }
73
74
75 /**
76  * Getter for member Config.
77  * @return Member Config.
78  */
79 ConfigPtr Updater::get_config()
80 {
81     return Conf;
82 }
83
84
85 /**
86  * Getter for member Logger.
87  * @return Member Logger.
88  */
89 LoggerPtr Updater::get_logger()
90 {
91     return Log;
92 }
93
94
95 /**
96  * Reloading the config. Delete all Service objects and then init new Service objects from config files.
97  */
98 void Updater::reload_config()
99 {
100     // delete all service objects
101     Conf->delete_services();
102
103     // delete the actual Variables_map, perhaps with old cmd options which would overwrite new config file options.
104     Conf->delete_variables_map();
105
106     // load only config files
107     init_config_from_files();
108
109     // re_init log facility, perhaps new config file options for logger are set.
110     init_log_facility();
111 }
112
113
114 void Updater::init_log_facility()
115 {
116     Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
117     Log->print_init_log_facility();
118 }
119
120
121 /**
122  * Update all configured services.
123  */
124 void Updater::update_services()
125 {
126     list<ServicePtr> services = this->Conf->get_services();
127
128     string ip = "192.168.1.1";
129
130     BOOST_FOREACH( ServicePtr service, services )
131     {
132         service->update(ip);
133     }
134 }