Commit | Line | Data |
---|---|---|
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 | #include <boost/serialization/export.hpp> |
ac7fdc22 GE |
27 | |
28 | // serialization for std::exception | |
29 | namespace boost { | |
30 | namespace serialization { | |
31 | ||
32 | template<class Archive> | |
33 | void serialize(Archive & ar, std::exception & g, const unsigned int version) | |
34 | { | |
35 | } | |
36 | ||
37 | } // namespace serialization | |
38 | } // namespace boost | |
39 | ||
40 | namespace libt2n | |
41 | { | |
42 | ||
04e6b271 | 43 | /// a generic exception that can be handeled with libt2n |
ac7fdc22 GE |
44 | class t2n_exception : public std::exception |
45 | { | |
46 | private: | |
0cf4dc9b | 47 | std::string message; |
ac7fdc22 GE |
48 | |
49 | friend class boost::serialization::access; | |
50 | template<class Archive> | |
51 | void serialize(Archive & ar, const unsigned int version) | |
52 | { | |
53 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception); | |
54 | ar & BOOST_SERIALIZATION_NVP(message); | |
55 | } | |
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 | }; | |
76 | BOOST_CLASS_EXPORT(t2n_exception) | |
77 | ||
04e6b271 | 78 | /// a (unspecified) problem with libt2n communication |
ac7fdc22 GE |
79 | class t2n_communication_error : public t2n_exception |
80 | { | |
81 | private: | |
82 | friend class boost::serialization::access; | |
83 | template<class Archive> | |
84 | void serialize(Archive & ar, const unsigned int version) | |
85 | { | |
86 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception); | |
87 | } | |
88 | ||
89 | public: | |
0cf4dc9b | 90 | t2n_communication_error(const std::string& _message) |
ac7fdc22 GE |
91 | : t2n_exception(_message) |
92 | { } | |
93 | ||
94 | t2n_communication_error() | |
95 | { } | |
96 | ||
0cf4dc9b | 97 | t2n_exception* clone() const |
ac7fdc22 GE |
98 | { return new t2n_communication_error(*this); } |
99 | ||
100 | void do_throw() | |
101 | { throw *this; } | |
102 | }; | |
103 | BOOST_CLASS_EXPORT(t2n_communication_error) | |
104 | ||
04e6b271 | 105 | /// can't connect to libt2n server |
ac7fdc22 GE |
106 | class t2n_connect_error : public t2n_communication_error |
107 | { | |
108 | private: | |
109 | friend class boost::serialization::access; | |
110 | template<class Archive> | |
111 | void serialize(Archive & ar, const unsigned int version) | |
112 | { | |
113 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error); | |
114 | } | |
115 | ||
116 | public: | |
0cf4dc9b | 117 | t2n_connect_error(const std::string& _message) |
ac7fdc22 GE |
118 | : t2n_communication_error(_message) |
119 | { } | |
120 | ||
121 | t2n_connect_error() | |
122 | { } | |
123 | ||
0cf4dc9b | 124 | t2n_exception* clone() const |
ac7fdc22 GE |
125 | { return new t2n_connect_error(*this); } |
126 | ||
127 | void do_throw() | |
128 | { throw *this; } | |
129 | }; | |
130 | BOOST_CLASS_EXPORT(t2n_connect_error) | |
131 | ||
04e6b271 | 132 | /// error establishing a socket on the server (only thrown on the server-side) |
ac7fdc22 GE |
133 | class t2n_server_error : public t2n_communication_error |
134 | { | |
135 | private: | |
136 | friend class boost::serialization::access; | |
137 | template<class Archive> | |
138 | void serialize(Archive & ar, const unsigned int version) | |
139 | { | |
140 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error); | |
141 | } | |
142 | ||
143 | public: | |
0cf4dc9b | 144 | t2n_server_error(const std::string& _message) |
ac7fdc22 GE |
145 | : t2n_communication_error(_message) |
146 | { } | |
147 | ||
148 | t2n_server_error() | |
149 | { } | |
150 | ||
0cf4dc9b | 151 | t2n_exception* clone() const |
ac7fdc22 GE |
152 | { return new t2n_server_error(*this); } |
153 | ||
154 | void do_throw() | |
155 | { throw *this; } | |
156 | }; | |
157 | BOOST_CLASS_EXPORT(t2n_server_error) | |
158 | ||
04e6b271 | 159 | /// error transmitting or receiving libt2n messages |
ac7fdc22 GE |
160 | class t2n_transfer_error : public t2n_communication_error |
161 | { | |
162 | private: | |
163 | friend class boost::serialization::access; | |
164 | template<class Archive> | |
165 | void serialize(Archive & ar, const unsigned int version) | |
166 | { | |
167 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error); | |
168 | } | |
169 | ||
170 | public: | |
0cf4dc9b | 171 | t2n_transfer_error(const std::string& _message) |
ac7fdc22 GE |
172 | : t2n_communication_error(_message) |
173 | { } | |
174 | ||
175 | t2n_transfer_error() | |
176 | { } | |
177 | ||
0cf4dc9b | 178 | t2n_exception* clone() const |
ac7fdc22 GE |
179 | { return new t2n_transfer_error(*this); } |
180 | ||
181 | void do_throw() | |
182 | { throw *this; } | |
183 | }; | |
184 | BOOST_CLASS_EXPORT(t2n_transfer_error) | |
185 | ||
04e6b271 | 186 | /// tried to talk to an incompatible libt2n version |
ac7fdc22 GE |
187 | class t2n_version_mismatch : public t2n_communication_error |
188 | { | |
189 | private: | |
190 | friend class boost::serialization::access; | |
191 | template<class Archive> | |
192 | void serialize(Archive & ar, const unsigned int version) | |
193 | { | |
194 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error); | |
195 | } | |
196 | ||
197 | public: | |
0cf4dc9b | 198 | t2n_version_mismatch(const std::string& _message) |
ac7fdc22 GE |
199 | : t2n_communication_error(_message) |
200 | { } | |
201 | ||
202 | t2n_version_mismatch() | |
203 | { } | |
204 | ||
0cf4dc9b | 205 | t2n_exception* clone() const |
ac7fdc22 GE |
206 | { return new t2n_version_mismatch(*this); } |
207 | ||
208 | void do_throw() | |
209 | { throw *this; } | |
210 | }; | |
211 | BOOST_CLASS_EXPORT(t2n_version_mismatch) | |
212 | ||
04e6b271 | 213 | /// illegal libt2n command received |
ac7fdc22 GE |
214 | class t2n_command_error : public t2n_exception |
215 | { | |
216 | private: | |
217 | friend class boost::serialization::access; | |
218 | template<class Archive> | |
219 | void serialize(Archive & ar, const unsigned int version) | |
220 | { | |
221 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception); | |
222 | } | |
223 | ||
224 | public: | |
0cf4dc9b | 225 | t2n_command_error(const std::string& _message) |
ac7fdc22 GE |
226 | : t2n_exception(_message) |
227 | { } | |
228 | ||
229 | t2n_command_error() | |
230 | { } | |
231 | ||
0cf4dc9b | 232 | t2n_exception* clone() const |
ac7fdc22 GE |
233 | { return new t2n_command_error(*this); } |
234 | ||
235 | void do_throw() | |
236 | { throw *this; } | |
237 | }; | |
238 | BOOST_CLASS_EXPORT(t2n_command_error) | |
239 | ||
04e6b271 | 240 | /// error serializing or deserializing a libt2n command packet |
ac7fdc22 GE |
241 | class t2n_serialization_error : public t2n_exception |
242 | { | |
243 | private: | |
244 | friend class boost::serialization::access; | |
245 | template<class Archive> | |
246 | void serialize(Archive & ar, const unsigned int version) | |
247 | { | |
248 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception); | |
249 | } | |
250 | ||
251 | public: | |
0cf4dc9b | 252 | t2n_serialization_error(const std::string& _message) |
ac7fdc22 GE |
253 | : t2n_exception(_message) |
254 | { } | |
255 | ||
256 | t2n_serialization_error() | |
257 | { } | |
258 | ||
0cf4dc9b | 259 | t2n_exception* clone() const |
ac7fdc22 GE |
260 | { return new t2n_serialization_error(*this); } |
261 | ||
262 | void do_throw() | |
263 | { throw *this; } | |
264 | }; | |
265 | BOOST_CLASS_EXPORT(t2n_serialization_error) | |
266 | ||
cc68aabb | 267 | /** @brief a runtime error within the remote function. |
04e6b271 GE |
268 | derive your own custom exceptions from this one |
269 | */ | |
ac7fdc22 GE |
270 | class t2n_runtime_error : public t2n_exception |
271 | { | |
272 | private: | |
273 | friend class boost::serialization::access; | |
274 | template<class Archive> | |
275 | void serialize(Archive & ar, const unsigned int version) | |
276 | { | |
277 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception); | |
278 | } | |
279 | ||
280 | public: | |
0cf4dc9b | 281 | t2n_runtime_error(const std::string& _message) |
ac7fdc22 GE |
282 | : t2n_exception(_message) |
283 | { } | |
284 | ||
285 | t2n_runtime_error() | |
286 | { } | |
287 | ||
0cf4dc9b | 288 | t2n_exception* clone() const |
ac7fdc22 GE |
289 | { return new t2n_runtime_error(*this); } |
290 | ||
291 | void do_throw() | |
292 | { throw *this; } | |
293 | }; | |
294 | BOOST_CLASS_EXPORT(t2n_runtime_error) | |
295 | ||
296 | } | |
297 | ||
298 | #endif |