FreeWRL / FreeX3D 4.3.0
SAIexception.h
1/****************************************************************************
2 This file is part of the FreeWRL/FreeX3D Distribution.
3
4 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
5
6 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
18****************************************************************************/
19
20#ifndef _SAIEXCEPTION_H_
21#define _SAIEXCEPTION_H_
22
23#define SAI_GENERIC_EXCEPTION 0
24#define SAI_BROWSER_UNAVAILABLE 1
25#define SAI_CONNECTION_ERROR 2
26#define SAI_DISPOSED 3
27#define SAI_IMPORTED_NODE 4
28#define SAI_INSUFFICIENT_CAPABILITIES 5
29#define SAI_INVALID_ACCESS_TYPE 6
30#define SAI_INVALID_BROWSER 7
31#define SAI_INVALID_DOCUMENT 8
32#define SAI_INVALID_FIELD 9
33#define SAI_INVALID_NAME 10 //mapped to SAI_INVALID_FIELD or to SAI_INVALID_NODE as Java Language Binding does
34#define SAI_INVALID_NODE 11
35#define SAI_INVALID_OPERATION_TIMING 12
36#define SAI_INVALID_URL 13
37#define SAI_INVALID_X3D 14
38#define SAI_NODE_NOT_AVAILABLE 15
39#define SAI_NODE_IN_USE 16
40#define SAI_NOT_SHARED 17
41#define SAI_NOT_SUPPORTED 18
42#define SAI_URL_UNAVAILABLE 19
43#define SAI_INVALID_EXECUTION_CONTEXT 20
44//derived exceptions as specified in Java Language Binding
45#define SAI_NOT_READABLE_FIELD 21
46#define SAI_NOT_WRITABLE_FIELD 22
47
48//placeholder for custom exception left to the provider
49#define SAI_CUSTOM_EXCEPTION 100
50
51#include <exception>
52
53namespace freeWRLSAI_cpp
54{
55 //Generic SAI exception. Base class
56 class saiException : public std::exception
57 {
58 public:
60 {
61 m_nErrorCode = 0;
62 }
63
64 virtual const char* what(){return "Generic SAI exception.\n";}
65
66 virtual int GetError(){return m_nErrorCode;}
67
68 protected:
69 int m_nErrorCode;
70 };
71
72 //SAI_BROWSER_UNAVAILABLE exception.
74 {
75 public:
77 {
78 m_nErrorCode = SAI_BROWSER_UNAVAILABLE;
79 }
80
81 virtual const char* what(){return "The request to gain a reference to a SAIBrowserApp has failed.\n "
82 "The connection may be down or the type of reference required is not supported.";}
83 };
84
86 {
87 public:
89 {
90 m_nErrorCode = SAI_CONNECTION_ERROR;
91 }
92
93 virtual const char* what(){return "Connection to browser failed or was never established.\n";}
94 };
95
97 {
98 public:
100 {
101 m_nErrorCode = SAI_DISPOSED;
102 }
103
104 virtual const char* what(){return "The reference required has already beed disposed in this context.\n";}
105 };
106
108 {
109 public:
111 {
112 m_nErrorCode = SAI_IMPORTED_NODE;
113 }
114
115 virtual const char* what(){return "An operation was attempted that used an imported node when it is not permitted.\n";}
116 };
117
119 {
120 public:
122 {
123 m_nErrorCode = SAI_INSUFFICIENT_CAPABILITIES;
124 }
125
126 virtual const char* what(){return "Cannot add a node to an execution context that is greater than the capabilities defined by the profile and components definition for the scene.\n";}
127 };
128
130 {
131 public:
133 {
134 m_nErrorCode = SAI_INVALID_ACCESS_TYPE;
135 }
136
137 virtual const char* what(){return "Cannot perform the requested operation because it is an invalid action for this field type.\n";}
138 };
139
141 {
142 public:
144 {
145 m_nErrorCode = SAI_INVALID_BROWSER;
146 }
147
148 virtual const char* what(){return "The Browser service requested has been disposed of prior to this request.\n";}
149 };
150
152 {
153 public:
155 {
156 m_nErrorCode = SAI_INVALID_DOCUMENT;
157 }
158
159 virtual const char* what(){return "The document structure is not compliant with X3D DOM.\n";}
160 };
161
163 {
164 public:
166 {
167 m_nErrorCode = SAI_INVALID_OPERATION_TIMING;
168 }
169
170 virtual const char* what(){return "The user is attempting to make a service request that is performed outside of the context that such operations are permitted in.\n";}
171 };
172
174 {
175 public:
177 {
178 m_nErrorCode = SAI_INVALID_URL;
179 }
180
181 virtual const char* what(){return "Syntax Error: the url specified is not correct.\n";}
182 };
183
185 {
186 public:
188 {
189 m_nErrorCode = SAI_INVALID_X3D;
190 }
191
192 virtual const char* what(){return "Syntax Error: the X3D document requested or specified is not correct.\n";}
193 };
194
196 {
197 public:
199 {
200 m_nErrorCode = SAI_NODE_NOT_AVAILABLE;
201 }
202
203 virtual const char* what(){return "The imported node requested has not yet been verified for export.\n";}
204 };
205
207 {
208 public:
210 {
211 m_nErrorCode = SAI_NODE_IN_USE;
212 }
213
214 virtual const char* what(){return "A named node handling action has attempted to re-use a name that is already defined elsewhere in this current scene.\n "
215 "Or the node, or one of its children, is currently in use in another scene.\n";}
216 };
217
219 {
220 public:
222 {
223 m_nErrorCode = SAI_NOT_SHARED;
224 }
225
226 virtual const char* what(){return "A service request was made that assumed the browser was currently participating in a shared scene graph when it was not.\n";}
227 };
228
230 {
231 public:
233 {
234 m_nErrorCode = SAI_NOT_SUPPORTED;
235 }
236
237 virtual const char* what(){return "The service request is not supported.\n";}
238 };
239
241 {
242 public:
244 {
245 m_nErrorCode = SAI_URL_UNAVAILABLE;
246 }
247
248 virtual const char* what(){return "No valid URL has been specified for this request.\n";}
249 };
250
251 //DERIVED FROM disposedException
252
254 {
255 public:
257 {
258 m_nErrorCode = SAI_INVALID_EXECUTION_CONTEXT;
259 }
260
261 virtual const char* what(){return "The execution context requested has been disposed of prior to this request.\n";}
262 };
263
265 {
266 public:
268 {
269 m_nErrorCode = SAI_INVALID_FIELD;
270 }
271
272 virtual const char* what(){return "The requested field has been disposed of prior to this request.\n";}
273 };
274
276 {
277 public:
279 {
280 m_nErrorCode = SAI_INVALID_NODE;
281 }
282
283 virtual const char* what(){return "The requested node has been disposed of prior to this request.\n";}
284 };
285
286 //OTHER DERIVED EXCEPTION
288 {
289 public:
291 {
292 invalidFieldException::m_nErrorCode = SAI_NOT_WRITABLE_FIELD;
293 }
294
295 virtual const char* what(){return "The requested field cannot be written.\n";}
296 };
297
299 {
300 public:
302 {
303 invalidFieldException::m_nErrorCode = SAI_NOT_READABLE_FIELD;
304 }
305
306 virtual const char* what(){return "The requested field cannot be read.\n";}
307 };
308
309 //facility exception NOT REQUESTED by W3C specs
311 {
312 public:
313 saiCustomException(const char* strWhat, const char* strFile, int strLine, const char* strFunc)
314 {
315 m_nErrorCode = SAI_CUSTOM_EXCEPTION;
316
317 char buffer[256];
318
319 int nChars = sprintf_s(buffer,256,"%s\n In file: %s, line: %d, function: %s",strWhat,strFile,strLine,strFunc);
320
321 if(nChars > 0)
322 m_strWhat = buffer;
323 else
324 m_strWhat = "Exception message was not well formed.\n";
325 }
326
327 virtual const char* what(){return m_strWhat.c_str();}
328
329 std::string m_strWhat;
330 };
331
332};
333
334#endif //_SAIEXCEPTION_H_