Added bin/ to .gitignore.
[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
12#include <boost/foreach.hpp>
13
8bca3c5d 14using namespace std;
527536b3 15
b1be615b
BS
16/**
17 * Default constructor which initializes the member Conf.
18 */
4545a371
BS
19Updater::Updater()
20{
254bbf53
BS
21 // initialize Logger
22 LoggerPtr _log(new Logger);
23 Log = _log;
4545a371 24
254bbf53
BS
25 // initialize Config
26 ConfigPtr _config(new Config(Log));
27 Conf = _config;
527536b3 28
254bbf53 29 Log->print_constructor_call("Updater");
4545a371
BS
30}
31
527536b3 32
b1be615b
BS
33/**
34 * Default destructor.
35 */
4545a371
BS
36Updater::~Updater()
37{
254bbf53 38 Log->print_destructor_call("Updater");
4545a371
BS
39}
40
527536b3 41
b1be615b 42/**
254bbf53
BS
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.
38060291 47 */
254bbf53 48int Updater::init_config_from_cmd(int argc, char *argv[])
38060291
BS
49{
50 // Load the command line parameters
254bbf53
BS
51 if( Conf->parse_cmd_line( argc, argv ) != 0)
52 return 1;
38060291 53
254bbf53
BS
54 // successful parsed
55 Log->print_cmd_parsed();
38060291
BS
56 return 0;
57}
58
59
60/**
254bbf53
BS
61 * Load the main config and the service definition files in config path.
62 * @return 0 if all is fine,
b1be615b 63 */
254bbf53 64int Updater::init_config_from_files()
4545a371 65{
254bbf53
BS
66 // Load the main and service config files in config path
67 if( Conf->load_config_from_files() != 0)
68 return 1;
4545a371 69
254bbf53
BS
70 // successful loaded
71 return 0;
4545a371
BS
72}
73
527536b3 74
b1be615b 75/**
3434b35f
BS
76 * Getter for member Config.
77 * @return Member Config.
78 */
79ConfigPtr Updater::get_config()
80{
81 return Conf;
82}
83
84
85/**
86 * Getter for member Logger.
87 * @return Member Logger.
88 */
89LoggerPtr Updater::get_logger()
90{
91 return Log;
92}
93
94
95/**
c5675c01
BS
96 * Reloading the config. Delete all Service objects and then init new Service objects from config files.
97 */
98void Updater::reload_config()
99{
8bca3c5d 100 // delete all service objects
c5675c01 101 Conf->delete_services();
8bca3c5d
BS
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
c5675c01 107 init_config_from_files();
8bca3c5d
BS
108
109 // re_init log facility, perhaps new config file options for logger are set.
110 init_log_facility();
111}
112
113
114void Updater::init_log_facility()
115{
116 Log->set_log_facility(Conf->get_loglevel(),Conf->get_syslog());
117 Log->print_init_log_facility();
c5675c01
BS
118}
119
120
121/**
b1be615b
BS
122 * Update all configured services.
123 */
4545a371
BS
124void Updater::update_services()
125{
85a0abf9 126 list<ServicePtr> services = this->Conf->get_services();
4545a371
BS
127
128 string ip = "192.168.1.1";
129
85a0abf9 130 BOOST_FOREACH( ServicePtr service, services )
4545a371
BS
131 {
132 service->update(ip);
133 }
b1be615b 134}