libt2n: (tomj) compile fix
[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{
1e1f17bf
GE
41/** @brief a generic exception that can be handeled with libt2n
42 @note don't derive the exceptions your application generates directly from this one
43 but use libt2n::t2n_runtime_error for this
44*/
ac7fdc22
GE
45class t2n_exception : public std::exception
46{
47 private:
0cf4dc9b 48 std::string message;
ac7fdc22
GE
49
50 friend class boost::serialization::access;
51 template<class Archive>
e453407d 52 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
53
54 public:
0cf4dc9b 55 t2n_exception(const std::string& _message)
ac7fdc22
GE
56 { message=_message; }
57
58 t2n_exception()
59 { }
60
61 virtual const char* what() const throw()
62 { return message.c_str(); }
63
64 virtual t2n_exception* clone() const
65 { return new t2n_exception(*this); }
66
67 virtual ~t2n_exception() throw()
68 {}
69
70 virtual void do_throw()
71 { throw *this; }
72};
ac7fdc22 73
04e6b271 74/// a (unspecified) problem with libt2n communication
ac7fdc22
GE
75class t2n_communication_error : public t2n_exception
76{
77 private:
78 friend class boost::serialization::access;
79 template<class Archive>
e453407d 80 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
81
82 public:
0cf4dc9b 83 t2n_communication_error(const std::string& _message)
ac7fdc22
GE
84 : t2n_exception(_message)
85 { }
86
87 t2n_communication_error()
88 { }
89
0cf4dc9b 90 t2n_exception* clone() const
ac7fdc22
GE
91 { return new t2n_communication_error(*this); }
92
93 void do_throw()
94 { throw *this; }
95};
ac7fdc22 96
04e6b271 97/// can't connect to libt2n server
ac7fdc22
GE
98class t2n_connect_error : public t2n_communication_error
99{
100 private:
101 friend class boost::serialization::access;
102 template<class Archive>
e453407d 103 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
104
105 public:
0cf4dc9b 106 t2n_connect_error(const std::string& _message)
ac7fdc22
GE
107 : t2n_communication_error(_message)
108 { }
109
110 t2n_connect_error()
111 { }
112
0cf4dc9b 113 t2n_exception* clone() const
ac7fdc22
GE
114 { return new t2n_connect_error(*this); }
115
116 void do_throw()
117 { throw *this; }
118};
ac7fdc22 119
04e6b271 120/// error establishing a socket on the server (only thrown on the server-side)
ac7fdc22
GE
121class t2n_server_error : public t2n_communication_error
122{
123 private:
124 friend class boost::serialization::access;
125 template<class Archive>
e453407d 126 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
127
128 public:
0cf4dc9b 129 t2n_server_error(const std::string& _message)
ac7fdc22
GE
130 : t2n_communication_error(_message)
131 { }
132
133 t2n_server_error()
134 { }
135
0cf4dc9b 136 t2n_exception* clone() const
ac7fdc22
GE
137 { return new t2n_server_error(*this); }
138
139 void do_throw()
140 { throw *this; }
141};
ac7fdc22 142
04e6b271 143/// error transmitting or receiving libt2n messages
ac7fdc22
GE
144class t2n_transfer_error : public t2n_communication_error
145{
146 private:
147 friend class boost::serialization::access;
148 template<class Archive>
e453407d 149 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
150
151 public:
0cf4dc9b 152 t2n_transfer_error(const std::string& _message)
ac7fdc22
GE
153 : t2n_communication_error(_message)
154 { }
155
156 t2n_transfer_error()
157 { }
158
0cf4dc9b 159 t2n_exception* clone() const
ac7fdc22
GE
160 { return new t2n_transfer_error(*this); }
161
162 void do_throw()
163 { throw *this; }
164};
ac7fdc22 165
04e6b271 166/// tried to talk to an incompatible libt2n version
ac7fdc22
GE
167class t2n_version_mismatch : public t2n_communication_error
168{
169 private:
170 friend class boost::serialization::access;
171 template<class Archive>
e453407d 172 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
173
174 public:
0cf4dc9b 175 t2n_version_mismatch(const std::string& _message)
ac7fdc22
GE
176 : t2n_communication_error(_message)
177 { }
178
179 t2n_version_mismatch()
180 { }
181
0cf4dc9b 182 t2n_exception* clone() const
ac7fdc22
GE
183 { return new t2n_version_mismatch(*this); }
184
185 void do_throw()
186 { throw *this; }
187};
ac7fdc22 188
04e6b271 189/// illegal libt2n command received
ac7fdc22
GE
190class t2n_command_error : public t2n_exception
191{
192 private:
193 friend class boost::serialization::access;
194 template<class Archive>
e453407d 195 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
196
197 public:
0cf4dc9b 198 t2n_command_error(const std::string& _message)
ac7fdc22
GE
199 : t2n_exception(_message)
200 { }
201
202 t2n_command_error()
203 { }
204
0cf4dc9b 205 t2n_exception* clone() const
ac7fdc22
GE
206 { return new t2n_command_error(*this); }
207
208 void do_throw()
209 { throw *this; }
210};
ac7fdc22 211
04e6b271 212/// error serializing or deserializing a libt2n command packet
ac7fdc22
GE
213class t2n_serialization_error : public t2n_exception
214{
215 private:
216 friend class boost::serialization::access;
217 template<class Archive>
e453407d 218 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
219
220 public:
0cf4dc9b 221 t2n_serialization_error(const std::string& _message)
ac7fdc22
GE
222 : t2n_exception(_message)
223 { }
224
225 t2n_serialization_error()
226 { }
227
0cf4dc9b 228 t2n_exception* clone() const
ac7fdc22
GE
229 { return new t2n_serialization_error(*this); }
230
231 void do_throw()
232 { throw *this; }
233};
ac7fdc22 234
cc68aabb 235/** @brief a runtime error within the remote function.
04e6b271 236 derive your own custom exceptions from this one
7781f1c4 237
1e1f17bf 238 @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
04e6b271 239*/
ac7fdc22
GE
240class t2n_runtime_error : public t2n_exception
241{
242 private:
243 friend class boost::serialization::access;
244 template<class Archive>
e453407d 245 void serialize(Archive & ar, const unsigned int version);
ac7fdc22
GE
246
247 public:
0cf4dc9b 248 t2n_runtime_error(const std::string& _message)
ac7fdc22
GE
249 : t2n_exception(_message)
250 { }
251
252 t2n_runtime_error()
253 { }
254
0cf4dc9b 255 t2n_exception* clone() const
ac7fdc22
GE
256 { return new t2n_runtime_error(*this); }
257
258 void do_throw()
259 { throw *this; }
260};
ac7fdc22 261
7087e187 262} // namespace libt2n
ac7fdc22
GE
263
264#endif