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