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