Each Service has Protocol, Hostname, Login, Password, Shared_Ptr to Logging facility...
[bpdyndnsd] / src / updater.cpp
CommitLineData
b1be615b
BS
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
4545a371
BS
10#include "updater.h"
11
8bca3c5d 12using namespace std;
527536b3 13
b1be615b
BS
14/**
15 * Default constructor which initializes the member Conf.
16 */
4545a371
BS
17Updater::Updater()
18{
254bbf53
BS
19 // initialize Logger
20 LoggerPtr _log(new Logger);
21 Log = _log;
4545a371 22
254bbf53
BS
23 // initialize Config
24 ConfigPtr _config(new Config(Log));
25 Conf = _config;
527536b3 26
254bbf53 27 Log->print_constructor_call("Updater");
4545a371
BS
28}
29
527536b3 30
b1be615b
BS
31/**
32 * Default destructor.
33 */
4545a371
BS
34Updater::~Updater()
35{
254bbf53 36 Log->print_destructor_call("Updater");
4545a371
BS
37}
38
527536b3 39
b1be615b 40/**
254bbf53
BS
41 * Parse the command line arguments and initialize corresponding options.
42 * @param argc Number command line arguments.
43 * @param argv[] Array with arguments.
44 * @return 0 if cmd options successfully parsed, 1 if usage or version.
38060291 45 */
254bbf53 46int Updater::init_config_from_cmd(int argc, char *argv[])
38060291
BS
47{
48 // Load the command line parameters
254bbf53
BS
49 if( Conf->parse_cmd_line( argc, argv ) != 0)
50 return 1;
38060291 51
59c8d63c
BS
52 // If we have loaded the cmd options we need to init the log facility immediately in case debugging is enabled from cmd.
53 init_log_facility();
54
254bbf53
BS
55 // successful parsed
56 Log->print_cmd_parsed();
38060291
BS
57 return 0;
58}
59
60
61/**
254bbf53
BS
62 * Load the main config and the service definition files in config path.
63 * @return 0 if all is fine,
b1be615b 64 */
254bbf53 65int Updater::init_config_from_files()
4545a371 66{
254bbf53
BS
67 // Load the main and service config files in config path
68 if( Conf->load_config_from_files() != 0)
69 return 1;
4545a371 70
59c8d63c
BS
71 // Re-init log facility, perhaps new config file options for logger are set.
72 // These config file options will only overwrite the cmd options if the SIGHUP (reload config) is caught.
73 init_log_facility();
74
254bbf53
BS
75 // successful loaded
76 return 0;
4545a371
BS
77}
78
527536b3 79
b1be615b 80/**
3434b35f
BS
81 * Getter for member Config.
82 * @return Member Config.
83 */
84ConfigPtr Updater::get_config()
85{
86 return Conf;
87}
88
89
90/**
91 * Getter for member Logger.
92 * @return Member Logger.
93 */
94LoggerPtr Updater::get_logger()
95{
96 return Log;
97}
98
99
100/**
c5675c01
BS
101 * Reloading the config. Delete all Service objects and then init new Service objects from config files.
102 */
103void Updater::reload_config()
104{
8bca3c5d 105 // delete all service objects
c5675c01 106 Conf->delete_services();
8bca3c5d
BS
107
108 // delete the actual Variables_map, perhaps with old cmd options which would overwrite new config file options.
109 Conf->delete_variables_map();
110
111 // load only config files
c5675c01 112 init_config_from_files();
8bca3c5d
BS
113}
114
115
2bc1878a
BS
116/**
117 * Initialize the logging facility with loglevel and syslog.
118 */
8bca3c5d
BS
119void Updater::init_log_facility()
120{
121 Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
122 Log->print_init_log_facility();
c5675c01
BS
123}
124
125
126/**
b1be615b
BS
127 * Update all configured services.
128 */
4545a371
BS
129void Updater::update_services()
130{
85a0abf9 131 list<ServicePtr> services = this->Conf->get_services();
4545a371
BS
132
133 string ip = "192.168.1.1";
134
85a0abf9 135 BOOST_FOREACH( ServicePtr service, services )
4545a371
BS
136 {
137 service->update(ip);
138 }
b1be615b 139}