source: xplra/src/client/c/hu/varadiistvan/xplra/Exception.h@ 14:bb6484eceb1e

Last change on this file since 14:bb6484eceb1e was 14:bb6484eceb1e, checked in by István Váradi <ivaradi@…>, 11 years ago

Very basic client code works

File size: 6.2 KB
Line 
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
39namespace hu { namespace varadiistvan { namespace xplra {
40
41//------------------------------------------------------------------------------
42
43/**
44 * Base class for exceptions that can be thrown by the client.
45 */
46class Exception : public std::exception
47{
48protected:
49 /**
50 * The string representation of the error message.
51 */
52 std::string message;
53
54public:
55 /**
56 * Construct the exception with the given message.
57 */
58 Exception(const char* message) throw();
59
60protected:
61 /**
62 * Default constructor for children.
63 */
64 Exception() throw();
65
66public:
67 /**
68 * Destroy the exception
69 */
70 virtual ~Exception() throw();
71
72public:
73 /**
74 * Get a message.
75 */
76 virtual const char* what() const throw();
77};
78
79//------------------------------------------------------------------------------
80
81/**
82 * An I/O exception.
83 */
84class IOException : public Exception
85{
86public:
87 /**
88 * Type for the error code.
89 */
90 typedef unsigned long errorCode_t;
91
92private:
93 /**
94 * The error code.
95 */
96 errorCode_t errorCode;
97
98public:
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 */
117class ProtocolException : public Exception
118{
119public:
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
149private:
150 /**
151 * The error code.
152 */
153 errorCode_t errorCode;
154
155public:
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 */
173class NotConnectedException : public Exception
174{
175public:
176 /**
177 * Construct the exception
178 */
179 NotConnectedException();
180};
181
182//------------------------------------------------------------------------------
183// Inline definitions
184//------------------------------------------------------------------------------
185
186inline Exception::Exception(const char* message) throw() :
187 message(message)
188{
189}
190
191//------------------------------------------------------------------------------
192
193inline Exception::Exception() throw()
194{
195}
196
197//------------------------------------------------------------------------------
198
199inline Exception::~Exception() throw()
200{
201}
202
203//------------------------------------------------------------------------------
204//------------------------------------------------------------------------------
205
206inline IOException::errorCode_t IOException::getErrorCode() const throw()
207{
208 return errorCode;
209}
210
211//------------------------------------------------------------------------------
212//------------------------------------------------------------------------------
213
214inline ProtocolException::errorCode_t
215ProtocolException::getErrorCode() const throw()
216{
217 return errorCode;
218}
219
220//------------------------------------------------------------------------------
221//------------------------------------------------------------------------------
222
223inline NotConnectedException::NotConnectedException() :
224 Exception("xplra::NotConnectedException: not connected to the simulator")
225{
226}
227
228//------------------------------------------------------------------------------
229
230} /* namespace hu::varadiistvan::xplra */ } /* namespace hu::varadiistvan */ } /* namespace hu */
231
232//------------------------------------------------------------------------------
233#endif // HU_VARADIISTVAN_XPLRA_EXCEPTION_H
234
235// Local Variables:
236// mode: C++
237// c-basic-offset: 4
238// indent-tabs-mode: nil
239// End:
Note: See TracBrowser for help on using the repository browser.