Switch time() calls to monotonic clock calls (#7597)
[libt2n] / src / t2n_exception.hxx
CommitLineData
19facd85
TJ
1/*
2Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
3
4The software in this package is distributed under the GNU General
5Public License version 2 (with a special exception described below).
6
7A copy of GNU General Public License (GPL) is included in this distribution,
8in the file COPYING.GPL.
9
10As a special exception, if other files instantiate templates or use macros
11or inline functions from this file, or you compile this file and link it
12with other works to produce a work based on this file, this file
13does not by itself cause the resulting work to be covered
14by the GNU General Public License.
15
16However the source code for this file must still be made available
17in accordance with section (3) of the GNU General Public License.
18
19This exception does not invalidate any other reasons why a work based
20on this file might be covered by the GNU General Public License.
21*/
ac7fdc22
GE
22#ifndef __LIBT2N_T2N_EXCEPTION
23#define __LIBT2N_T2N_EXCEPTION
24
25#include <stdexcept>
26#include <string>
27
0cf4dc9b 28#include <boost/serialization/serialization.hpp>
ac7fdc22 29
ac7fdc22
GE
30namespace boost {
31namespace serialization {
32
7087e187 33// make std::exception serializable
ac7fdc22
GE
34template<class Archive>
35void serialize(Archive & ar, std::exception & g, const unsigned int version)
36{
37}
38
39} // namespace serialization
40} // namespace boost
41
42namespace libt2n
43{
1e1f17bf
GE
44/** @brief a generic exception that can be handeled with libt2n
45 @note don't derive the exceptions your application generates directly from this one
46 but use libt2n::t2n_runtime_error for this
47*/
ac7fdc22
GE
48class t2n_exception : public std::exception
49{
50 private:
0cf4dc9b 51 std::string message;
ac7fdc22
GE
52
53 friend class boost::serialization::access;
54 template<class Archive>
e453407d 55 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
56
57 public:
0cf4dc9b 58 t2n_exception(const std::string& _message)
ac7fdc22
GE
59 { message=_message; }
60
61 t2n_exception()
62 { }
63
64 virtual const char* what() const throw()
65 { return message.c_str(); }
66
67 virtual t2n_exception* clone() const
68 { return new t2n_exception(*this); }
69
70 virtual ~t2n_exception() throw()
71 {}
72
73 virtual void do_throw()
74 { throw *this; }
75};
ac7fdc22 76
04e6b271 77/// a (unspecified) problem with libt2n communication
ac7fdc22
GE
78class t2n_communication_error : public t2n_exception
79{
80 private:
81 friend class boost::serialization::access;
82 template<class Archive>
e453407d 83 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
84
85 public:
0cf4dc9b 86 t2n_communication_error(const std::string& _message)
ac7fdc22
GE
87 : t2n_exception(_message)
88 { }
89
90 t2n_communication_error()
91 { }
92
0cf4dc9b 93 t2n_exception* clone() const
ac7fdc22
GE
94 { return new t2n_communication_error(*this); }
95
96 void do_throw()
97 { throw *this; }
98};
ac7fdc22 99
04e6b271 100/// can't connect to libt2n server
ac7fdc22
GE
101class t2n_connect_error : public t2n_communication_error
102{
103 private:
104 friend class boost::serialization::access;
105 template<class Archive>
e453407d 106 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
107
108 public:
0cf4dc9b 109 t2n_connect_error(const std::string& _message)
ac7fdc22
GE
110 : t2n_communication_error(_message)
111 { }
112
113 t2n_connect_error()
114 { }
115
0cf4dc9b 116 t2n_exception* clone() const
ac7fdc22
GE
117 { return new t2n_connect_error(*this); }
118
119 void do_throw()
120 { throw *this; }
121};
ac7fdc22 122
04e6b271 123/// error establishing a socket on the server (only thrown on the server-side)
ac7fdc22
GE
124class t2n_server_error : public t2n_communication_error
125{
126 private:
127 friend class boost::serialization::access;
128 template<class Archive>
e453407d 129 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
130
131 public:
0cf4dc9b 132 t2n_server_error(const std::string& _message)
ac7fdc22
GE
133 : t2n_communication_error(_message)
134 { }
135
136 t2n_server_error()
137 { }
138
0cf4dc9b 139 t2n_exception* clone() const
ac7fdc22
GE
140 { return new t2n_server_error(*this); }
141
142 void do_throw()
143 { throw *this; }
144};
ac7fdc22 145
04e6b271 146/// error transmitting or receiving libt2n messages
ac7fdc22
GE
147class t2n_transfer_error : public t2n_communication_error
148{
149 private:
150 friend class boost::serialization::access;
151 template<class Archive>
e453407d 152 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
153
154 public:
0cf4dc9b 155 t2n_transfer_error(const std::string& _message)
ac7fdc22
GE
156 : t2n_communication_error(_message)
157 { }
158
159 t2n_transfer_error()
160 { }
161
0cf4dc9b 162 t2n_exception* clone() const
ac7fdc22
GE
163 { return new t2n_transfer_error(*this); }
164
165 void do_throw()
166 { throw *this; }
167};
ac7fdc22 168
04e6b271 169/// tried to talk to an incompatible libt2n version
ac7fdc22
GE
170class t2n_version_mismatch : public t2n_communication_error
171{
172 private:
173 friend class boost::serialization::access;
174 template<class Archive>
e453407d 175 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
176
177 public:
0cf4dc9b 178 t2n_version_mismatch(const std::string& _message)
ac7fdc22
GE
179 : t2n_communication_error(_message)
180 { }
181
182 t2n_version_mismatch()
183 { }
184
0cf4dc9b 185 t2n_exception* clone() const
ac7fdc22
GE
186 { return new t2n_version_mismatch(*this); }
187
188 void do_throw()
189 { throw *this; }
190};
ac7fdc22 191
04e6b271 192/// illegal libt2n command received
ac7fdc22
GE
193class t2n_command_error : public t2n_exception
194{
195 private:
196 friend class boost::serialization::access;
197 template<class Archive>
e453407d 198 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
199
200 public:
0cf4dc9b 201 t2n_command_error(const std::string& _message)
ac7fdc22
GE
202 : t2n_exception(_message)
203 { }
204
205 t2n_command_error()
206 { }
207
0cf4dc9b 208 t2n_exception* clone() const
ac7fdc22
GE
209 { return new t2n_command_error(*this); }
210
211 void do_throw()
212 { throw *this; }
213};
ac7fdc22 214
04e6b271 215/// error serializing or deserializing a libt2n command packet
ac7fdc22
GE
216class t2n_serialization_error : public t2n_exception
217{
218 private:
219 friend class boost::serialization::access;
220 template<class Archive>
e453407d 221 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
222
223 public:
0cf4dc9b 224 t2n_serialization_error(const std::string& _message)
ac7fdc22
GE
225 : t2n_exception(_message)
226 { }
227
228 t2n_serialization_error()
229 { }
230
0cf4dc9b 231 t2n_exception* clone() const
ac7fdc22
GE
232 { return new t2n_serialization_error(*this); }
233
234 void do_throw()
235 { throw *this; }
236};
ac7fdc22 237
cc68aabb 238/** @brief a runtime error within the remote function.
04e6b271 239 derive your own custom exceptions from this one
7781f1c4 240
1e1f17bf 241 @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
04e6b271 242*/
ac7fdc22
GE
243class t2n_runtime_error : public t2n_exception
244{
245 private:
246 friend class boost::serialization::access;
247 template<class Archive>
e453407d 248 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
249
250 public:
0cf4dc9b 251 t2n_runtime_error(const std::string& _message)
ac7fdc22
GE
252 : t2n_exception(_message)
253 { }
254
255 t2n_runtime_error()
256 { }
257
0cf4dc9b 258 t2n_exception* clone() const
ac7fdc22
GE
259 { return new t2n_runtime_error(*this); }
260
261 void do_throw()
262 { throw *this; }
263};
ac7fdc22 264
7087e187 265} // namespace libt2n
ac7fdc22 266
d2cb39bb
RP
267#include "t2n_exception.tcc"
268
ac7fdc22 269#endif