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> | |
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 |
72 | class 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 |
95 | class 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 |
118 | class 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 |
141 | class 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 |
164 | class 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 |
187 | class 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 | |
04e6b271 | 209 | /// error serializing or deserializing a libt2n command packet |
ac7fdc22 GE |
210 | class t2n_serialization_error : public t2n_exception |
211 | { | |
212 | private: | |
213 | friend class boost::serialization::access; | |
214 | template<class Archive> | |
e453407d | 215 | void serialize(Archive & ar, const unsigned int version); |
ac7fdc22 GE |
216 | |
217 | public: | |
0cf4dc9b | 218 | t2n_serialization_error(const std::string& _message) |
ac7fdc22 GE |
219 | : t2n_exception(_message) |
220 | { } | |
221 | ||
222 | t2n_serialization_error() | |
223 | { } | |
224 | ||
0cf4dc9b | 225 | t2n_exception* clone() const |
ac7fdc22 GE |
226 | { return new t2n_serialization_error(*this); } |
227 | ||
228 | void do_throw() | |
229 | { throw *this; } | |
230 | }; | |
ac7fdc22 | 231 | |
cc68aabb | 232 | /** @brief a runtime error within the remote function. |
04e6b271 GE |
233 | derive your own custom exceptions from this one |
234 | */ | |
ac7fdc22 GE |
235 | class t2n_runtime_error : public t2n_exception |
236 | { | |
237 | private: | |
238 | friend class boost::serialization::access; | |
239 | template<class Archive> | |
e453407d | 240 | void serialize(Archive & ar, const unsigned int version); |
ac7fdc22 GE |
241 | |
242 | public: | |
0cf4dc9b | 243 | t2n_runtime_error(const std::string& _message) |
ac7fdc22 GE |
244 | : t2n_exception(_message) |
245 | { } | |
246 | ||
247 | t2n_runtime_error() | |
248 | { } | |
249 | ||
0cf4dc9b | 250 | t2n_exception* clone() const |
ac7fdc22 GE |
251 | { return new t2n_runtime_error(*this); } |
252 | ||
253 | void do_throw() | |
254 | { throw *this; } | |
255 | }; | |
ac7fdc22 | 256 | |
7087e187 | 257 | } // namespace libt2n |
ac7fdc22 GE |
258 | |
259 | #endif |