Use enum for perform_update() return code. Made function protected
[bpdyndnsd] / src / service.hpp
CommitLineData
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
23class Service
24{
92beaba3 25
2bc1878a 26private:
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;
4553e833 38 int MaxEqualUpdatesInSuccession;
c3dea5dc 39 int DNSCacheTTL;
3c0cd271 40
4553e833 41 std::map<time_t,std::string> LastUpdates;
2bc1878a 42
0f0908e1
TJ
43 int ErrorCount;
44 time_t ErrorServiceBlockedUntil;
45
2bc1878a
BS
46 friend class boost::serialization::access;
47 template<class Archive>
ca5d6889
BS
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;
4553e833 58 ar & MaxEqualUpdatesInSuccession;
ca5d6889
BS
59 ar & DNSCacheTTL;
60 }
2bc1878a 61
88a594e8 62 Logger::Ptr Log;
27baf279 63
d008afbe
TJ
64protected:
65
66 enum UpdateErrorCode { UpdateOk=0, GenericError=1, NoChange=2, Blocked=3 };
67 virtual UpdateErrorCode perform_update(const std::string& ip) = 0;
68
4545a371 69public:
88a594e8
BS
70
71 typedef boost::shared_ptr<Service> Ptr;
72
4545a371
BS
73 Service();
74
4248e8ca 75 virtual ~Service();
4545a371 76
0ebcd4ef 77 void update(const std::string& ip, const time_t current_time, bool changed_to_online);
c3dea5dc 78
08e6f339 79 bool update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host);
4545a371 80
4553e833
BS
81 void set_last_update(const time_t current_time, const std::string& ip);
82
83 time_t get_last_update_time();
fc613942 84
3c0cd271 85 int get_update_interval()const;
e8d4a6f8 86 void set_update_interval(const int _update_interval);
6d64d311 87
3c0cd271 88 int get_max_updates_within_interval() const;
e8d4a6f8 89 void set_max_updates_within_interval(const int _max_updates_within_interval);
b38684ce 90
4553e833
BS
91 int get_max_equal_updates_in_succession() const;
92 void set_max_equal_updates_in_succession(const int _max_equal_updates_in_succession);
93
c3dea5dc
BS
94 int get_dns_cache_ttl() const;
95 void set_dns_cache_ttl(const int _dns_cache_ttl);
96
e8d4a6f8 97 void set_protocol(const std::string& _protocol);
b38684ce 98 std::string get_protocol() const;
3a89ac31 99
e8d4a6f8 100 void set_hostname(const std::string& _hostname);
b38684ce 101 std::string get_hostname() const;
3a89ac31 102
e8d4a6f8 103 void set_login(const std::string& _login);
b38684ce 104 std::string get_login() const;
3a89ac31 105
e8d4a6f8 106 void set_password(const std::string& _password);
b38684ce 107 std::string get_password() const;
3a89ac31 108
4553e833
BS
109 void set_last_updates(std::map<time_t,std::string> _last_updates);
110 const std::map<time_t,std::string> get_last_updates() const;
2bc1878a 111
e8d4a6f8 112 void set_actual_ip(const std::string& _actual_ip);
b38684ce 113 std::string get_actual_ip() const;
27baf279 114
e8d4a6f8 115 void set_logger(const Logger::Ptr& _log);
b38684ce 116 Logger::Ptr get_logger() const;
27baf279 117
c3dea5dc 118 std::string get_service_name() const;
3c0cd271 119
e8d4a6f8
BS
120 bool operator== (const Service& other) const;
121 bool operator!= (const Service& other) const;
4545a371
BS
122};
123
124#endif