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