![]() |
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.
|
This file contain functions that should be used directly by Native Channel Providers. More...
#include <jni.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <stdbool.h>
#include "slc_macros.h"
#include "sysutil_proto.h"
#include "aida_pva_jni_helper.h"
#include "aida_pva_server_helper.h"
#include "aida_pva_types_helper.h"
Go to the source code of this file.
Functions | |
int | ascanf (JNIEnv *env, Arguments *arguments, const char *formatString,...) |
ascanf(), avscanf() More... | |
int | avscanf (JNIEnv *env, Arguments *arguments, Value *value, const char *formatString,...) |
ascanf(), avscanf() More... | |
void | tableAddColumn (JNIEnv *env, Table *table, Type type, void *data, bool ieeeFormat) |
Add a column of arbitrary type to a Table. More... | |
void | tableAddField (JNIEnv *env, Table *table, char *fieldName) |
Add a dynamic field to a table. More... | |
void | tableAddFixedWidthStringColumn (JNIEnv *env, Table *table, char *data, int width) |
This reads data from an allocated space that is rows * width with each string occupying width characters Though the strings are null terminated if there is space, there is no guarantee so an exact number of bytes is copied. More... | |
void | tableAddLabel (JNIEnv *env, Table *table, char *labelName) |
Add a dynamic column to a table. More... | |
void | tableAddSingleRowBooleanColumn (JNIEnv *env, Table *table, unsigned char data) |
Add a boolean column to a Table with only one row. More... | |
void | tableAddSingleRowByteColumn (JNIEnv *env, Table *table, unsigned char data) |
Add a byte column to a Table with only one row. More... | |
void | tableAddSingleRowDoubleColumn (JNIEnv *env, Table *table, double data, bool ieeeDouble) |
Add a double column to a Table with only one row. More... | |
void | tableAddSingleRowFloatColumn (JNIEnv *env, Table *table, float data, bool ieeeFloat) |
Add a float column to a Table with only one row. More... | |
void | tableAddSingleRowIntegerColumn (JNIEnv *env, Table *table, int data) |
Add a integer column to a Table with only one row. More... | |
void | tableAddSingleRowLongColumn (JNIEnv *env, Table *table, long data) |
Add a long column to a Table with only one row. More... | |
void | tableAddSingleRowShortColumn (JNIEnv *env, Table *table, short data) |
Add a short column to a Table with only one row. More... | |
void | tableAddSingleRowStringColumn (JNIEnv *env, Table *table, char *data) |
Add a string column to a Table with only one row. More... | |
void | tableAddStringColumn (JNIEnv *env, Table *table, char **data) |
Add a String column to the given Table. More... | |
Table | tableCreate (JNIEnv *env, int rows, int columns) |
Make a Table for return to client. More... | |
Table | tableCreateDynamic (JNIEnv *env, int rows, int columns) |
Make a Dynamic Table for return to client. More... | |
This file contain functions that should be used directly by Native Channel Providers.
These functions provide all of the features related to processing of Arguments and Table that allow the Channel Provider to implement its service.
MEMBER=SLCLIBS:AIDA_PVALIB ATTRIBUTES=JNI
Definition in file aida_pva_types_helper.c.
int ascanf | ( | JNIEnv * | env, |
Arguments * | arguments, | ||
const char * | formatString, | ||
... | |||
) |
Argument Processing.
Reads data from the given arguments
and stores them according to parameter format into the locations given by the additional arguments, as if scanf() was used, but reading from arguments instead of the standard input (stdin).
env | The JNI environment. Used in all functions involving JNI |
arguments | Arguments that the function processes as its source to retrieve the data. |
formatString | C string that contains a format string as described above |
... | Depending on the format string, the function may expect a sequence of additional arguments, containing pairs of names and pointers to allocated storage (except as indicated above), where the interpretation of the extracted data is stored with the appropriate type. There should be at least as many pairs of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function |
EXIT_SUCCESS
if all required arguments were read and no errors occurred, otherwise EXIT_FAILURE
MissingRequiredArgumentException | if one of the required arguments are missing |
Definition at line 86 of file aida_pva_types_helper.c.
Referenced by aidaRequestBoolean(), aidaRequestBooleanArray(), aidaRequestByte(), aidaRequestByteArray(), aidaRequestDouble(), aidaRequestDoubleArray(), aidaRequestFloat(), aidaRequestFloatArray(), aidaRequestInteger(), aidaRequestIntegerArray(), aidaRequestLong(), aidaRequestLongArray(), aidaRequestShort(), aidaRequestShortArray(), aidaRequestString(), aidaRequestStringArray(), aidaRequestTable(), and aidaSetValue().
Reads data from the given arguments
and stores them according to parameter format into the locations given by the additional arguments, as if scanf() was used, but reading from arguments instead of the standard input (stdin).
The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier. For strings and arrays only the pointer needs to be pre-allocated.
The only space allocated by this function is for the strings or arrays. So callers should only free strings and arrays. Even if you provide a default value for a string the pointer will be allocated memory on exit from the function, so even then you need to free it.
String space is allocated as follows:
There are a number of differences from scanf() which are best described by example:
By default all arguments referenced by format specifications are considered required unless the format specification character is preceded by o. For optional arguments the pointer provided must point to the default value. In the case of arrays and strings this will be copied into allocated storage that will need to be freed as normal.
json
and presented as: name
as "json.foo.bar" to retrieve the 0
value.jsonArray
and presented as 20
value.name
"value", then the avscanf() function will use the supplied value
parameter to get the data for that parameter unsigned char *
- interpret the input as a boolean, then extract a single byte into the corresponding variable.true
0
- integer, short, long,0.0
- float, double“true”
- char string“t”
- char string“yes”
- char string“y”
- char string!0
- short, int, long, float, or doublefalse
0
- integer, short, long,0.0
- float, double“false”
- char string“f”
- char string“no”
- char string“n”
- char string0
- short, int, long, float, or doublechar *
- extract a single character into the corresponding variable.int *
- extract an integer into the corresponding variable (see l & h below).float *
- extract a floating point number (see l below).char *
- extract a string of characters into allocated space and point the corresponding variable to it.unsigned int *
- extract an unsigned integer into the corresponding variable (see l & h below).short *
- preceding d will retrieve a short e.g. "%hd".long *
, double * - preceding d will retrieve a long eg. "%ld"; preceding f will retrieve a double eg. "%lf".int
.env | The JNI environment. Used in all functions involving JNI |
arguments | Arguments that the function processes as its source to retrieve the data. |
value | For the avscanf() form this parameter holds the parsed Value given to the Channel Provider endpoint. |
formatString | C string that contains a format string as described above |
... | Depending on the format string, the function may expect a sequence of additional arguments, containing pairs of names and pointers to allocated storage (except as indicated above), where the interpretation of the extracted data is stored with the appropriate type. There should be at least as many pairs of these arguments as the number of references in the format specifiers. Additional arguments are ignored by the function |
EXIT_SUCCESS
if all required arguments were read and no errors occurred, otherwise EXIT_FAILURE
MissingRequiredArgumentException | if one of the required arguments are missing |
Definition at line 250 of file aida_pva_types_helper.c.
Referenced by aidaSetValue(), and aidaSetValueWithResponse().
Add a column of arbitrary type to a Table.
Add the given data to the column assuming that the data has a number of rows that corresponds to the Table's rowCount. Memory will be allocated for the data of the column so the data
buffer presented can be freed up after calling this function.
The framework will release all memory associated with a Table when you return from your API implementation.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
type | the type of this Table column. |
data | the data to add to this column, a buffer of sizeof(type) * table->rowCount size. |
ieeeFormat | true if the data provided is already in ieee format. If the data is not in ieee format, usually because it has been retrieved from some backend system, this function will convert it to ieee format unless this parameter is set to true. |
Create a two column, two row Table, add data, and return.
Definition at line 755 of file aida_pva_types_helper.c.
References Table::_currentColumn, AIDA_BOOLEAN_ARRAY_TYPE, AIDA_BYTE_ARRAY_TYPE, AIDA_DOUBLE_ARRAY_TYPE, AIDA_FLOAT_ARRAY_TYPE, AIDA_INTEGER_ARRAY_TYPE, AIDA_LONG_ARRAY_TYPE, AIDA_SHORT_ARRAY_TYPE, AIDA_STRING_ARRAY_TYPE, aidaThrowNonOsException(), Table::columnCount, CONVERT_FROM_VMS_DOUBLE, CONVERT_FROM_VMS_FLOAT, ON_EXCEPTION_RETURN_VOID, Table::ppData, Table::rowCount, and UNABLE_TO_GET_DATA_EXCEPTION.
Referenced by aidaRequestTable(), aidaSetValueWithResponse(), tableAddFixedWidthStringColumn(), tableAddSingleRowBooleanColumn(), tableAddSingleRowByteColumn(), tableAddSingleRowDoubleColumn(), tableAddSingleRowFloatColumn(), tableAddSingleRowIntegerColumn(), tableAddSingleRowLongColumn(), tableAddSingleRowShortColumn(), and tableAddStringColumn().
void tableAddField | ( | JNIEnv * | env, |
Table * | table, | ||
char * | fieldName | ||
) |
Add a dynamic field to a table.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
fieldName | The name of the field to add |
Definition at line 828 of file aida_pva_types_helper.c.
References Table::_currentField, aidaThrowNonOsException(), ALLOCATE_STRING_AND_ON_ERROR_RETURN_VOID, Table::columnCount, Table::ppFields, and UNABLE_TO_GET_DATA_EXCEPTION.
void tableAddFixedWidthStringColumn | ( | JNIEnv * | env, |
Table * | table, | ||
char * | data, | ||
int | width | ||
) |
This reads data from an allocated space that is rows * width with each string occupying width characters Though the strings are null terminated if there is space, there is no guarantee so an exact number of bytes is copied.
Add fixed-width string data to a column in the given Table.
Each string in the Table is allocated maximally.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, a pointer to char buffer containing the fixed length strings. The strings are arranged in contiguous blocks width long. |
width | the width of the strings |
Definition at line 955 of file aida_pva_types_helper.c.
References Table::_currentColumn, AIDA_STRING_ARRAY_TYPE, ALLOCATE_FIXED_LENGTH_STRING_AND_ON_ERROR_RETURN_VOID, ON_EXCEPTION_RETURN_VOID, Table::ppData, Table::rowCount, and tableAddColumn().
Referenced by aidaRequestTable(), and aidaSetValueWithResponse().
void tableAddLabel | ( | JNIEnv * | env, |
Table * | table, | ||
char * | labelName | ||
) |
Add a dynamic column to a table.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
labelName | the label name to add |
Definition at line 847 of file aida_pva_types_helper.c.
References Table::_currentLabel, aidaThrowNonOsException(), ALLOCATE_STRING_AND_ON_ERROR_RETURN_VOID, Table::columnCount, Table::ppLabels, and UNABLE_TO_GET_DATA_EXCEPTION.
void tableAddSingleRowBooleanColumn | ( | JNIEnv * | env, |
Table * | table, | ||
unsigned char | data | ||
) |
Add a boolean column to a Table with only one row.
This function will allocate the required memory for the single unsigned char
that is required.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, a pointer to an unsigned char . |
Definition at line 996 of file aida_pva_types_helper.c.
References AIDA_BOOLEAN_TYPE, and tableAddColumn().
Referenced by aidaRequestTable(), and aidaSetValueWithResponse().
void tableAddSingleRowByteColumn | ( | JNIEnv * | env, |
Table * | table, | ||
unsigned char | data | ||
) |
Add a byte column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, an unsigned char . |
Definition at line 1025 of file aida_pva_types_helper.c.
References AIDA_BYTE_TYPE, and tableAddColumn().
Referenced by aidaRequestTable().
void tableAddSingleRowDoubleColumn | ( | JNIEnv * | env, |
Table * | table, | ||
double | data, | ||
bool | ieeeDouble | ||
) |
Add a double column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, a double . |
ieeeDouble | True if the data is in ieee format, otherwise the double precision floating point number is converted from VMS to ieee format. |
Definition at line 1175 of file aida_pva_types_helper.c.
References AIDA_DOUBLE_TYPE, and tableAddColumn().
Referenced by aidaRequestTable(), and aidaSetValueWithResponse().
void tableAddSingleRowFloatColumn | ( | JNIEnv * | env, |
Table * | table, | ||
float | data, | ||
bool | ieeeFloat | ||
) |
Add a float column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, a float . |
ieeeFloat | True if the data is in ieee format, otherwise the given floating point number is converted from VMS to ieee format. |
Definition at line 1144 of file aida_pva_types_helper.c.
References AIDA_FLOAT_TYPE, and tableAddColumn().
Referenced by aidaRequestTable().
void tableAddSingleRowIntegerColumn | ( | JNIEnv * | env, |
Table * | table, | ||
int | data | ||
) |
Add a integer column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
data | the data to add to this column, an int |
Definition at line 1083 of file aida_pva_types_helper.c.
References AIDA_INTEGER_TYPE, and tableAddColumn().
Referenced by aidaRequestTable().
void tableAddSingleRowLongColumn | ( | JNIEnv * | env, |
Table * | table, | ||
long | data | ||
) |
Add a long column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
data | the data to add to this column. A long value |
Definition at line 1113 of file aida_pva_types_helper.c.
References AIDA_LONG_TYPE, and tableAddColumn().
Referenced by aidaRequestTable().
void tableAddSingleRowShortColumn | ( | JNIEnv * | env, |
Table * | table, | ||
short | data | ||
) |
Add a short column to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | The Table to add the column to. |
data | The data to add to this column, a short . |
Definition at line 1054 of file aida_pva_types_helper.c.
References AIDA_SHORT_TYPE, and tableAddColumn().
Referenced by aidaRequestTable().
void tableAddSingleRowStringColumn | ( | JNIEnv * | env, |
Table * | table, | ||
char * | data | ||
) |
Add a string column to a Table with only one row.
This is a shortcut Table function that simplifies adding a string to a Table with only one row.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the column to. |
data | the data to add to this column. A single string. |
Definition at line 1205 of file aida_pva_types_helper.c.
References tableAddStringColumn().
Referenced by aidaRequestTable().
void tableAddStringColumn | ( | JNIEnv * | env, |
Table * | table, | ||
char ** | data | ||
) |
Add a String column to the given Table.
This reads data from a buffer that is itself a list of pointers to strings. We allocate just enough space to store the strings in our Table. This is allocated in one buffer so there is only one pointer to release.
env | The JNI environment. Used in all functions involving JNI. |
table | the Table to add the string column to. |
data | the data to add to this column, a buffer of sizeof(char *) * table->rowCount size. This will contain the strings to be added to the Table. |
Create a single column, one row Table, add data, and return.
Definition at line 912 of file aida_pva_types_helper.c.
References Table::_currentColumn, AIDA_STRING_ARRAY_TYPE, ALLOCATE_STRING_AND_ON_ERROR_RETURN_VOID, ON_EXCEPTION_RETURN_VOID, Table::ppData, Table::rowCount, and tableAddColumn().
Referenced by aidaRequestTable(), and tableAddSingleRowStringColumn().
Table tableCreate | ( | JNIEnv * | env, |
int | rows, | ||
int | columns | ||
) |
Make a Table for return to client.
Table Handling.
This is the first call that needs to be made to return a Table. This will create a Table with the specified the number of rows and columns. You need to call tableAddColumn(), tableAddStringColumn(), or any of the other special tableAdd
functions to add columns to the Table before returning it.
env | The JNI environment. Used in all functions involving JNI. |
rows | the number of rows to create the Table with. |
columns | the number of columns to create the Table with, |
Create a two column, two row Table, add data, and return.
Definition at line 672 of file aida_pva_types_helper.c.
References Table::_currentColumn, AIDA_INTERNAL_EXCEPTION, aidaThrowNonOsException(), ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_, Table::columnCount, Table::ppData, Table::rowCount, and Table::types.
Referenced by aidaRequestTable(), aidaSetValueWithResponse(), and tableCreateDynamic().
Table tableCreateDynamic | ( | JNIEnv * | env, |
int | rows, | ||
int | columns | ||
) |
Make a Dynamic Table for return to client.
This is the first call that needs to be made to return a Dynamic Table. This will create a Table with the specified the number of rows and columns. You need to call tableAddColumn(), tableAddStringColumn(), tableAddField(), tableAddLabel(), or any of the other special tableAdd
functions to add columns to the Table before returning it. Calling tableAddField(), and tableAddLabel() are mandatory
env | The JNI environment. Used in all functions involving JNI. |
rows | the number of rows to create the Table with. |
columns | the number of columns to create the Table with, |
Create a two column, two row Table, Set Field names, and labels, add data, and return.
Definition at line 692 of file aida_pva_types_helper.c.
References Table::_currentField, Table::_currentLabel, ALLOCATE_MEMORY_AND_ON_ERROR_RETURN_, ON_EXCEPTION_RETURN_, Table::ppFields, Table::ppLabels, and tableCreate().
Referenced by aidaRequestTable().