Commit | Line | Data |
---|---|---|
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 |
18 | Updater::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 |
35 | Updater::~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 | 47 | int 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 | 63 | int 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 BS |
74 | /** |
75 | * Update all configured services. | |
76 | */ | |
4545a371 BS |
77 | void Updater::update_services() |
78 | { | |
85a0abf9 | 79 | list<ServicePtr> services = this->Conf->get_services(); |
4545a371 BS |
80 | |
81 | string ip = "192.168.1.1"; | |
82 | ||
85a0abf9 | 83 | BOOST_FOREACH( ServicePtr service, services ) |
4545a371 BS |
84 | { |
85 | service->update(ip); | |
86 | } | |
b1be615b | 87 | } |