Fix test for valid pointer after conversion to boost::smart_ptr (The class defines...
[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
527536b3 14
b1be615b
BS
15/**
16 * Default constructor which initializes the member Conf.
17 */
4545a371
BS
18Updater::Updater()
19{
254bbf53
BS
20 // initialize Logger
21 LoggerPtr _log(new Logger);
22 Log = _log;
4545a371 23
254bbf53
BS
24 // initialize Config
25 ConfigPtr _config(new Config(Log));
26 Conf = _config;
527536b3 27
254bbf53 28 Log->print_constructor_call("Updater");
4545a371
BS
29}
30
527536b3 31
b1be615b
BS
32/**
33 * Default destructor.
34 */
4545a371
BS
35Updater::~Updater()
36{
254bbf53 37 Log->print_destructor_call("Updater");
4545a371
BS
38}
39
527536b3 40
b1be615b 41/**
254bbf53
BS
42 * Parse the command line arguments and initialize corresponding options.
43 * @param argc Number command line arguments.
44 * @param argv[] Array with arguments.
45 * @return 0 if cmd options successfully parsed, 1 if usage or version.
38060291 46 */
254bbf53 47int Updater::init_config_from_cmd(int argc, char *argv[])
38060291
BS
48{
49 // Load the command line parameters
254bbf53
BS
50 if( Conf->parse_cmd_line( argc, argv ) != 0)
51 return 1;
38060291 52
254bbf53
BS
53 // successful parsed
54 Log->print_cmd_parsed();
38060291
BS
55 return 0;
56}
57
58
59/**
254bbf53
BS
60 * Load the main config and the service definition files in config path.
61 * @return 0 if all is fine,
b1be615b 62 */
254bbf53 63int Updater::init_config_from_files()
4545a371 64{
254bbf53
BS
65 // Load the main and service config files in config path
66 if( Conf->load_config_from_files() != 0)
67 return 1;
4545a371 68
254bbf53
BS
69 // successful loaded
70 return 0;
4545a371
BS
71}
72
527536b3 73
b1be615b 74/**
3434b35f
BS
75 * Getter for member Config.
76 * @return Member Config.
77 */
78ConfigPtr Updater::get_config()
79{
80 return Conf;
81}
82
83
84/**
85 * Getter for member Logger.
86 * @return Member Logger.
87 */
88LoggerPtr Updater::get_logger()
89{
90 return Log;
91}
92
93
94/**
c5675c01
BS
95 * Reloading the config. Delete all Service objects and then init new Service objects from config files.
96 */
97void Updater::reload_config()
98{
99 Conf->delete_services();
100 init_config_from_files();
101}
102
103
104/**
b1be615b
BS
105 * Update all configured services.
106 */
4545a371
BS
107void Updater::update_services()
108{
85a0abf9 109 list<ServicePtr> services = this->Conf->get_services();
4545a371
BS
110
111 string ip = "192.168.1.1";
112
85a0abf9 113 BOOST_FOREACH( ServicePtr service, services )
4545a371
BS
114 {
115 service->update(ip);
116 }
b1be615b 117}