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 | { | |
20 | } | |
21 | ||
527536b3 | 22 | |
b1be615b BS |
23 | /** |
24 | * Constructor. | |
25 | * @param _conf A pointer to a Config object. | |
26 | */ | |
85a0abf9 | 27 | Updater::Updater(ConfigPtr _conf) |
4545a371 | 28 | { |
b1be615b | 29 | Conf = _conf; |
4545a371 BS |
30 | } |
31 | ||
527536b3 | 32 | |
b1be615b BS |
33 | /** |
34 | * Default destructor. | |
35 | */ | |
4545a371 BS |
36 | Updater::~Updater() |
37 | { | |
85a0abf9 | 38 | cout << "Updater destructor!!!" << endl; |
4545a371 BS |
39 | } |
40 | ||
527536b3 | 41 | |
b1be615b | 42 | /** |
38060291 BS |
43 | * |
44 | * @param argc | |
45 | * @param argv[] | |
46 | * @return | |
47 | */ | |
48 | const int Updater::init_config_from_cmd(int argc, char *argv[]) | |
49 | { | |
50 | // Load the command line parameters | |
51 | int ret_val = Conf->parse_cmd_line(argc,argv); | |
52 | if(ret_val == 1) | |
53 | { | |
54 | // usage | |
55 | Conf->print_usage(); | |
56 | return ret_val; | |
57 | } | |
58 | else if(ret_val == 2) | |
59 | { | |
60 | // version | |
61 | ostringstream version_string; | |
62 | version_string << VERSION << "." << REVISION << "." << RELEASE; | |
63 | Conf->print_version(version_string.str()); | |
64 | return ret_val; | |
65 | } | |
66 | // successful parsed | |
67 | Conf->print_cmd_parsed(); | |
68 | return 0; | |
69 | } | |
70 | ||
71 | const int Updater::init_config_from_files() | |
72 | { | |
73 | // Load the main config and the service files | |
74 | string config_path = "/home/bjoern/bpdyndnsd"; // TODO: standard config path should be /etc/bpdyndnsd if not specified other on command line | |
75 | int ret_val = Conf->load_config_from_files(config_path); | |
76 | if(ret_val == 3) | |
77 | { | |
78 | // unknown option | |
79 | Conf->print_unknown_conf_option(); | |
80 | return ret_val; | |
81 | } | |
82 | else if(ret_val == 4) | |
83 | { | |
84 | // error opening | |
85 | Conf->print_error_opening(); | |
86 | return ret_val; | |
87 | } | |
88 | // successful loaded | |
89 | Conf->print_conf_loaded(); | |
90 | return 0; | |
91 | } | |
92 | ||
93 | ||
94 | /** | |
b1be615b BS |
95 | * Setter for member Conf. |
96 | * @param _conf | |
97 | */ | |
85a0abf9 | 98 | void Updater::set_config(ConfigPtr _conf) |
4545a371 | 99 | { |
b1be615b | 100 | Conf = _conf; |
4545a371 BS |
101 | } |
102 | ||
527536b3 | 103 | |
b1be615b BS |
104 | /** |
105 | * Getter for member Conf. | |
106 | * @return Conf. | |
107 | */ | |
85a0abf9 | 108 | ConfigPtr Updater::get_config() |
4545a371 | 109 | { |
b1be615b | 110 | return Conf; |
4545a371 BS |
111 | } |
112 | ||
527536b3 | 113 | |
b1be615b BS |
114 | /** |
115 | * Update all configured services. | |
116 | */ | |
4545a371 BS |
117 | void Updater::update_services() |
118 | { | |
85a0abf9 | 119 | list<ServicePtr> services = this->Conf->get_services(); |
4545a371 BS |
120 | |
121 | string ip = "192.168.1.1"; | |
122 | ||
85a0abf9 | 123 | BOOST_FOREACH( ServicePtr service, services ) |
4545a371 BS |
124 | { |
125 | service->update(ip); | |
126 | } | |
b1be615b | 127 | } |