X-Plane Remote Access Plugin and Client Library
Exception.h
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 
46 class Exception : public std::exception
47 {
48 protected:
52  std::string message;
53 
54 public:
58  Exception(const char* message) throw();
59 
60 protected:
64  Exception() throw();
65 
66 public:
70  virtual ~Exception() throw();
71 
72 public:
76  virtual const char* what() const throw();
77 };
78 
79 //------------------------------------------------------------------------------
80 
84 class IOException : public Exception
85 {
86 public:
90  typedef unsigned long errorCode_t;
91 
92 private:
97 
98 public:
102  IOException(errorCode_t errorCode) throw();
103 
104 
108  errorCode_t getErrorCode() const throw();
109 };
110 
111 //------------------------------------------------------------------------------
112 
118 {
119 public:
123  typedef enum {
125  INVALID_COMMAND = 1,
126 
128  UNKNOWN_DATAREF = 2,
129 
131  INVALID_TYPE = 3,
132 
134  INVALID_LENGTH = 4,
135 
137  INVALID_OFFSET = 5,
138 
140  INVALID_COUNT = 6,
141 
143  INVALID_ID = 7,
144 
146  INVALID_DURATION = 8,
147 
149  OTHER = 255
150  } errorCode_t;
151 
152 private:
157 
162 
166  long parameter;
167 
168 public:
172  ProtocolException(errorCode_t errorCode,
173  bool hasParameter = false, long parameter = 0) throw();
174 
178  errorCode_t getErrorCode() const throw();
179 
183  bool getParameter(long& param) const throw();
184 };
185 
186 //------------------------------------------------------------------------------
187 
193 {
194 public:
198  NotConnectedException() throw();
199 };
200 
201 //------------------------------------------------------------------------------
202 
208 {
209 public:
213  TypeMismatchException() throw();
214 };
215 
216 //------------------------------------------------------------------------------
217 
223 {
224 public:
228  InvalidIDException() throw();
229 };
230 
231 //------------------------------------------------------------------------------
232 // Inline definitions
233 //------------------------------------------------------------------------------
234 
235 inline Exception::Exception(const char* message) throw() :
237 {
238 }
239 
240 //------------------------------------------------------------------------------
241 
242 inline Exception::Exception() throw()
243 {
244 }
245 
246 //------------------------------------------------------------------------------
247 
248 inline Exception::~Exception() throw()
249 {
250 }
251 
252 //------------------------------------------------------------------------------
253 //------------------------------------------------------------------------------
254 
256 {
257  return errorCode;
258 }
259 
260 //------------------------------------------------------------------------------
261 //------------------------------------------------------------------------------
262 
265 {
266  return errorCode;
267 }
268 
269 //------------------------------------------------------------------------------
270 
271 inline bool ProtocolException::getParameter(long& param) const throw()
272 {
273  if (hasParameter) param = parameter;
274  return hasParameter;
275 }
276 
277 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 
281  Exception("xplra::NotConnectedException: not connected to the simulator")
282 {
283 }
284 
285 //------------------------------------------------------------------------------
286 //------------------------------------------------------------------------------
287 
290 {
291 }
292 
293 //------------------------------------------------------------------------------
294 //------------------------------------------------------------------------------
295 
298 {
299 }
300 
301 //------------------------------------------------------------------------------
302 
303 } /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
304 
305 //------------------------------------------------------------------------------
306 #endif // HU_VARADIISTVAN_XPLRA_EXCEPTION_H
307 
308 // Local Variables:
309 // mode: C++
310 // c-basic-offset: 4
311 // indent-tabs-mode: nil
312 // End:
virtual const char * what() const
Definition: Exception.cc:43
errorCode_t getErrorCode() const
Definition: Exception.h:255
bool getParameter(long &param) const
Definition: Exception.h:271
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41