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.h
Go to the documentation of this file.
1/** @file
2 * @brief The Header File for the AIDA-PVA Module functions.
3 * **CMS**=C_INC
4 */
5#ifndef aida_pva_h
6#define aida_pva_h
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include <stdio.h>
12#include <string.h>
13#include <stdlib.h>
14#include <ctype.h> /* isalnum, ispunct */
15
16#include <stsdef.h> /* Macros for handling VMS status */
17#include <stdbool.h>
18#include <stsdef.h> /* Macros for handling VMS status */
19#include <jni.h>
20
21#include "slc_macros.h"
22#include "msg_proto.h" /* for standalone_init */
23#include "errtranslate.h"
24#include "ref.h" /* passing by reference macros */
25#include "process_parm.h"
26
27#include "aida_pva_json.h"
28#include "aida_pva_types.h"
29#include "aida_pva_exceptions.h"
30#include "aida_pva_api.h"
31#include "aida_pva_convert.h"
32#include "aida_pva_memory.h"
33#include "aida_pva_uri.h"
34
35/////////////////////////////////
36/// Initialisation
37/////////////////////////////////
38
39/**
40 * Call standalone_init() and set development mode flag.
41 * @param processName the name of the process being initialised
42 * @param initMessageServices boolean to determine if the message service needs to be initialised
43 * @return vms status code
44 */
45vmsstat_t init(const char* processName, bool initMessageServices);
46
47/////////////////////////////////
48/// Exception Handling
49/////////////////////////////////
50
51/**
52 * To log any exceptions and throw back to java.
53 *
54 * The #exception is formatted in a standard way using the VMS status code and its associated message
55 * and the optionally supplied #message.
56 * The #exception is always assumed to be from the edu.stanford.slac.except package
57 *
58 * @param env the JNI environment. Used in all functions involving JNI
59 * @param status the VMS status code to luck up and display text for.
60 * @param exception the string representation of the exception class to throw.
61 * @param message the optional message to attach to the exception. If NULL it is ignored.
62 */
63void aidaThrow(JNIEnv* env, vmsstat_t status, char* exception, const char* message);
64
65/**
66 * To log any non-OS exceptions and throw back to java.
67 *
68 * The #exception is formatted in a standard way with the optionally supplied #message.
69 * The #exception is always assumed to be from the edu.stanford.slac.except package
70 *
71 * @param env the JNI environment. Used in all functions involving JNI
72 * @param exception the string representation of the exception class to throw.
73 * @param message the optional message to attach to the exception. If NULL it is ignored.
74 */
75void aidaThrowNonOsException(JNIEnv* env, char* exception, const char* message);
76
77/////////////////////////////////
78/// String Handling
79/////////////////////////////////
80
81/**
82 * Check if a string @p str, ends with another string @p suffix.
83 *
84 * @param str the string to check.
85 * @param suffix the @p suffix to look for at the end of @p str
86 * @return `true` if @p str ends with @p suffix. `false`
87 */
88int endsWith(const char* str, char* suffix);
89
90/**
91 * Check if a string starts with another string.
92 *
93 * @param str
94 * @param prefix
95 * @returns true if string starts with prefix
96 */
97int startsWith(const char* str, char* prefix);
98
99/////////////////////////////////
100/// URI Handling for group, secn, pmu and slacName
101/////////////////////////////////
102
103/**
104 * Get the Display group name from a URI.
105 *
106 * @param groupName pre-allocated space to store the group name
107 * @param uri the new format AIDA PV name
108 * @return EXIT_SUCCESS if all goes well EXIT_FAILURE otherwise
109 */
110int groupNameFromUri(char groupName[], const char* uri);
111
112/**
113 * Get secondary from pseudo secondary (containing a colon) number from URI.
114 * e.g. `BD01:BEND:BDES` => `BEND` as int4u
115 *
116 * @param uri the new format AIDA PV name
117 * @param secn pointer to an int to store the secondary as a number
118 */
119void secnFromUri(const char* uri, int4u* secn);
120
121/**
122 * Get secondary from URI. Just points into the URI so don't go messing with it.
123 *
124 * @param uri the new format AIDA PV name
125 */
126const char* secondaryFromUri(const char* uri);
127
128/**
129 * Get primary, micro and unit from a device name.
130 *
131 * @param env the JNI environment. Used in all functions involving JNI
132 * @param device pre-allocated space to store the device
133 * @param primary pre-allocated space to store the primary
134 * @param micro pre-allocated space to store the micro
135 * @param unit pre-allocated space to store the unit
136 */
137int pmuFromDeviceName(JNIEnv* env, char* device, char* primary, char* micro, int4u* unit);
138
139/**
140 * Get the pmu part of a URI.
141 *
142 * @param pmuString the pre-allocated space to store the pmu string
143 * @param uri the new format AIDA PV name
144 */
145void pmuStringFromUri(char* pmuString, const char* uri);
146
147/**
148 * Convert all URIs to slac names before making queries.
149 *
150 * @param slcName pointer to space to store the SLC name
151 * @param uri the new format AIDA PV name
152 */
153void uriToSlcName(char slcName[MAX_URI_LEN], const char* uri);
154
155/**
156 * Convert the given URI to the legacy AIDA name for low level functions that still require it that way.
157 *
158 * @param legacyName pointer to space to store the legacy AIDA name
159 * @param uri the new format AIDA PV name
160 */
161void uriLegacyName(char legacyName[MAX_URI_LEN], const char* uri);
162
163/////////////////////////////////
164/// Memory Handling
165/////////////////////////////////
166/**
167 * Allocate memory and copy the source to it if specified. If the null terminate flag is set
168 * null terminate the allocate space, at the last position
169 *
170 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
171 * @param source source of data to copy to newly allocated space, NULL to not copy
172 * @param size the amount of space to allocate
173 * @param nullTerminate true to null terminate
174 * @param message the message to display if anything goes wrong
175 * @return the allocated memory
176 */
177void* allocateMemory(JNIEnv* env, void* source, size_t size, bool nullTerminate, char* message);
178
179/**
180 * Free up any memory allocated for the given pv and arguments.
181 *
182 * @param arguments the given arguments
183 */
184void releasePvAndArguments(JNIEnv* env, jstring uri, const char* pv, Arguments arguments);
185
186/**
187 * Free up any memory allocated the given scalar array.
188 *
189 * @param array the given scalar array
190 */
191void releaseArray(Array array);
192
193/**
194 * Free up any memory allocated for string arrays.
195 *
196 * @param array
197 */
199
200/**
201 * Free up any memory allocated for the given table.
202 *
203 * @param table the given tables
204 */
205void releaseTable(Table table);
206
207/**
208 * Release all allocated memory in the given value.
209 *
210 * @param value the given value'
211 */
212void releaseValue(Value value);
213
214
215/////////////////////////////////
216/// Table Handling
217/////////////////////////////////
218
219/**
220 * Make a Table for return to client. This is the first call that needs to be made to return a Table.
221 * This will create a Table with the specified the number of rows and columns.
222 * You need to call tableAddColumn(), tableAddStringColumn(), or any of the
223 * other special `tableAdd` functions to add
224 * columns to the Table before returning it.
225 *
226 * @param env The JNI environment. Used in all functions involving JNI.
227 * @param rows the number of rows to create the Table with.
228 * @param columns the number of columns to create the Table with,
229 * @return the newly created Table
230 *
231 * @see
232 * tableAddColumn(),
233 * tableAddStringColumn()
234 * tableAddFixedWidthStringColumn(),
235 * tableAddSingleRowBooleanColumn(),
236 * tableAddSingleRowByteColumn(),
237 * tableAddSingleRowShortColumn(),
238 * tableAddSingleRowIntegerColumn(),
239 * tableAddSingleRowLongColumn(),
240 * tableAddSingleRowFloatColumn(),
241 * tableAddSingleRowDoubleColumn(),
242 * tableAddSingleRowStringColumn(),
243 *
244 * @paragraph Example
245 *
246 * Create a two column, two row Table, add data, and return.
247 * @code
248 * int rows = 2, columns = 2;
249 * float xData[rows] = { 1.0f, 2.0f }, yData[rows] = { 7.0f, 8.0f };
250 *
251 * Table table = tableCreate(env, rows, columns);
252 * ON_EXCEPTION_RETURN_(table)
253 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, xData, true);
254 * ON_EXCEPTION_RETURN_(table)
255 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, yData, true);
256 * ON_EXCEPTION_RETURN_(table)
257 * return table;
258 * @endcode
259 * @note
260 * You need to call ON_EXCEPTION_RETURN_(table) after each call to make
261 * sure that no exception was raised.
262 */
263Table tableCreate(JNIEnv* env, int rows, int columns);
264
265/**
266 * Make a Dynamic Table for return to client. This is the first call that needs to be made to return a Dynamic Table.
267 * This will create a Table with the specified the number of rows and columns.
268 * You need to call tableAddColumn(), tableAddStringColumn(), tableAddField(), tableAddLabel(), or any of the
269 * other special `tableAdd` functions to add
270 * columns to the Table before returning it. Calling tableAddField(), and tableAddLabel() are mandatory
271 *
272 * @param env The JNI environment. Used in all functions involving JNI.
273 * @param rows the number of rows to create the Table with.
274 * @param columns the number of columns to create the Table with,
275 * @return the newly created Table
276 *
277 * @see
278 * tableAddColumn(),
279 * tableAddField(),
280 * tableAddLabel(),
281 * tableAddStringColumn()
282 * tableAddFixedWidthStringColumn(),
283 * tableAddSingleRowBooleanColumn(),
284 * tableAddSingleRowByteColumn(),
285 * tableAddSingleRowShortColumn(),
286 * tableAddSingleRowIntegerColumn(),
287 * tableAddSingleRowLongColumn(),
288 * tableAddSingleRowFloatColumn(),
289 * tableAddSingleRowDoubleColumn(),
290 * tableAddSingleRowStringColumn(),
291 *
292 * @paragraph Example
293 *
294 * Create a two column, two row Table, Set Field names, and labels, add data, and return.
295 * @code
296 * int rows = 2, columns = 2;
297 * float xData[rows] = { 1.0f, 2.0f }, yData[rows] = { 7.0f, 8.0f };
298 * char *fields[columns] = { "field1", "field2" };
299 * char *labels[columns] = { "label1", "label2" };
300 *
301 * Table table = tableCreateDynamic(env, rows, columns);
302 * ON_EXCEPTION_RETURN_(table)
303 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, xData, true);
304 * ON_EXCEPTION_RETURN_(table)
305 * tableAddField(env, &table, fields[0]);
306 * ON_EXCEPTION_RETURN_(table)
307 * tableAddLabel(env, &table, labels[0]);
308 * ON_EXCEPTION_RETURN_(table)
309 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, yData, true);
310 * ON_EXCEPTION_RETURN_(table)
311 * tableAddField(env, &table, fields[1]);
312 * ON_EXCEPTION_RETURN_(table)
313 * tableAddLabel(env, &table, labels[1]);
314 * ON_EXCEPTION_RETURN_(table)
315 * return table;
316 * @endcode
317 * @note
318 * You need to call ON_EXCEPTION_RETURN_(table) after each call to make
319 * sure that no exception was raised.
320 */
321Table tableCreateDynamic(JNIEnv* env, int rows, int columns);
322
323/**
324 * Add a column of arbitrary type to a Table. Add the given data to the
325 * column assuming that the data has a number of rows that corresponds to the
326 * Table's rowCount. Memory will be allocated for the data of the column so
327 * the @p data buffer presented can be freed up after calling this function.
328 *
329 * @note
330 * Don't call this to add strings to the Table. Use tableAddStringColumn() for that.
331 *
332 * The framework will release all memory associated with
333 * a Table when you return from your API implementation.
334 *
335 * @param env The JNI environment. Used in all functions involving JNI.
336 * @param table the Table to add the column to.
337 * @param type the type of this Table column.
338 * @param data the data to add to this column, a buffer of `sizeof(type) * table->rowCount` size.
339 * @param ieeeFormat true if the data provided is already in ieee format. If the data is not in ieee format,
340 * usually because it has been retrieved from some backend system, this function will convert it to ieee format
341 * unless this parameter is set to true.
342 *
343 * @see
344 * tableCreate(),
345 * tableAddStringColumn()
346 * tableAddFixedWidthStringColumn(),
347 * tableAddSingleRowBooleanColumn(),
348 * tableAddSingleRowByteColumn(),
349 * tableAddSingleRowShortColumn(),
350 * tableAddSingleRowIntegerColumn(),
351 * tableAddSingleRowLongColumn(),
352 * tableAddSingleRowFloatColumn(),
353 * tableAddSingleRowDoubleColumn(),
354 * tableAddSingleRowStringColumn(),
355 *
356 * @paragraph Example
357 *
358 * Create a two column, two row Table, add data, and return.
359 * @code
360 * int rows = 2, columns = 2;
361 * float xData[rows] = { 1.0f, 2.0f }, yData[rows] = { 7.0f, 8.0f };
362 *
363 * Table table = tableCreate(env, rows, columns);
364 * ON_EXCEPTION_RETURN_(table)
365 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, xData, true);
366 * ON_EXCEPTION_RETURN_(table)
367 * tableAddColumn(env, &table, AIDA_FLOAT_TYPE, yData, true);
368 * ON_EXCEPTION_RETURN_(table)
369 * return table;
370 * @endcode
371 * @note
372 * You need to call ON_EXCEPTION_RETURN_(table) after each call to make
373 * sure that no exception was raised.
374 */
375void tableAddColumn(JNIEnv* env, Table* table, Type type, void* data, bool ieeeFormat);
376
377/**
378 * Add a dynamic field to a table.
379 *
380 * @see tableCreateDynamic
381 *
382 * @param env The JNI environment. Used in all functions involving JNI.
383 * @param table the Table to add the column to.
384 * @param fieldName The name of the field to add
385 */
386void tableAddField(JNIEnv* env, Table* table, char* fieldName);
387
388/**
389 * Add a dynamic column to a table
390 *
391 * @see tableCreateDynamic
392 *
393 * @param env The JNI environment. Used in all functions involving JNI.
394 * @param table the Table to add the column to.
395 * @param labelName the label name to add
396 */
397void tableAddLabel(JNIEnv* env, Table* table, char* labelName);
398
399/**
400 * Add a String column to the given Table.
401 * This reads data from a buffer that is itself a list of pointers to strings.
402 * We allocate just enough space to store the strings in our Table. This is allocated
403 * in one buffer so there is only one pointer to release.
404 *
405 * @note
406 * The framework will release all memory associated with
407 * a Table when you return from your API implementation.
408 *
409 * @param env The JNI environment. Used in all functions involving JNI.
410 * @param table the Table to add the string column to.
411 * @param data the data to add to this column, a buffer of `sizeof(char *) * table->rowCount` size.
412 * This will contain the strings to be added to the Table.
413 *
414 * @see
415 * tableCreate(),
416 * tableAddColumn(),
417 * tableAddFixedWidthStringColumn(),
418 * tableAddSingleRowBooleanColumn(),
419 * tableAddSingleRowByteColumn(),
420 * tableAddSingleRowShortColumn(),
421 * tableAddSingleRowIntegerColumn(),
422 * tableAddSingleRowLongColumn(),
423 * tableAddSingleRowFloatColumn(),
424 * tableAddSingleRowDoubleColumn(),
425 * tableAddSingleRowStringColumn(),
426 *
427 * @paragraph Example
428 *
429 * Create a single column, one row Table, add data, and return.
430 * @code
431 * int rows = 1, columns = 1;
432 * char* namesData[rows];
433 * namesData[0] = "NAME";
434 *
435 * Table table = tableCreate(env, rows, columns);
436 * ON_EXCEPTION_RETURN_(table)
437 * tableAddStringColumn(env, &table, namesData);
438 * ON_EXCEPTION_RETURN_(table)
439 * return table;
440 * @endcode
441 * @note
442 * You need to call ON_EXCEPTION_RETURN_(table) after each call to make
443 * sure that no exception was raised.
444 */
445void tableAddStringColumn(JNIEnv* env, Table* table, char** data);
446
447/**
448 * Add fixed-width string data to a column in the given Table.
449 * This reads data from an allocated space that is rows * width with each string occupying width characters
450 * Though the strings are null terminated if there is space, there is no guarantee so an exact number of
451 * bytes is copied. Each string in the Table is allocated maximally.
452 *
453 * @note
454 * The framework will release all memory associated with
455 * a Table when you return from your API implementation.
456 *
457 * @param env The JNI environment. Used in all functions involving JNI.
458 * @param table The Table to add the column to.
459 * @param data The data to add to this column, a pointer to `char` buffer containing
460 * the fixed length strings. The strings are arranged in
461 * contiguous blocks @p width long.
462 * @param width the width of the strings
463 *
464 * @see
465 * tableCreate(),
466 * tableAddColumn(),
467 * tableAddStringColumn()
468 * tableAddSingleRowBooleanColumn(),
469 * tableAddSingleRowByteColumn(),
470 * tableAddSingleRowShortColumn(),
471 * tableAddSingleRowIntegerColumn(),
472 * tableAddSingleRowLongColumn(),
473 * tableAddSingleRowFloatColumn(),
474 * tableAddSingleRowDoubleColumn(),
475 * tableAddSingleRowStringColumn(),
476 */
477void tableAddFixedWidthStringColumn(JNIEnv* env, Table* table, char* data, int width);
478
479/**
480 * Add a boolean column to a Table with only one row. This function will allocate
481 * the required memory for the single `unsigned char` that is required.
482 *
483 * @note
484 * The framework will release all memory associated with
485 * a Table when you return from your API implementation.
486 *
487 * @param env The JNI environment. Used in all functions involving JNI.
488 * @param table The Table to add the column to.
489 * @param data The data to add to this column, a pointer to an `unsigned char`.
490 *
491 * @see
492 * tableCreate(),
493 * tableAddColumn(),
494 * tableAddStringColumn()
495 * tableAddFixedWidthStringColumn(),
496 * tableAddSingleRowByteColumn(),
497 * tableAddSingleRowShortColumn(),
498 * tableAddSingleRowIntegerColumn(),
499 * tableAddSingleRowLongColumn(),
500 * tableAddSingleRowFloatColumn(),
501 * tableAddSingleRowDoubleColumn(),
502 * tableAddSingleRowStringColumn(),
503 */
504void tableAddSingleRowBooleanColumn(JNIEnv* env, Table* table, unsigned char data);
505
506/**
507 * Add a byte column to a Table with only one row.
508 *
509 * @note
510 * The framework will release all memory associated with
511 * a Table when you return from your API implementation.
512 *
513 * @param env The JNI environment. Used in all functions involving JNI.
514 * @param table The Table to add the column to.
515 * @param data The data to add to this column, an `unsigned char`.
516 *
517 * @see
518 * tableCreate(),
519 * tableAddColumn(),
520 * tableAddStringColumn()
521 * tableAddFixedWidthStringColumn(),
522 * tableAddSingleRowBooleanColumn(),
523 * tableAddSingleRowShortColumn(),
524 * tableAddSingleRowIntegerColumn(),
525 * tableAddSingleRowLongColumn(),
526 * tableAddSingleRowFloatColumn(),
527 * tableAddSingleRowDoubleColumn(),
528 * tableAddSingleRowStringColumn(),
529 */
530void tableAddSingleRowByteColumn(JNIEnv* env, Table* table, unsigned char data);
531
532/**
533 * Add a short column to a Table with only one row.
534 *
535 * @note
536 * The framework will release all memory associated with
537 * a Table when you return from your API implementation.
538 *
539 * @param env The JNI environment. Used in all functions involving JNI.
540 * @param table The Table to add the column to.
541 * @param data The data to add to this column, a `short`.
542 *
543 * @see
544 * tableCreate(),
545 * tableAddColumn(),
546 * tableAddStringColumn()
547 * tableAddFixedWidthStringColumn(),
548 * tableAddSingleRowBooleanColumn(),
549 * tableAddSingleRowByteColumn(),
550 * tableAddSingleRowIntegerColumn(),
551 * tableAddSingleRowLongColumn(),
552 * tableAddSingleRowFloatColumn(),
553 * tableAddSingleRowDoubleColumn(),
554 * tableAddSingleRowStringColumn(),
555 */
556void tableAddSingleRowShortColumn(JNIEnv* env, Table* table, short data);
557
558/**
559 * Add a integer column to a Table with only one row.
560 *
561 * @note
562 * The framework will release all memory associated with
563 * a Table when you return from your API implementation.
564 *
565 * @param env The JNI environment. Used in all functions involving JNI.
566 * @param table the Table to add the column to.
567 * @param data the data to add to this column, an `int`
568 *
569 * @see
570 * tableCreate(),
571 * tableAddColumn(),
572 * tableAddStringColumn()
573 * tableAddFixedWidthStringColumn(),
574 * tableAddSingleRowBooleanColumn(),
575 * tableAddSingleRowByteColumn(),
576 * tableAddSingleRowShortColumn(),
577 * tableAddSingleRowLongColumn(),
578 * tableAddSingleRowFloatColumn(),
579 * tableAddSingleRowDoubleColumn(),
580 * tableAddSingleRowStringColumn(),
581 */
582void tableAddSingleRowIntegerColumn(JNIEnv* env, Table* table, int data);
583
584/**
585 * Add a long column to a Table with only one row.
586 *
587 *
588 * @note
589 * The framework will release all memory associated with
590 * a Table when you return from your API implementation.
591 *
592 * @param env The JNI environment. Used in all functions involving JNI.
593 * @param table the Table to add the column to.
594 * @param data the data to add to this column. A `long` value
595 *
596 * @see
597 * tableCreate(),
598 * tableAddColumn(),
599 * tableAddStringColumn()
600 * tableAddFixedWidthStringColumn(),
601 * tableAddSingleRowBooleanColumn(),
602 * tableAddSingleRowByteColumn(),
603 * tableAddSingleRowShortColumn(),
604 * tableAddSingleRowIntegerColumn(),
605 * tableAddSingleRowFloatColumn(),
606 * tableAddSingleRowDoubleColumn(),
607 * tableAddSingleRowStringColumn(),
608 */
609void tableAddSingleRowLongColumn(JNIEnv* env, Table* table, long data);
610
611/**
612 * Add a float column to a Table with only one row.
613 *
614 * @note
615 * The framework will release all memory associated with
616 * a Table when you return from your API implementation.
617 *
618 * @param env The JNI environment. Used in all functions involving JNI.
619 * @param table The Table to add the column to.
620 * @param data The data to add to this column, a `float`.
621 * @param ieeeFloat True if the data is in ieee format, otherwise the given floating point
622 * number is converted from VMS to ieee format.
623 *
624 * @see
625 * tableCreate(),
626 * tableAddColumn(),
627 * tableAddStringColumn()
628 * tableAddFixedWidthStringColumn(),
629 * tableAddSingleRowBooleanColumn(),
630 * tableAddSingleRowByteColumn(),
631 * tableAddSingleRowShortColumn(),
632 * tableAddSingleRowIntegerColumn(),
633 * tableAddSingleRowLongColumn(),
634 * tableAddSingleRowDoubleColumn(),
635 * tableAddSingleRowStringColumn(),
636 */
637void tableAddSingleRowFloatColumn(JNIEnv* env, Table* table, float data, bool ieeeFloat);
638
639/**
640 * Add a double column to a Table with only one row.
641 *
642 * @note
643 * The framework will release all memory associated with
644 * a Table when you return from your API implementation.
645 *
646 * @param env The JNI environment. Used in all functions involving JNI.
647 * @param table The Table to add the column to.
648 * @param data The data to add to this column, a `double`.
649 * @param ieeeDouble True if the data is in ieee format, otherwise the double precision floating point
650 * number is converted from VMS to ieee format.
651 *
652 * @see
653 * tableCreate(),
654 * tableAddColumn(),
655 * tableAddStringColumn()
656 * tableAddFixedWidthStringColumn(),
657 * tableAddSingleRowBooleanColumn(),
658 * tableAddSingleRowByteColumn(),
659 * tableAddSingleRowShortColumn(),
660 * tableAddSingleRowIntegerColumn(),
661 * tableAddSingleRowLongColumn(),
662 * tableAddSingleRowFloatColumn(),
663 * tableAddSingleRowStringColumn(),
664 */
665void tableAddSingleRowDoubleColumn(JNIEnv* env, Table* table, double data, bool ieeeDouble);
666
667/**
668 * Add a string column to a Table with only one row. This is a shortcut
669 * Table function that simplifies adding a string to a Table with only one row.
670 *
671 * @note
672 * The framework will release all memory associated with
673 * a Table when you return from your API implementation.
674 *
675 * @param env The JNI environment. Used in all functions involving JNI.
676 * @param table the Table to add the column to.
677 * @param data the data to add to this column. A single string.
678 *
679 * @see
680 * tableCreate(),
681 * tableAddColumn(),
682 * tableAddStringColumn()
683 * tableAddFixedWidthStringColumn(),
684 * tableAddSingleRowBooleanColumn(),
685 * tableAddSingleRowByteColumn(),
686 * tableAddSingleRowShortColumn(),
687 * tableAddSingleRowIntegerColumn(),
688 * tableAddSingleRowLongColumn(),
689 * tableAddSingleRowFloatColumn(),
690 * tableAddSingleRowDoubleColumn(),
691 */
692void tableAddSingleRowStringColumn(JNIEnv* env, Table* table, char* data);
693
694/////////////////////////////////
695/// Argument Processing
696/////////////////////////////////
697
698/**
699 * ascanf(), avscanf()
700 *
701 * @paragraph Synopsis
702 * @code
703 * int ascanf(Arguments *arguments, const char *format, ...);
704 * int avscanf(Arguments *arguments, Value *value, const char *format, ...);
705 * @endcode
706 *
707 * @paragraph Details
708 * Reads data from the given @p arguments and stores them according
709 * to parameter format into the locations given by the additional arguments,
710 * as if scanf() was used, but reading from arguments instead of the standard input (stdin).
711 *
712 * @see avscanf() for full details.
713 *
714 * @param env The JNI environment. Used in all functions involving JNI
715 * @param arguments Arguments that the function processes as its source to retrieve the data.
716 * @param formatString C string that contains a format string as described above
717 * @param ... Depending on the format string, the function may expect a sequence of additional arguments,
718 * containing pairs of names and pointers to allocated storage (except as indicated above),
719 * where the interpretation of the extracted data is stored with the appropriate type.
720 * There should be at least as many pairs of these arguments as the number of values stored
721 * by the format specifiers.
722 * Additional arguments are ignored by the function
723 * @return `EXIT_SUCCESS` if all required arguments were read and no errors occurred, otherwise `EXIT_FAILURE`
724 * @throw MissingRequiredArgumentException if one of the required arguments are missing
725*/
726int ascanf(JNIEnv* env, Arguments* arguments, const char* formatString, ...);
727
728/**
729 * ascanf(), avscanf()
730 *
731 * @paragraph Synopsis
732 * @code
733 * int ascanf(Arguments *arguments, const char *format, ...);
734 * int avscanf(Arguments *arguments, Value *value, const char *format, ...);
735 * @endcode
736 *
737 * @paragraph Details
738 * Reads data from the given @p arguments and stores them according
739 * to parameter format into the locations given by the additional arguments,
740 * as if scanf() was used, but reading from arguments instead of the standard input (stdin).
741 *
742 * The additional arguments should point to already allocated objects of
743 * the type specified by their corresponding format specifier.
744 * For strings and arrays only the pointer needs to be pre-allocated.
745 *
746 * The only space allocated by this function is for the strings or arrays. So callers
747 * should only free strings and arrays. Even if you provide a default value for a string
748 * the pointer will be allocated memory on exit from the function, so even then you need to free it.
749 *
750 * @note
751 * Only the provided pointer needs to be freed as only one allocation is made e.g.
752 * @code
753 * Arguments arguments;
754 * int *intArray;
755 * ascanf(arguments "%da, "fooArray", &intArray);
756 * // Do stuff
757 * free(intArray);
758 * @endcode
759 *
760 * String space is allocated as follows:
761 * @code
762 * +------------------------+----------+----------+----------+---------+
763 * | pointers to strings | string 1 | string 2 | string 3 | ... |
764 * +------------------------+----------+----------+----------+---------+
765 * @endcode
766 *
767 * @paragraph dts Differences to scanf()
768 * ___
769 * There are a number of differences from scanf() which are best described by example:
770 *
771 * @paragraph gd General differences
772 * -# Scan into simple variable/
773 * @code
774 * int n;
775 * ascanf("%d", "NPOS", &n);
776 * @endcode
777 * You must always provide the name of the variable and the pointer to the place to put the value in pairs
778 * -# Optional arguments.
779 * Optional arguments are specified with the **o** character before the format character.
780 * @code
781 * short flag = 10; // 10 is the default value
782 * ascanf("%ohd", "flag", &flag);
783 * @endcode
784 *
785 * By default all arguments referenced by format specifications are considered required
786 * unless the format specification character is preceded by **o**.
787 * For optional arguments the pointer provided must point to the default value.
788 * In the case of arrays and strings this will be copied into allocated storage that
789 * will need to be freed as normal.
790 *
791 * @paragraph an Argument names
792 * -# You can specify simple argument names to search for. These will simply find the named argument and extract its value.
793 * @code
794 * int simpleInt;
795 * ascanf(&arguments "%d, "simple", &simpleInt);
796 * @endcode
797 * -# You can also use dot and square brace notation to refer to complex arguments that are either arrays or complex objects.
798 * Values that are buried deep inside the json structures can be referenced in this way. e.g., given a
799 * variable named `json` and presented as:
800 * @code
801 * json='{"foo": {"bar": 0}}}'
802 * @endcode
803 * You can specify the @p name as "json.foo.bar" to retrieve the `0` value.
804 * -# Also given a variable named `jsonArray` and presented as
805 * @code
806 * jsonArray='[{"foo": 10}, {"bar": 20}]'
807 * @endcode
808 * You can specify the #p name as "jsonArray[1].bar" to retrieve the `20` value.
809 * -# Finally if you use the @p name "value", then the avscanf() function
810 * will use the supplied @p value parameter to get the data for that parameter
811 * @code
812 * Arguments arguments;
813 * Value value;
814 * int *intArray;
815 * avscanf(&arguments &value, "%da, "fooArray", &intArray);
816 * // Do stuff
817 * free(intArray);
818 * @endcode
819 *
820 * @paragraph fs Format Specifiers
821 * ___
822 * @paragraph sfs Type specifiers
823 * - **b** : `unsigned char *` - interpret the input as a boolean, then extract a single byte into the corresponding variable.
824 * - The following translate to `true`
825 * - not `0` - integer, short, long,
826 * - not `0.0` - float, double
827 * - “true” - char string
828 * - “t” - char string
829 * - “yes” - char string
830 * - “y” - char string
831 * - `!0` - short, int, long, float, or double
832 * - The following translate to `false`
833 * - `0` - integer, short, long,
834 * - `0.0` - float, double
835 * - “false” - char string
836 * - “f”- char string
837 * - “no”- char string
838 * - “n”- char string
839 * - `0` - short, int, long, float, or double
840 * - **c** : `char *` - extract a single character into the corresponding variable.
841 * - **d** : `int *` - extract an integer into the corresponding variable (see **l** & **h** below).
842 * - **f** : `float *` - extract a floating point number (see **l** below).
843 * - **s** : `char *` - extract a string of characters into allocated space and point the corresponding variable to it.
844 * - **u** : `unsigned int *` - extract an unsigned integer into the corresponding variable (see **l** & **h** below).
845 *
846 * @paragraph rf Required flag
847 * - **o** - optional precede the format with this to indicate that the argument is optional.
848 *
849 * @paragraph Prefixes
850 * - **h** - `short *` - preceding **d** will retrieve a short e.g. "%hd".
851 * - **l** - `long *`, double * - preceding **d** will retrieve a long eg. "%ld"; preceding **f** will retrieve a double eg. "%lf".
852 *
853 * @paragraph Suffixes
854 * - **a** - extract an array of the preceding type into a block of allocated space and point the corresponding variable to it.
855 * The variable will have an extra level of indirection than the non-array version.
856 * e.g.,
857 * @code
858 * int i;
859 * ascanf(..., "%d", &i);
860 * @endcode
861 * becomes
862 * @code
863 * int *ia, n;
864 * ascanf(..., "%da", &ia, &n);
865 * @endcode
866 * Also, you need to provide an extra parameter for each format containing an **a** suffix to hold the count of array
867 * elements found. The pointer will point to an `int`.
868 *
869 *
870 * @param env The JNI environment. Used in all functions involving JNI
871 * @param arguments Arguments that the function processes as its source to retrieve the data.
872 * @param value For the avscanf() form this parameter holds the parsed Value given to the Channel Provider endpoint.
873 * @param formatString C string that contains a format string as described above
874 * @param ... Depending on the format string, the function may expect a sequence of additional arguments,
875 * containing pairs of names and pointers to allocated storage (except as indicated above),
876 * where the interpretation of the extracted data is stored with the appropriate type.
877 * There should be at least as many pairs of these arguments as the number of references
878 * in the format specifiers.
879 * Additional arguments are ignored by the function
880 * @return `EXIT_SUCCESS` if all required arguments were read and no errors occurred, otherwise `EXIT_FAILURE`
881 * @throw MissingRequiredArgumentException if one of the required arguments are missing
882*/
883int avscanf(JNIEnv* env, Arguments* arguments, Value* value, const char* formatString, ...);
884
885#ifdef __cplusplus
886}
887#endif
888#endif
889
void tableAddField(JNIEnv *env, Table *table, char *fieldName)
Add a dynamic field to a table.
void tableAddStringColumn(JNIEnv *env, Table *table, char **data)
Add a String column to the given Table.
int startsWith(const char *str, char *prefix)
Check if a string starts with another string.
void pmuStringFromUri(char *pmuString, const char *uri)
Get the pmu part of a URI.
void tableAddFixedWidthStringColumn(JNIEnv *env, Table *table, char *data, int width)
Add fixed-width string data to a column in the given Table.
const char * secondaryFromUri(const char *uri)
Get secondary from URI.
void releaseArray(Array array)
Free up any memory allocated the given scalar array.
void tableAddSingleRowFloatColumn(JNIEnv *env, Table *table, float data, bool ieeeFloat)
Add a float column to a Table with only one row.
int groupNameFromUri(char groupName[], const char *uri)
URI Handling for group, secn, pmu and slacName.
void secnFromUri(const char *uri, int4u *secn)
Get secondary from pseudo secondary (containing a colon) number from URI.
int ascanf(JNIEnv *env, Arguments *arguments, const char *formatString,...)
Argument Processing.
int endsWith(const char *str, char *suffix)
String Handling.
void aidaThrow(JNIEnv *env, vmsstat_t status, char *exception, const char *message)
Exception Handling.
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)
Table Handling.
void tableAddLabel(JNIEnv *env, Table *table, char *labelName)
Add a dynamic column to a table.
void tableAddSingleRowIntegerColumn(JNIEnv *env, Table *table, int data)
Add a integer column to a Table with only one row.
vmsstat_t init(const char *processName, bool initMessageServices)
Initialisation.
void * allocateMemory(JNIEnv *env, void *source, size_t size, bool nullTerminate, char *message)
Memory Handling.
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.
void releaseValue(Value value)
Release all allocated memory in the given value.
void tableAddColumn(JNIEnv *env, Table *table, Type type, void *data, bool ieeeFormat)
Add a column of arbitrary type to a Table.
int avscanf(JNIEnv *env, Arguments *arguments, Value *value, const char *formatString,...)
ascanf(), avscanf()
void uriLegacyName(char legacyName[MAX_URI_LEN], const char *uri)
Convert the given URI to the legacy AIDA name for low level functions that still require it that way.
void aidaThrowNonOsException(JNIEnv *env, char *exception, const char *message)
To log any non-OS exceptions and throw back to java.
void releaseTable(Table table)
Free up any memory allocated for the given table.
void releaseStringArray(StringArray array)
Free up any memory allocated for string arrays.
void tableAddSingleRowStringColumn(JNIEnv *env, Table *table, char *data)
Add a string column to a Table with only one row.
void uriToSlcName(char slcName[MAX_URI_LEN], const char *uri)
Convert all URIs to slac names before making queries.
Table tableCreateDynamic(JNIEnv *env, int rows, int columns)
Make a Dynamic Table for return to client.
int pmuFromDeviceName(JNIEnv *env, char *device, char *primary, char *micro, int4u *unit)
Get primary, micro and unit from a device name.
void releasePvAndArguments(JNIEnv *env, jstring uri, const char *pv, Arguments arguments)
Free up any memory allocated for the given pv and arguments.
The Header File for the Channel Provider API endpoints and endpoint-stubs MACROS.
The Header File for the type conversion functions.
The Header File for the exceptions helper MACROS.
The Header File for the memory management functions and macros.
The Header File for the type enumerations, unions, and typedefs.
Type
The definition of Aida Types.
The Header File for uri and channel name manipulation functions.
#define MAX_URI_LEN
The maximum length of a URI.
Definition: aida_pva_uri.h:20
An Arguments structure stores all of the arguments passed from the request to the Native Channel Prov...
An array of data.
An array of string data.
Table structure.
This special type represents a Value.