e0410f13b1a133b9494f7532de50afe0ef621869
[bpdyndnsd] / src / service.hpp
1 /** @file
2  * @brief The abstract service class. This class represents all services.
3  *
4  *
5  *
6  * @copyright Intra2net AG
7  * @license GPLv2
8 */
9
10 #ifndef SERVICE_H
11 #define SERVICE_H
12
13 #include "logger.hpp"
14
15 #include <boost/archive/text_oarchive.hpp>
16 #include <boost/archive/text_iarchive.hpp>
17
18 #include <boost/shared_ptr.hpp>
19 #include <string>
20 #include <list>
21
22
23 class Service
24 {
25
26 private:
27
28     std::string Protocol;
29     std::string Hostname;
30
31     std::string Login;
32     std::string Password;
33
34     std::string ActualIP;
35
36     int UpdateInterval;
37     int MaxUpdatesWithinInterval;
38     int MaxEqualUpdatesInSuccession;
39     int DNSCacheTTL;
40
41     std::map<time_t,std::string> LastUpdates;
42
43     int ErrorCount;
44     time_t ErrorServiceBlockedUntil;
45
46     friend class boost::serialization::access;
47     template<class Archive>
48     void serialize(Archive & ar, const unsigned int version)
49     {
50         // protocol and hostname are the unique identifier for each service.
51         ar & Protocol;
52         ar & Hostname;
53         // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service.
54         ar & LastUpdates;
55         ar & ActualIP;
56         ar & UpdateInterval;
57         ar & MaxUpdatesWithinInterval;
58         ar & MaxEqualUpdatesInSuccession;
59         ar & DNSCacheTTL;
60     }
61
62     Logger::Ptr Log;
63
64 public:
65
66     typedef boost::shared_ptr<Service> Ptr;
67
68     Service();
69
70     virtual ~Service();
71
72     virtual int perform_update(const std::string& ip) = 0;
73
74     void update(const std::string& ip, const time_t current_time, bool changed_to_online);
75
76     bool update_allowed(const time_t current_time, bool changed_to_online);
77
78     void set_last_update(const time_t current_time, const std::string& ip);
79
80     time_t get_last_update_time();
81
82     int get_update_interval()const;
83     void set_update_interval(const int _update_interval);
84
85     int get_max_updates_within_interval() const;
86     void set_max_updates_within_interval(const int _max_updates_within_interval);
87
88     int get_max_equal_updates_in_succession() const;
89     void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession);
90
91     int get_dns_cache_ttl() const;
92     void set_dns_cache_ttl(const int _dns_cache_ttl);
93
94     void set_protocol(const std::string& _protocol);
95     std::string get_protocol() const;
96
97     void set_hostname(const std::string& _hostname);
98     std::string get_hostname() const;
99
100     void set_login(const std::string& _login);
101     std::string get_login() const;
102
103     void set_password(const std::string& _password);
104     std::string get_password() const;
105
106     void set_last_updates(std::map<time_t,std::string> _last_updates);
107     const std::map<time_t,std::string> get_last_updates() const;
108
109     void set_actual_ip(const std::string& _actual_ip);
110     std::string get_actual_ip() const;
111
112     void set_logger(const Logger::Ptr& _log);
113     Logger::Ptr get_logger() const;
114
115     std::string get_service_name() const;
116
117     bool operator== (const Service& other) const;
118     bool operator!= (const Service& other) const;
119 };
120
121 #endif