Accelerator Independent Data Access / PVAccess 2.0
AIDA-PVA is the latest version of the AIDA framework. Built on top of EPICS 7 it enables client applications to programmatically access and manage any device or database on the SLAC Network using simple channel names.
Loading...
Searching...
No Matches
aida_pva_exceptions.h
Go to the documentation of this file.
1/** @file
2 * @brief The Header File for the exceptions helper MACROS.
3 * **CMS**=C_INC
4 */
5#ifndef aida_pva_exceptions_h
6#define aida_pva_exceptions_h
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include "aida_pva.h"
12#include "errtranslate.h"
13
14// Supported exceptions
15/**
16 * Use this string to signal Internal Exceptions in aidaThrow()
17 */
18#define AIDA_INTERNAL_EXCEPTION "AidaInternalException"
19/**
20 * Use this string to signal Server Initialisation Exceptions in aidaThrow()
21 */
22#define SERVER_INITIALISATION_EXCEPTION "ServerInitialisationException"
23/**
24 * Use this string to signal Exceptions when trying to Get Data in aidaThrow()
25 */
26#define UNABLE_TO_GET_DATA_EXCEPTION "UnableToGetDataException"
27/**
28 * Use this string to signal Exceptions when trying to Set Data in aidaThrow()
29 */
30#define UNABLE_TO_SET_DATA_EXCEPTION "UnableToSetDataException"
31/**
32 * Use this string to signal Unsupported Channel Exceptions in aidaThrow()
33 */
34#define UNSUPPORTED_CHANNEL_EXCEPTION "UnsupportedChannelException"
35/**
36 * Use this string to signal Missing Required Argument Exceptions in aidaThrow()
37 */
38#define MISSING_REQUIRED_ARGUMENT_EXCEPTION "MissingRequiredArgumentException"
39
40/**
41 * The maximum size of the error text message in an aidaThrow() call
42 */
43#define MAX_ERROR_TEXT_LEN 100
44
45/**
46 * Check to see if an exception has been raised,
47 * and return the given return value.
48 *
49 * Uses local variable `env` for checking exception status.
50 *
51 * @param _r the specified return value.
52 * @return This MACRO will return the specified return value from your function if there has been an exception.
53 */
54#define ON_EXCEPTION_RETURN_(_r) \
55 if ((*env)->ExceptionCheck(env)) { \
56 return _r; \
57 }
58
59/**
60 * Check to see if an exception has been raised,
61 * then free tracked memory,
62 * and return the given return value.
63 *
64 * Uses local variable `env` for checking exception status.
65 *
66 * @param _r the specified return value.
67 * @return This MACRO will return the specified return value from your function if there has been an exception.
68 */
69#define ON_EXCEPTION_FREE_MEMORY_AND_RETURN_(_r) \
70 if ((*env)->ExceptionCheck(env)) { \
71 FREE_MEMORY \
72 return _r; \
73 }
74
75/**
76 * Check to see if an exception has been raised,
77 * and return void,
78 *
79 * Uses local variable `env` for checking exception status.
80 *
81 * @return This MACRO will return from your function if there has been an exception.
82 */
83#define ON_EXCEPTION_RETURN_VOID \
84 if ((*env)->ExceptionCheck(env)) { \
85 return; \
86 }
87
88/**
89 * Check to see if an exception has been raised,
90 * free local variable pv if set,
91 * free local variable {@link Arguments}
92 * and return the given return value.
93 *
94 * Uses local variable `env` for checking exception status.
95 *
96 * @param _r the specified return value.
97 * @return This MACRO will return the specified return value from your function if there has been an exception.
98 */
99#define ON_EXCEPTION_FREE_PV_AND_ARGUMENTS_AND_RETURN_(_r) \
100 if ((*env)->ExceptionCheck(env)) { \
101 releasePvAndArguments(env, uri, pv, arguments); \
102 return _r; \
103 }
104
105/**
106 * Check to see if an exception has been raised,
107 * free local variable pv if set,
108 * free local variable {@link Arguments}
109 * and return void,
110 *
111 * Uses local variable `env` for checking exception status.
112 *
113 * @return This MACRO will return from your function if there has been an exception.
114 */
115#define ON_EXCEPTION_FREE_PV_AND_ARGUMENTS_AND_RETURN_VOID \
116 if ((*env)->ExceptionCheck(env)) { \
117 releasePvAndArguments(env, uri, pv, arguments); \
118 return; \
119 }
120
121/**
122 * Check to see if an exception has been raised,
123 * free a local variable `string`,
124 * free local variable pv if set,
125 * free local variable {@link Arguments}
126 * and return the given return value.
127 *
128 * Uses local variable `env` for checking exception status.
129 *
130 * @param _r the specified return value.
131 * @return This MACRO will return the specified return value from your function if there has been an exception.
132 */
133#define ON_EXCEPTION_FREE_STRING_AND_PV_AND_ARGS_AND_RETURN_(_r) \
134 if ((*env)->ExceptionCheck(env)) { \
135 if ( string ) free(string); \
136 releasePvAndArguments(env, uri, pv, arguments); \
137 return _r; \
138 }
139
140/**
141 * Check to see if an exception has been raised,
142 * free a local variable `string`,
143 * and return the given return value.
144 *
145 * Uses local variable `env` for checking exception status.
146 *
147 * @param _r the specified return value.
148 * @return This MACRO will return the specified return value from your function if there has been an exception.
149 */
150#define ON_EXCEPTION_FREE_STRING_AND_RETURN_(_r) \
151 if ((*env)->ExceptionCheck(env)) { \
152 if ( string ) free(string); \
153 return _r; \
154 }
155
156/**
157 * Check to see if an exception has been raised,
158 * free local variable {@link Array},
159 * free local variable pv if set,
160 * free local variable {@link Arguments}
161 * and return the given return value.
162 *
163 * Uses local variable `env` for checking exception status.
164 *
165 * @param _r the specified return value.
166 * @return This MACRO will return the specified return value from your function if there has been an exception.
167 */
168#define ON_EXCEPTION_FREE_ARRAY_AND_PV_AND_ARGS_AND_RETURN_(_r) \
169 if ((*env)->ExceptionCheck(env)) { \
170 releaseArray(array); \
171 releasePvAndArguments(env, uri, pv, arguments); \
172 return _r; \
173 }
174
175/**
176 * Check to see if an exception has been raised,
177 * free local variable {@link Array},
178 * free local variable pv if set,
179 * free local variable {@link Arguments}
180 * and return void.
181 *
182 * Uses local variable `env` for checking exception status.
183 *
184 * @return This MACRO will return from your function if there has been an exception.
185 */
186#define ON_EXCEPTION_FREE_STRING_ARRAY_AND_PV_AND_ARGS_AND_RETURN_NULL \
187 if ((*env)->ExceptionCheck(env)) { \
188 releaseStringArray(array); \
189 releasePvAndArguments(env, uri, pv, arguments); \
190 return NULL; \
191 }
192
193/**
194 * Check to see if an exception has been raised,
195 * free local variable {@link Table},
196 * free local variable pv if set,
197 * free local variable {@link Arguments},
198 * and return the given return value.
199 *
200 * Uses local variable `env` for checking exception status.
201 *
202 * @param _r the specified return value.
203 * @return This MACRO will return the specified return value from your function if there has been an exception.
204 */
205#define ON_EXCEPTION_FREE_TABLE_AND_PV_AND_ARGS_AND_RETURN_(_r) \
206 if ((*env)->ExceptionCheck(env)) { \
207 releaseTable(table); \
208 releasePvAndArguments(env, uri, pv, arguments); \
209 return _r; \
210 }
211
212/**
213 * Check to see if an exception has been raised,
214 * free local variable `value`,
215 * free local variable pv if set,
216 * free local variable {@link Arguments}
217 * and return void.
218 *
219 * Uses local variable `env` for checking exception status.
220 *
221 * @return This MACRO will return from your function if there has been an exception.
222 */
223#define ON_EXCEPTION_FREE_VALUE_AND_PV_AND_ARGS_AND_RETURN_VOID \
224 if ((*env)->ExceptionCheck(env)) { \
225 releaseValue(value); \
226 releasePvAndArguments(env, uri, pv, arguments); \
227 return; \
228 }
229
230/**
231 * Check to see if an exception has been raised,
232 * free local variable `value`,
233 * free local variable pv if set,
234 * free local variable {@link Arguments},
235 * and return the given return value.
236 *
237 * Uses local variable `env` for checking exception status.
238 *
239 * @param _r the specified return value.
240 * @return This MACRO will return the specified return value from your function if there has been an exception.
241 */
242#define ON_EXCEPTION_FREE_VALUE_AND_PV_AND_ARGS_AND_RETURN_(_r) \
243 if ((*env)->ExceptionCheck(env)) { \
244 releaseValue(value); \
245 releasePvAndArguments(env, uri, pv, arguments); \
246 return _r; \
247 }
248
249/**
250 * Format an error message, throw it in an exception, free any allocated memory and return the error code.
251 *
252 * @param _exception exception to raise (string)
253 * @param _errorText the text of the error to raise
254 * @param _ref a string that will be substituted in message with %s
255 * @param _r the specified return value
256 * @return This MACRO will return the specified return value from your function
257 */
258#define SPRINTF_ERROR_FREE_MEMORY_AND_RETURN_(_exception, _errorText, _ref, _r) \
259{ \
260 char error[MAX_ERROR_TEXT_LEN + strlen(_ref)]; \
261 sprintf(error, _errorText, _ref); \
262 aidaThrowNonOsException(env, _exception, error); \
263 FREE_MEMORY \
264 return _r; \
265}
266
267/**
268 * Format an error message, throw it in an exception, free any allocated memory and return the error code.
269 *
270 * @param _exception exception to raise (string)
271 * @param _status the OS status code to include in the message
272 * @param _errorText the text of the error to raise
273 * @param _ref a string that will be substituted in message with %s
274 * @param _r the specified return value
275 * @return This MACRO will return the specified return value from your function
276 */
277#define SPRINTF_ERROR_STATUS_FREE_MEMORY_AND_RETURN_(_status, _exception, _errorText, _ref, _r) \
278{ \
279 char error[MAX_ERROR_TEXT_LEN + strlen(_ref)]; \
280 sprintf(error, _errorText, _ref); \
281 aidaThrow(env, _status, _exception, error); \
282 FREE_MEMORY \
283 return _r; \
284}
285
286/**
287 * Throw error message in an exception, free any allocated memory and return the error code.
288 *
289 * @param _exception exception to raise (string)
290 * @param _errorText the text of the error to raise
291 * @param _r the specified return value
292 * @return This MACRO will return the specified return value from your function
293 */
294#define PRINT_ERROR_FREE_MEMORY_AND_RETURN_(_exception, _errorText, _r) \
295{ \
296 aidaThrowNonOsException(env, _exception, _errorText); \
297 FREE_MEMORY \
298 return _r; \
299}
300
301/**
302 * Throw unsupported channel exception and return a blank array.
303 */
304#define UNSUPPORTED_ARRAY_REQUEST \
305 aidaThrowNonOsException(env, UNSUPPORTED_CHANNEL_EXCEPTION, uri); \
306 Array array; \
307 return array;
308
309/**
310 * Throw an unsupported channel exception and return an empty string array.
311 */
312#define UNSUPPORTED_STRING_ARRAY_REQUEST \
313 aidaThrowNonOsException(env, UNSUPPORTED_CHANNEL_EXCEPTION, uri); \
314 StringArray stringArray; \
315 return stringArray;
316
317/**
318 * Throw an unsupported channel exception and return an empty table.
319 */
320#define UNSUPPORTED_TABLE_REQUEST \
321 aidaThrowNonOsException(env, UNSUPPORTED_CHANNEL_EXCEPTION, uri); \
322 Table table; \
323 return table;
324
325#ifdef __cplusplus
326}
327#endif
328#endif
329
The Header File for the AIDA-PVA Module functions.