Moved some logic out of main into updater.
[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 }
21
22
23 /**
24  * Constructor.
25  * @param _conf A pointer to a Config object.
26  */
27 Updater::Updater(ConfigPtr _conf)
28 {
29     Conf = _conf;
30 }
31
32
33 /**
34  * Default destructor.
35  */
36 Updater::~Updater()
37 {
38     cout << "Updater destructor!!!" << endl;
39 }
40
41
42 /**
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 /**
95  * Setter for member Conf.
96  * @param _conf
97  */
98 void Updater::set_config(ConfigPtr _conf)
99 {
100     Conf = _conf;
101 }
102
103
104 /**
105  * Getter for member Conf.
106  * @return Conf.
107  */
108 ConfigPtr Updater::get_config()
109 {
110     return Conf;
111 }
112
113
114 /**
115  * Update all configured services.
116  */
117 void Updater::update_services()
118 {
119     list<ServicePtr> services = this->Conf->get_services();
120
121     string ip = "192.168.1.1";
122
123     BOOST_FOREACH( ServicePtr service, services )
124     {
125         service->update(ip);
126     }
127 }