libt2n: (gerd) finish server callbacks
[libt2n] / src / t2n_exception.hxx
CommitLineData
ac7fdc22
GE
1/***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
3 * gve@intra2net.com *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19#ifndef __LIBT2N_T2N_EXCEPTION
20#define __LIBT2N_T2N_EXCEPTION
21
22#include <stdexcept>
23#include <string>
24
0cf4dc9b 25#include <boost/serialization/serialization.hpp>
ac7fdc22 26
ac7fdc22
GE
27namespace boost {
28namespace serialization {
29
7087e187 30// make std::exception serializable
ac7fdc22
GE
31template<class Archive>
32void serialize(Archive & ar, std::exception & g, const unsigned int version)
33{
34}
35
36} // namespace serialization
37} // namespace boost
38
39namespace libt2n
40{
04e6b271 41/// a generic exception that can be handeled with libt2n
ac7fdc22
GE
42class t2n_exception : public std::exception
43{
44 private:
0cf4dc9b 45 std::string message;
ac7fdc22
GE
46
47 friend class boost::serialization::access;
48 template<class Archive>
e453407d 49 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
50
51 public:
0cf4dc9b 52 t2n_exception(const std::string& _message)
ac7fdc22
GE
53 { message=_message; }
54
55 t2n_exception()
56 { }
57
58 virtual const char* what() const throw()
59 { return message.c_str(); }
60
61 virtual t2n_exception* clone() const
62 { return new t2n_exception(*this); }
63
64 virtual ~t2n_exception() throw()
65 {}
66
67 virtual void do_throw()
68 { throw *this; }
69};
ac7fdc22 70
04e6b271 71/// a (unspecified) problem with libt2n communication
ac7fdc22
GE
72class t2n_communication_error : public t2n_exception
73{
74 private:
75 friend class boost::serialization::access;
76 template<class Archive>
e453407d 77 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
78
79 public:
0cf4dc9b 80 t2n_communication_error(const std::string& _message)
ac7fdc22
GE
81 : t2n_exception(_message)
82 { }
83
84 t2n_communication_error()
85 { }
86
0cf4dc9b 87 t2n_exception* clone() const
ac7fdc22
GE
88 { return new t2n_communication_error(*this); }
89
90 void do_throw()
91 { throw *this; }
92};
ac7fdc22 93
04e6b271 94/// can't connect to libt2n server
ac7fdc22
GE
95class t2n_connect_error : public t2n_communication_error
96{
97 private:
98 friend class boost::serialization::access;
99 template<class Archive>
e453407d 100 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
101
102 public:
0cf4dc9b 103 t2n_connect_error(const std::string& _message)
ac7fdc22
GE
104 : t2n_communication_error(_message)
105 { }
106
107 t2n_connect_error()
108 { }
109
0cf4dc9b 110 t2n_exception* clone() const
ac7fdc22
GE
111 { return new t2n_connect_error(*this); }
112
113 void do_throw()
114 { throw *this; }
115};
ac7fdc22 116
04e6b271 117/// error establishing a socket on the server (only thrown on the server-side)
ac7fdc22
GE
118class t2n_server_error : public t2n_communication_error
119{
120 private:
121 friend class boost::serialization::access;
122 template<class Archive>
e453407d 123 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
124
125 public:
0cf4dc9b 126 t2n_server_error(const std::string& _message)
ac7fdc22
GE
127 : t2n_communication_error(_message)
128 { }
129
130 t2n_server_error()
131 { }
132
0cf4dc9b 133 t2n_exception* clone() const
ac7fdc22
GE
134 { return new t2n_server_error(*this); }
135
136 void do_throw()
137 { throw *this; }
138};
ac7fdc22 139
04e6b271 140/// error transmitting or receiving libt2n messages
ac7fdc22
GE
141class t2n_transfer_error : public t2n_communication_error
142{
143 private:
144 friend class boost::serialization::access;
145 template<class Archive>
e453407d 146 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
147
148 public:
0cf4dc9b 149 t2n_transfer_error(const std::string& _message)
ac7fdc22
GE
150 : t2n_communication_error(_message)
151 { }
152
153 t2n_transfer_error()
154 { }
155
0cf4dc9b 156 t2n_exception* clone() const
ac7fdc22
GE
157 { return new t2n_transfer_error(*this); }
158
159 void do_throw()
160 { throw *this; }
161};
ac7fdc22 162
04e6b271 163/// tried to talk to an incompatible libt2n version
ac7fdc22
GE
164class t2n_version_mismatch : public t2n_communication_error
165{
166 private:
167 friend class boost::serialization::access;
168 template<class Archive>
e453407d 169 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
170
171 public:
0cf4dc9b 172 t2n_version_mismatch(const std::string& _message)
ac7fdc22
GE
173 : t2n_communication_error(_message)
174 { }
175
176 t2n_version_mismatch()
177 { }
178
0cf4dc9b 179 t2n_exception* clone() const
ac7fdc22
GE
180 { return new t2n_version_mismatch(*this); }
181
182 void do_throw()
183 { throw *this; }
184};
ac7fdc22 185
04e6b271 186/// illegal libt2n command received
ac7fdc22
GE
187class t2n_command_error : public t2n_exception
188{
189 private:
190 friend class boost::serialization::access;
191 template<class Archive>
e453407d 192 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
193
194 public:
0cf4dc9b 195 t2n_command_error(const std::string& _message)
ac7fdc22
GE
196 : t2n_exception(_message)
197 { }
198
199 t2n_command_error()
200 { }
201
0cf4dc9b 202 t2n_exception* clone() const
ac7fdc22
GE
203 { return new t2n_command_error(*this); }
204
205 void do_throw()
206 { throw *this; }
207};
ac7fdc22 208
6cda58a6
GE
209/// illegal libt2n option set
210class t2n_parameter_error : public t2n_exception
211{
212 private:
213 friend class boost::serialization::access;
214 template<class Archive>
215 void serialize(Archive & ar, const unsigned int version);
216
217 public:
218 t2n_parameter_error(const std::string& _message)
219 : t2n_exception(_message)
220 { }
221
222 t2n_parameter_error()
223 { }
224
225 t2n_exception* clone() const
226 { return new t2n_parameter_error(*this); }
227
228 void do_throw()
229 { throw *this; }
230};
231
04e6b271 232/// error serializing or deserializing a libt2n command packet
ac7fdc22
GE
233class t2n_serialization_error : public t2n_exception
234{
235 private:
236 friend class boost::serialization::access;
237 template<class Archive>
e453407d 238 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
239
240 public:
0cf4dc9b 241 t2n_serialization_error(const std::string& _message)
ac7fdc22
GE
242 : t2n_exception(_message)
243 { }
244
245 t2n_serialization_error()
246 { }
247
0cf4dc9b 248 t2n_exception* clone() const
ac7fdc22
GE
249 { return new t2n_serialization_error(*this); }
250
251 void do_throw()
252 { throw *this; }
253};
ac7fdc22 254
cc68aabb 255/** @brief a runtime error within the remote function.
04e6b271
GE
256 derive your own custom exceptions from this one
257*/
ac7fdc22
GE
258class t2n_runtime_error : public t2n_exception
259{
260 private:
261 friend class boost::serialization::access;
262 template<class Archive>
e453407d 263 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
264
265 public:
0cf4dc9b 266 t2n_runtime_error(const std::string& _message)
ac7fdc22
GE
267 : t2n_exception(_message)
268 { }
269
270 t2n_runtime_error()
271 { }
272
0cf4dc9b 273 t2n_exception* clone() const
ac7fdc22
GE
274 { return new t2n_runtime_error(*this); }
275
276 void do_throw()
277 { throw *this; }
278};
ac7fdc22 279
7087e187 280} // namespace libt2n
ac7fdc22
GE
281
282#endif