Commit | Line | Data |
---|---|---|
b1be615b | 1 | /** @file |
2bc1878a | 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 | #include "service.h" |
11 | ||
2bc1878a | 12 | |
85a0abf9 BS |
13 | /** |
14 | * Default Constructor | |
15 | */ | |
4545a371 | 16 | Service::Service() |
27baf279 BS |
17 | : Protocol("") |
18 | , Hostname("") | |
19 | , Login("NOT SERIALIZED") | |
20 | , Password("NOT SERIALIZED") | |
025abebb | 21 | , ActualIP("0.0.0.0") |
2e956a36 BS |
22 | , Lastupdated(0) |
23 | , Log(new Logger()) | |
4545a371 BS |
24 | { |
25 | } | |
26 | ||
2bc1878a | 27 | |
85a0abf9 | 28 | /** |
27baf279 | 29 | * Default Destructor needed for deserialization. |
85a0abf9 | 30 | */ |
4545a371 BS |
31 | Service::~Service() |
32 | { | |
33 | } | |
34 | ||
35 | ||
2bc1878a BS |
36 | /** |
37 | * Although this is an abstract class, we need the serialize function that we can serialize derived classes through a Service *. | |
38 | * @param ar Archive. | |
39 | * @param version Version. | |
40 | */ | |
41 | template<class Archive> | |
42 | void Service::serialize(Archive & ar, const unsigned int version) | |
43 | { | |
3a89ac31 BS |
44 | // protocol and hostname are the unique identifier for each service. |
45 | ar & Protocol; | |
46 | ar & Hostname; | |
27baf279 | 47 | // lastupdated and actual_ip must also be serialized, cause these are essential infos of each service. |
2bc1878a | 48 | ar & Lastupdated; |
025abebb | 49 | ar & ActualIP; |
3a89ac31 BS |
50 | } |
51 | ||
52 | ||
53 | /** | |
54 | * Setter for member Protocol. | |
55 | * @param _protocol Value to set Protocol to. | |
56 | */ | |
57 | void Service::set_protocol(const string& _protocol) | |
58 | { | |
59 | Protocol = _protocol; | |
60 | } | |
61 | ||
62 | ||
63 | /** | |
64 | * Getter for memeber Protocol. | |
65 | * @return Value of member Protocol. | |
66 | */ | |
b38684ce | 67 | string Service::get_protocol() const |
3a89ac31 BS |
68 | { |
69 | return Protocol; | |
70 | } | |
71 | ||
72 | ||
73 | /** | |
74 | * Setter for member Hostname. | |
75 | * @param _hostname Value to set Hostname to. | |
76 | */ | |
77 | void Service::set_hostname(const string& _hostname) | |
78 | { | |
79 | Hostname = _hostname; | |
80 | } | |
81 | ||
82 | ||
83 | /** | |
84 | * Getter for member Hostname. | |
85 | * @return Value of member Hostname. | |
86 | */ | |
b38684ce | 87 | string Service::get_hostname() const |
3a89ac31 BS |
88 | { |
89 | return Hostname; | |
90 | } | |
91 | ||
92 | ||
93 | /** | |
94 | * Setter for member Login. | |
95 | * @param _login Value to set Login to. | |
96 | */ | |
97 | void Service::set_login(const string& _login) | |
98 | { | |
99 | Login = _login; | |
100 | } | |
101 | ||
102 | ||
103 | /** | |
104 | * Getter for member Login. | |
105 | * @return Value of member Login. | |
106 | */ | |
b38684ce | 107 | string Service::get_login() const |
3a89ac31 BS |
108 | { |
109 | return Login; | |
110 | } | |
111 | ||
112 | ||
113 | /** | |
114 | * Setter for member Password. | |
115 | * @param _password Value to set Password to. | |
116 | */ | |
117 | void Service::set_password(const string& _password) | |
118 | { | |
119 | Password = _password; | |
120 | } | |
121 | ||
122 | ||
123 | /** | |
124 | * Getter for member Password. | |
125 | * @return Value of member Password. | |
126 | */ | |
b38684ce | 127 | string Service::get_password() const |
3a89ac31 BS |
128 | { |
129 | return Password; | |
130 | } | |
131 | ||
132 | ||
133 | /** | |
134 | * Setter for member Log. | |
135 | * @param _log Shared pointer to Logger object. | |
136 | */ | |
88a594e8 | 137 | void Service::set_logger(const Logger::Ptr& _log) |
3a89ac31 BS |
138 | { |
139 | Log = _log; | |
140 | } | |
141 | ||
142 | ||
143 | /** | |
144 | * Getter for member Log. | |
145 | * @return Shared pointer to Logger object. | |
146 | */ | |
b38684ce | 147 | Logger::Ptr Service::get_logger() const |
3a89ac31 BS |
148 | { |
149 | return Log; | |
2bc1878a BS |
150 | } |
151 | ||
152 | ||
153 | /** | |
154 | * Setter for member Lastupdated. | |
155 | * @param _lastupdated Value to set Lastupdated to. | |
156 | */ | |
157 | void Service::set_lastupdated(const int _lastupdated) | |
158 | { | |
159 | Lastupdated = _lastupdated; | |
160 | } | |
161 | ||
162 | ||
163 | /** | |
164 | * Getter for member Lastupdated. | |
165 | * @return Value of member Lastupdated. | |
166 | */ | |
b38684ce | 167 | int Service::get_lastupdated() const |
2bc1878a BS |
168 | { |
169 | return Lastupdated; | |
170 | } | |
171 | ||
172 | ||
173 | /** | |
025abebb BS |
174 | * Setter for member ActualIP. |
175 | * @param _actual_ip Value to set ActualIP to. | |
27baf279 BS |
176 | */ |
177 | void Service::set_actual_ip(const std::string& _actual_ip) | |
178 | { | |
025abebb | 179 | ActualIP = _actual_ip; |
27baf279 BS |
180 | } |
181 | ||
182 | ||
183 | /** | |
025abebb BS |
184 | * Getter for member ActualIP. |
185 | * @return Value of member ActualIP. | |
27baf279 | 186 | */ |
b38684ce | 187 | std::string Service::get_actual_ip() const |
27baf279 | 188 | { |
025abebb | 189 | return ActualIP; |
27baf279 BS |
190 | } |
191 | ||
192 | ||
193 | ||
194 | /** | |
3a89ac31 BS |
195 | * Overloading of comparison operator. |
196 | * @param other Reference to other Service object. | |
197 | * @return True if they equal, false if not. | |
2bc1878a | 198 | */ |
3a89ac31 | 199 | bool Service::operator== (const Service& other) const |
2bc1878a | 200 | { |
3a89ac31 BS |
201 | if ( ( this->Protocol == other.Protocol ) && ( this->Hostname == other.Hostname ) ) |
202 | return true; | |
203 | return false; | |
2bc1878a BS |
204 | } |
205 | ||
206 | ||
207 | /** | |
3a89ac31 BS |
208 | * Overloading of disparate operator. |
209 | * @param other Reference to other Service object. | |
210 | * @return True if they differ, false if they are equal. | |
2bc1878a | 211 | */ |
3a89ac31 | 212 | bool Service::operator!= (const Service& other) const |
2bc1878a | 213 | { |
3a89ac31 | 214 | return !(*this == other); |
2bc1878a | 215 | } |