1 | // Copyright (c) 2013 by István Váradi
|
---|
2 |
|
---|
3 | // This file is part of XPLRA, a remote-access plugin for X-Plane
|
---|
4 |
|
---|
5 | // Redistribution and use in source and binary forms, with or without
|
---|
6 | // modification, are permitted provided that the following conditions are met:
|
---|
7 |
|
---|
8 | // 1. Redistributions of source code must retain the above copyright notice, this
|
---|
9 | // list of conditions and the following disclaimer.
|
---|
10 | // 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | // this list of conditions and the following disclaimer in the documentation
|
---|
12 | // and/or other materials provided with the distribution.
|
---|
13 |
|
---|
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
15 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
---|
18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 |
|
---|
25 | // The views and conclusions contained in the software and documentation are those
|
---|
26 | // of the authors and should not be interpreted as representing official policies,
|
---|
27 | // either expressed or implied, of the FreeBSD Project.
|
---|
28 |
|
---|
29 | #ifndef HU_VARADIISTVAN_XPLRA_EXCEPTION_H
|
---|
30 | #define HU_VARADIISTVAN_XPLRA_EXCEPTION_H
|
---|
31 | //------------------------------------------------------------------------------
|
---|
32 |
|
---|
33 | #include <exception>
|
---|
34 |
|
---|
35 | #include <string>
|
---|
36 |
|
---|
37 | //------------------------------------------------------------------------------
|
---|
38 |
|
---|
39 | namespace hu { namespace varadiistvan { namespace xplra {
|
---|
40 |
|
---|
41 | //------------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Base class for exceptions that can be thrown by the client.
|
---|
45 | */
|
---|
46 | class Exception : public std::exception
|
---|
47 | {
|
---|
48 | protected:
|
---|
49 | /**
|
---|
50 | * The string representation of the error message.
|
---|
51 | */
|
---|
52 | std::string message;
|
---|
53 |
|
---|
54 | public:
|
---|
55 | /**
|
---|
56 | * Construct the exception with the given message.
|
---|
57 | */
|
---|
58 | Exception(const char* message) throw();
|
---|
59 |
|
---|
60 | protected:
|
---|
61 | /**
|
---|
62 | * Default constructor for children.
|
---|
63 | */
|
---|
64 | Exception() throw();
|
---|
65 |
|
---|
66 | public:
|
---|
67 | /**
|
---|
68 | * Destroy the exception
|
---|
69 | */
|
---|
70 | virtual ~Exception() throw();
|
---|
71 |
|
---|
72 | public:
|
---|
73 | /**
|
---|
74 | * Get a message.
|
---|
75 | */
|
---|
76 | virtual const char* what() const throw();
|
---|
77 | };
|
---|
78 |
|
---|
79 | //------------------------------------------------------------------------------
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * An I/O exception.
|
---|
83 | */
|
---|
84 | class IOException : public Exception
|
---|
85 | {
|
---|
86 | public:
|
---|
87 | /**
|
---|
88 | * Type for the error code.
|
---|
89 | */
|
---|
90 | typedef unsigned long errorCode_t;
|
---|
91 |
|
---|
92 | private:
|
---|
93 | /**
|
---|
94 | * The error code.
|
---|
95 | */
|
---|
96 | errorCode_t errorCode;
|
---|
97 |
|
---|
98 | public:
|
---|
99 | /**
|
---|
100 | * Construct the exception.
|
---|
101 | */
|
---|
102 | IOException(errorCode_t errorCode) throw();
|
---|
103 |
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Get the error code.
|
---|
107 | */
|
---|
108 | errorCode_t getErrorCode() const throw();
|
---|
109 | };
|
---|
110 |
|
---|
111 | //------------------------------------------------------------------------------
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * An exception arising from the invalid use of the protocol, e.g. an
|
---|
115 | * invalid dataref.
|
---|
116 | */
|
---|
117 | class ProtocolException : public Exception
|
---|
118 | {
|
---|
119 | public:
|
---|
120 | /**
|
---|
121 | * Type for the error codes.
|
---|
122 | */
|
---|
123 | typedef enum {
|
---|
124 | /// Invalid command issued
|
---|
125 | INVALID_COMMAND = 1,
|
---|
126 |
|
---|
127 | /// Unknown dataref
|
---|
128 | UNKNOWN_DATAREF = 2,
|
---|
129 |
|
---|
130 | /// Invalid type
|
---|
131 | INVALID_TYPE = 3,
|
---|
132 |
|
---|
133 | /// Invalid length
|
---|
134 | INVALID_LENGTH = 4,
|
---|
135 |
|
---|
136 | /// Invalid offset
|
---|
137 | INVALID_OFFSET = 5,
|
---|
138 |
|
---|
139 | /// Invalid count
|
---|
140 | INVALID_COUNT = 6,
|
---|
141 |
|
---|
142 | /// Invalid ID
|
---|
143 | INVALID_ID = 7,
|
---|
144 |
|
---|
145 | /// Other error
|
---|
146 | OTHER = 255
|
---|
147 | } errorCode_t;
|
---|
148 |
|
---|
149 | private:
|
---|
150 | /**
|
---|
151 | * The error code.
|
---|
152 | */
|
---|
153 | errorCode_t errorCode;
|
---|
154 |
|
---|
155 | public:
|
---|
156 | /**
|
---|
157 | * Construct the exception.
|
---|
158 | */
|
---|
159 | ProtocolException(errorCode_t errorCode) throw();
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Get the error code.
|
---|
163 | */
|
---|
164 | errorCode_t getErrorCode() const throw();
|
---|
165 | };
|
---|
166 |
|
---|
167 | //------------------------------------------------------------------------------
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Exception to signify the fact the we are not connected to the
|
---|
171 | * simulator.
|
---|
172 | */
|
---|
173 | class NotConnectedException : public Exception
|
---|
174 | {
|
---|
175 | public:
|
---|
176 | /**
|
---|
177 | * Construct the exception
|
---|
178 | */
|
---|
179 | NotConnectedException() throw();
|
---|
180 | };
|
---|
181 |
|
---|
182 | //------------------------------------------------------------------------------
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Exception thrown when we want to get or set a dataref in a
|
---|
186 | * MultiBuffer into or from a value of the wrong type.
|
---|
187 | */
|
---|
188 | class TypeMismatchException : public Exception
|
---|
189 | {
|
---|
190 | public:
|
---|
191 | /**
|
---|
192 | * Construct the exception
|
---|
193 | */
|
---|
194 | TypeMismatchException() throw();
|
---|
195 | };
|
---|
196 |
|
---|
197 | //------------------------------------------------------------------------------
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Exception thrown when we want to get or set a dataref with an
|
---|
201 | * invalid ID.
|
---|
202 | */
|
---|
203 | class InvalidIDException : public Exception
|
---|
204 | {
|
---|
205 | public:
|
---|
206 | /**
|
---|
207 | * Construct the exception
|
---|
208 | */
|
---|
209 | InvalidIDException() throw();
|
---|
210 | };
|
---|
211 |
|
---|
212 | //------------------------------------------------------------------------------
|
---|
213 | // Inline definitions
|
---|
214 | //------------------------------------------------------------------------------
|
---|
215 |
|
---|
216 | inline Exception::Exception(const char* message) throw() :
|
---|
217 | message(message)
|
---|
218 | {
|
---|
219 | }
|
---|
220 |
|
---|
221 | //------------------------------------------------------------------------------
|
---|
222 |
|
---|
223 | inline Exception::Exception() throw()
|
---|
224 | {
|
---|
225 | }
|
---|
226 |
|
---|
227 | //------------------------------------------------------------------------------
|
---|
228 |
|
---|
229 | inline Exception::~Exception() throw()
|
---|
230 | {
|
---|
231 | }
|
---|
232 |
|
---|
233 | //------------------------------------------------------------------------------
|
---|
234 | //------------------------------------------------------------------------------
|
---|
235 |
|
---|
236 | inline IOException::errorCode_t IOException::getErrorCode() const throw()
|
---|
237 | {
|
---|
238 | return errorCode;
|
---|
239 | }
|
---|
240 |
|
---|
241 | //------------------------------------------------------------------------------
|
---|
242 | //------------------------------------------------------------------------------
|
---|
243 |
|
---|
244 | inline ProtocolException::errorCode_t
|
---|
245 | ProtocolException::getErrorCode() const throw()
|
---|
246 | {
|
---|
247 | return errorCode;
|
---|
248 | }
|
---|
249 |
|
---|
250 | //------------------------------------------------------------------------------
|
---|
251 | //------------------------------------------------------------------------------
|
---|
252 |
|
---|
253 | inline NotConnectedException::NotConnectedException() throw() :
|
---|
254 | Exception("xplra::NotConnectedException: not connected to the simulator")
|
---|
255 | {
|
---|
256 | }
|
---|
257 |
|
---|
258 | //------------------------------------------------------------------------------
|
---|
259 | //------------------------------------------------------------------------------
|
---|
260 |
|
---|
261 | inline TypeMismatchException::TypeMismatchException() throw() :
|
---|
262 | Exception("xplra::TypeMismatchException")
|
---|
263 | {
|
---|
264 | }
|
---|
265 |
|
---|
266 | //------------------------------------------------------------------------------
|
---|
267 | //------------------------------------------------------------------------------
|
---|
268 |
|
---|
269 | inline InvalidIDException::InvalidIDException() throw() :
|
---|
270 | Exception("xplra::InvalidIDException")
|
---|
271 | {
|
---|
272 | }
|
---|
273 |
|
---|
274 | //------------------------------------------------------------------------------
|
---|
275 |
|
---|
276 | } /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
|
---|
277 |
|
---|
278 | //------------------------------------------------------------------------------
|
---|
279 | #endif // HU_VARADIISTVAN_XPLRA_EXCEPTION_H
|
---|
280 |
|
---|
281 | // Local Variables:
|
---|
282 | // mode: C++
|
---|
283 | // c-basic-offset: 4
|
---|
284 | // indent-tabs-mode: nil
|
---|
285 | // End:
|
---|