Introduced Logger.
[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
15 /**
16  * Default constructor which initializes the member Conf.
17  */
18 Updater::Updater()
19 {
20     // initialize Logger
21     LoggerPtr _log(new Logger);
22     Log = _log;
23
24     // initialize Config
25     ConfigPtr _config(new Config(Log));
26     Conf = _config;
27
28     Log->print_constructor_call("Updater");
29 }
30
31
32 /**
33  * Default destructor.
34  */
35 Updater::~Updater()
36 {
37     Log->print_destructor_call("Updater");
38 }
39
40
41 /**
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.
46  */
47 int Updater::init_config_from_cmd(int argc, char *argv[])
48 {
49     // Load the command line parameters
50     if( Conf->parse_cmd_line( argc, argv ) != 0)
51         return 1;
52
53     // successful parsed
54     Log->print_cmd_parsed();
55     return 0;
56 }
57
58
59 /**
60  * Load the main config and the service definition files in config path.
61  * @return 0 if all is fine, 
62  */
63 int Updater::init_config_from_files()
64 {
65     // Load the main and service config files in config path
66     if( Conf->load_config_from_files() != 0)
67         return 1;
68
69     // successful loaded
70     return 0;
71 }
72
73
74 /**
75  * Update all configured services.
76  */
77 void Updater::update_services()
78 {
79     list<ServicePtr> services = this->Conf->get_services();
80
81     string ip = "192.168.1.1";
82
83     BOOST_FOREACH( ServicePtr service, services )
84     {
85         service->update(ip);
86     }
87 }