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
AIDASLCREF_SERVER.c
Go to the documentation of this file.
1/** @file
2 * @brief Reference Server implementation.
3 * **MEMBER**=SLCLIBS:AIDA_PVALIB
4 * **ATTRIBUTES**=JNI,LIBR_NOGLOBAL
5 */
6#include "aida_pva.h"
7#include "AIDASLCREF_SERVER.h"
8
9VERSION("1.0.0")
10
11/**
12 * Initialise the service
13 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
14 * @throws ServerInitialisationException if the service fails to initialise
15 */
16void aidaServiceInit(JNIEnv* env)
17{
18 printf("AIDA-PVA Reference Provider\n");
19}
20
21/**
22 * Get a boolean.
23 *
24 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
25 * @param uri the uri
26 * @param arguments the arguments
27 * @return the boolean
28 */
29int aidaRequestBoolean(JNIEnv* env, const char* uri, Arguments arguments)
30{
31 // Only for attribute01
32 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute01")) {
34 }
35
36 int item;
37
38 // Optional Arguments
39 unsigned char x = 0x1;
40 ascanf(env, &arguments, "%ob", "x", &x);
41 item = x;
42
43 // Return the item
44 return item;
45
46}
47
48/**
49 * Get a byte
50 *
51 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
52 * @param uri the uri
53 * @param arguments the arguments
54 * @return the byte
55 */
56char aidaRequestByte(JNIEnv* env, const char* uri, Arguments arguments)
57{
58 // Only for attribute02
59 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute02")) {
61 }
62
63 char item = 0x02;
64
65 // Optional Arguments
66 unsigned char x = 0x0;
67 ascanf(env, &arguments, "%oc", "x", &x);
68 item |= x;
69
70 // Return the item
71 return item;
72}
73
74/**
75 * Get a short
76 *
77 * @param uri the uri
78 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
79 * @param arguments the arguments
80 * @return the short
81 */
82short aidaRequestShort(JNIEnv* env, const char* uri, Arguments arguments)
83{
84 // Only for attribute03
85 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute03")) {
87 }
88
89 short item = 3;
90
91 // Optional Arguments
92 short x = 0;
93 ascanf(env, &arguments, "ohd", "x", &x);
94 item += x;
95
96 // Return the item
97 return item;
98}
99
100/**
101 * Get a integer
102 *
103 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
104 * @param uri the uri
105 * @param arguments the arguments
106 * @return the integer
107 */
108int aidaRequestInteger(JNIEnv* env, const char* uri, Arguments arguments)
109{
110 // Only for attribute04
111 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute04")) {
113 }
114
115 int item = 4;
116
117 // Optional Arguments
118 int x = 0;
119 ascanf(env, &arguments, "%od", "x", &x);
120 item += x;
121
122 // Return the item
123 return item;
124}
125
126/**
127 * Get a long
128 *
129 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
130 * @param uri the uri
131 * @param arguments the arguments
132 * @return the long
133 */
134long aidaRequestLong(JNIEnv* env, const char* uri, Arguments arguments)
135{
136 // Only for attribute05
137 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute05")) {
139 }
140
141 long item = 5;
142
143 // Optional Arguments
144 long x = 0;
145 ascanf(env, &arguments, "%old", "x", &x);
146 item += x;
147
148 // Return the item
149 return item;
150}
151
152/**
153 * Get a float
154 *
155 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
156 * @param uri the uri
157 * @param arguments the arguments
158 * @return the float
159 */
160float aidaRequestFloat(JNIEnv* env, const char* uri, Arguments arguments)
161{
162 // Only for attribute06
163 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute06")) {
165 }
166
167 float item = 6.6f;
168
169 // Optional Arguments
170 float x = 1.0f;
171 ascanf(env, &arguments, "%of", "x", &x);
172 item *= x;
173
174 // Return the item
175 return item;
176}
177
178/**
179 * Get a double
180 *
181 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
182 * @param uri the uri
183 * @param arguments the arguments
184 * @return the double
185 */
186double aidaRequestDouble(JNIEnv* env, const char* uri, Arguments arguments)
187{
188 // Only for attribute07
189 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute07")) {
191 }
192
193 double item = 7.7;
194
195 // Optional Arguments
196 double x = 1.0;
197 ascanf(env, &arguments, "%olf", "x", &x);
198 item *= x;
199
200 // Return the item
201 return item;
202}
203
204/**
205 * Get a string. Allocate memory for string and it will be freed for you by framework
206 *
207 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
208 * @param uri the uri
209 * @param arguments the arguments
210 * @return the string
211 */
212char* aidaRequestString(JNIEnv* env, const char* uri, Arguments arguments)
213{
214 // Only for attribute08
215 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute08")) {
217 return NULL;
218 }
219
220 char* item;
221 char* data = "eight";
222
223 // Optional Arguments
224 char* x = "";
225 ascanf(env, &arguments, "%os", "x", &x);
226
227 // allocate and return
228 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, item, strlen(data) + strlen(x) + 3, "string", NULL)
229
230 if (!strlen(x)) {
231 sprintf(item, "%s", data);
232 } else {
233 sprintf(item, "%s: %s", data, x);
234 }
235 free(x);
236
237 // Return the item
238 return item;
239}
240
241/**
242 * Get a boolean array
243 *
244 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
245 * @param uri the uri
246 * @param arguments the arguments
247 * @return the boolean array
248 */
249Array aidaRequestBooleanArray(JNIEnv* env, const char* uri, Arguments arguments)
250{
251 // Only for attribute11
252 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute11")) {
254 }
255
256 Array booleanArray;
257 booleanArray.count = 1;
258 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, booleanArray.items, sizeof(unsigned char), "boolean array", booleanArray)
259 ((unsigned char*)(booleanArray.items))[0] = 1;
260
261 // Optional Arguments
262 unsigned char* x;
263 unsigned int count = 0;
264 if (!ascanf(env, &arguments, "%oba", "x", &x, &count) && count) {
265 free(booleanArray.items);
266 booleanArray.count = (int)count;
267 booleanArray.items = x;
268 }
269
270 // Return the boolean array
271 return booleanArray;
272}
273
274/**
275 * Get a byte array
276 *
277 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
278 * @param uri the uri
279 * @param arguments the arguments
280 * @return the byte array
281 */
282Array aidaRequestByteArray(JNIEnv* env, const char* uri, Arguments arguments)
283{
284 // Only for attribute12
285 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute12")) {
287 }
288
289 Array byteArray;
290 byteArray.count = 1;
291 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, byteArray.items, sizeof(unsigned char), "byte array", byteArray)
292 ((unsigned char*)(byteArray.items))[0] = 12;
293
294 // Optional Arguments
295 unsigned char* x;
296 unsigned int count = 0;
297 if (!ascanf(env, &arguments, "%oca", "x", &x, &count) && count) {
298 free(byteArray.items);
299 byteArray.count = (int)count;
300 byteArray.items = x;
301 for (int i = 0; i < count; i++) {
302 x[i] |= 12;
303 }
304 }
305
306 // Return the byte array
307 return byteArray;
308}
309
310/**
311 * Get a short array
312 *
313 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
314 * @param uri the uri
315 * @param arguments the arguments
316 * @return the short array
317 */
318Array aidaRequestShortArray(JNIEnv* env, const char* uri, Arguments arguments)
319{
320 // Only for attribute13
321 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute13")) {
323 }
324
325 Array shortArray;
326 shortArray.count = 1;
327 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, shortArray.items, sizeof(short), "short array", shortArray)
328 ((short*)(shortArray.items))[0] = 13;
329
330 // Optional Arguments
331 short* x;
332 unsigned int count = 0;
333 if (!ascanf(env, &arguments, "%ohda", "x", &x, &count) && count) {
334 free(shortArray.items);
335 shortArray.count = (int)count;
336 shortArray.items = x;
337 for (int i = 0; i < count; i++) {
338 x[i] += 13;
339 }
340 }
341
342 // Return the short array
343 return shortArray;
344}
345
346/**
347 * Get a integer array
348 *
349 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
350 * @param uri the uri
351 * @param arguments the arguments
352 * @return the integer array
353 */
354Array aidaRequestIntegerArray(JNIEnv* env, const char* uri, Arguments arguments)
355{
356 // Only for attribute14
357 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute14")) {
359 }
360
361 Array integerArray;
362 integerArray.count = 1;
363 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, integerArray.items, sizeof(int), "integer array", integerArray)
364 ((int*)(integerArray.items))[0] = 14;
365
366 // Optional Arguments
367 int* x;
368 unsigned int count = 0;
369 if (!ascanf(env, &arguments, "%oda", "x", &x, &count) && count) {
370 free(integerArray.items);
371 integerArray.count = (int)count;
372 integerArray.items = x;
373 for (int i = 0; i < count; i++) {
374 x[i] += 14;
375 }
376 }
377
378 // Return the integer array
379 return integerArray;
380}
381
382/**
383 * Get a long array
384 *
385 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
386 * @param uri the uri
387 * @param arguments the arguments
388 * @return the long array
389 */
390Array aidaRequestLongArray(JNIEnv* env, const char* uri, Arguments arguments)
391{
392 // Only for attribute15
393 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute15")) {
395 }
396
397 Array longArray;
398 longArray.count = 1;
399 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, longArray.items, sizeof(long), "long array", longArray)
400 ((long*)(longArray.items))[0] = 15l;
401
402 // Optional Arguments
403 long* x;
404 unsigned int count = 0;
405 if (!ascanf(env, &arguments, "%olda", "x", &x, &count) && count) {
406 free(longArray.items);
407 longArray.count = (int)count;
408 longArray.items = x;
409 for (int i = 0; i < count; i++) {
410 x[i] += 15l;
411 }
412 }
413
414 // Return the long array
415 return longArray;
416}
417
418/**
419 * Get a float array
420 *
421 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
422 * @param uri the uri
423 * @param arguments the arguments
424 * @return the float array
425 */
426Array aidaRequestFloatArray(JNIEnv* env, const char* uri, Arguments arguments)
427{
428 // Only for attribute16
429 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute16")) {
431 }
432
433 Array floatArray;
434 floatArray.count = 1;
435 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, floatArray.items, sizeof(float), "float array", floatArray)
436 ((float*)(floatArray.items))[0] = 16.6f;
437
438 // Optional Arguments
439 float* x;
440 unsigned int count = 0;
441 if (!ascanf(env, &arguments, "%ofa", "x", &x, &count) && count) {
442 free(floatArray.items);
443 floatArray.count = (int)count;
444 floatArray.items = x;
445 for (int i = 0; i < count; i++) {
446 x[i] *= 16.6f;
447 }
448 }
449
450 // Return the float array
451 return floatArray;
452}
453
454/**
455 * Get a double array
456 *
457 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
458 * @param uri the uri
459 * @param arguments the arguments
460 * @return the double array
461 */
462Array aidaRequestDoubleArray(JNIEnv* env, const char* uri, Arguments arguments)
463{
464 // Only for attribute17
465 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute17")) {
467 }
468
469 Array doubleArray;
470 doubleArray.count = 1;
471 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, doubleArray.items, sizeof(double), "double array", doubleArray)
472 ((double*)(doubleArray.items))[0] = 17.7;
473
474 // Optional Arguments
475 double* x;
476 unsigned int count = 0;
477 if (!ascanf(env, &arguments, "%olfa", "x", &x, &count) && count) {
478 free(doubleArray.items);
479 doubleArray.count = (int)count;
480 doubleArray.items = x;
481 for (int i = 0; i < count; i++) {
482 x[i] *= 17.7;
483 }
484 }
485
486 // Return the double array
487 return doubleArray;
488}
489
490/**
491 * Get a string array
492 *
493 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
494 * @param uri the uri
495 * @param arguments the arguments
496 * @return the string array
497 */
498StringArray aidaRequestStringArray(JNIEnv* env, const char* uri, Arguments arguments)
499{
500 // Only for attribute18
501 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute18")) {
503 }
504
505 StringArray stringArray;
506 stringArray.count = 1;
507 ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(env, stringArray.items, sizeof(char*), "string array", stringArray);
508 ALLOCATE_STRING_AND_ON_ERROR_RETURN_(env, stringArray.items[0], "eighteen", "string in string array", stringArray);
509
510 // Optional Arguments
511 char** x;
512 unsigned int count = 0;
513 if (!ascanf(env, &arguments, "%osa", "x", &x, &count) && count) {
514 free(stringArray.items);
515 stringArray.count = (int)count;
516 stringArray.items = x;
517 }
518
519 // Return the string array
520 return stringArray;
521}
522
523/**
524 * Get a table of data
525 *
526 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
527 * @param uri the uri
528 * @param arguments the arguments
529 * @return the table
530 */
531Table aidaRequestTable(JNIEnv* env, const char* uri, Arguments arguments)
532{
533 // Only for attribute20
534 if (!endsWith(uri, ":attribute32") && !endsWith(uri, ":attribute20")) {
537 }
538
539 // Optional Arguments
540 unsigned char xBoolean = 0x1, xByte = 0;
541 short xShort = 0;
542 int xInteger = 0;
543 long xLong = 0;
544 float xFloat = 1.0f;
545 double xDouble = 1.0;
546 char* xString = NULL;
547 if (ascanf(env, &arguments, "%ob %oc %ohd %od %old %of %olf %os",
548 "x.boolean", &xBoolean,
549 "x.byte", &xByte,
550 "x.short", &xShort,
551 "x.integer", &xInteger,
552 "x.long", &xLong,
553 "x.float", &xFloat,
554 "x.double", &xDouble,
555 "x.string", &xString)) {
557 }
558
559 Table table = tableCreate(env, 1, 8);
561 tableAddSingleRowBooleanColumn(env, &table, xBoolean);
563 tableAddSingleRowByteColumn(env, &table, 2 | xByte);
565 tableAddSingleRowShortColumn(env, &table, (short)(3 + xShort));
567 tableAddSingleRowIntegerColumn(env, &table, 4 + xInteger);
569 tableAddSingleRowLongColumn(env, &table, 5 + xLong);
571 tableAddSingleRowFloatColumn(env, &table, 6.6f * xFloat, true);
573 tableAddSingleRowDoubleColumn(env, &table, 7.7 * xDouble, true);
575 tableAddSingleRowStringColumn(env, &table, xString ? xString : "eight");
576
577 // Return the table
578 return table;
579}
580
581/**
582 * Set a value
583 *
584 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
585 * @param uri the uri
586 * @param arguments the arguments
587 * @param value to set
588 */
589void aidaSetValue(JNIEnv* env, const char* uri, Arguments arguments, Value value)
590{
591}
592
593/**
594 * Set a value and return a table as a response
595 *
596 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
597 * @param uri the uri
598 * @param arguments the arguments
599 * @param value to set
600 * @return a table
601 */
602Table aidaSetValueWithResponse(JNIEnv* env, const char* uri, Arguments arguments, Value value)
603{
604 // Mandatory Value Argument
605 unsigned char v;
606 avscanf(env, &arguments, &value, "%b", "value", &v);
607
608 Table table = tableCreate(env, 1, 1);
610 tableAddSingleRowBooleanColumn(env, &table, v);
611
612 // Return the table
613 return table;
614}
615
Array aidaRequestIntegerArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a integer array.
Table aidaSetValueWithResponse(JNIEnv *env, const char *uri, Arguments arguments, Value value)
Set a value and return a table as a response.
void aidaSetValue(JNIEnv *env, const char *uri, Arguments arguments, Value value)
Set a value.
char * aidaRequestString(JNIEnv *env, const char *uri, Arguments arguments)
Get a string.
float aidaRequestFloat(JNIEnv *env, const char *uri, Arguments arguments)
Get a float.
Table aidaRequestTable(JNIEnv *env, const char *uri, Arguments arguments)
Get a table of data.
Array aidaRequestLongArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a long array.
Array aidaRequestDoubleArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a double array.
StringArray aidaRequestStringArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a string array.
int aidaRequestInteger(JNIEnv *env, const char *uri, Arguments arguments)
Get a integer.
Array aidaRequestShortArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a short array.
Array aidaRequestBooleanArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a boolean array.
Array aidaRequestFloatArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a float array.
double aidaRequestDouble(JNIEnv *env, const char *uri, Arguments arguments)
Get a double.
void aidaServiceInit(JNIEnv *env)
Initialise the service.
Array aidaRequestByteArray(JNIEnv *env, const char *uri, Arguments arguments)
Get a byte array.
short aidaRequestShort(JNIEnv *env, const char *uri, Arguments arguments)
Get a short.
char aidaRequestByte(JNIEnv *env, const char *uri, Arguments arguments)
Get a byte.
int aidaRequestBoolean(JNIEnv *env, const char *uri, Arguments arguments)
Get a boolean.
long aidaRequestLong(JNIEnv *env, const char *uri, Arguments arguments)
Get a long.
The Header File for the AIDA-PVA Module functions.
#define VERSION(_version)
Use this macro to define the version of the provider.
Definition: aida_pva_api.h:40
#define RETURN_NULL_TABLE
Return an empty table response.
Definition: aida_pva_api.h:380
#define UNSUPPORTED_CHANNEL_EXCEPTION
Use this string to signal Unsupported Channel Exceptions in aidaThrow()
#define ON_EXCEPTION_RETURN_(_r)
Check to see if an exception has been raised, and return the given return value.
#define ALLOCATE_STRING_AND_ON_ERROR_RETURN_(_env, _var, _string, _purpose, _r)
Allocate memory for a string and copy the given string into this allocated space.
#define ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_(_env, _var, _size, _purpose, _r)
Allocate memory and on error return the given value.
int endsWith(const char *str, char *suffix)
Check if a string str, ends with another string suffix.
void aidaThrowNonOsException(JNIEnv *env, char *exception, const char *message)
To log any non-OS exceptions and throw back to java.
void tableAddSingleRowFloatColumn(JNIEnv *env, Table *table, float data, bool ieeeFloat)
Add a float column to a Table with only one row.
int ascanf(JNIEnv *env, Arguments *arguments, const char *formatString,...)
ascanf(), avscanf()
void tableAddSingleRowLongColumn(JNIEnv *env, Table *table, long data)
Add a long column to a Table with only one row.
Table tableCreate(JNIEnv *env, int rows, int columns)
Make a Table for return to client.
void tableAddSingleRowIntegerColumn(JNIEnv *env, Table *table, int data)
Add a integer column to a Table with only one row.
void tableAddSingleRowShortColumn(JNIEnv *env, Table *table, short data)
Add a short column to a Table with only one row.
void tableAddSingleRowByteColumn(JNIEnv *env, Table *table, unsigned char data)
Add a byte column to a Table with only one row.
void tableAddSingleRowDoubleColumn(JNIEnv *env, Table *table, double data, bool ieeeDouble)
Add a double column to a Table with only one row.
void tableAddSingleRowBooleanColumn(JNIEnv *env, Table *table, unsigned char data)
Add a boolean column to a Table with only one row.
int avscanf(JNIEnv *env, Arguments *arguments, Value *value, const char *formatString,...)
ascanf(), avscanf()
void tableAddSingleRowStringColumn(JNIEnv *env, Table *table, char *data)
Add a string column to a Table with only one row.
An Arguments structure stores all of the arguments passed from the request to the Native Channel Prov...
An array of data.
void * items
The items in this array.
int count
The number of items in this array.
An array of string data.
int count
The number of items in this array.
char ** items
The items in this array - pointers to the strings you allocate.
Table structure.
This special type represents a Value.