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_server_helper.h File Reference

The Header File for the Native Channel Provider Server Helper functions. More...

#include "aida_pva.h"

Go to the source code of this file.

Functions

Argument getArgument (Arguments arguments, char *name)
 Get a named argument. More...
 
json_value * getJsonRoot (json_value *jsonValue)
 
json_value * getJsonValue (Value *value, char *passedInPath)
 Get the json value from the given value identified by the path. More...
 
Value getNamedArrayValue (JNIEnv *env, Arguments arguments, char *name)
 Get array value from a named argument in the provided arguments structure. More...
 
Value getNamedValue (JNIEnv *env, Arguments arguments, char *name)
 Get value from a named argument in the provided arguments structure. More...
 

Detailed Description

The Header File for the Native Channel Provider Server Helper functions.

CMS=C_INC

Definition in file aida_pva_server_helper.h.

Function Documentation

◆ getArgument()

Argument getArgument ( Arguments  arguments,
char *  name 
)

Get a named argument.

Parameters
argumentsarguments
namename
Returns
Argument

Definition at line 184 of file aida_pva_server_helper.c.

185{
186 Argument noArgument;
187 memset(&noArgument, 0, sizeof(Argument));
188
189 for (int i = 0; i < arguments.argumentCount; i++) {
190 Argument argument = arguments.arguments[i];
191 if (!strcasecmp(argument.name, name)) {
192 if (strlen(argument.value) > 0) {
193 return argument;
194 }
195 }
196 }
197 return noArgument;
198}
A single request argument.
char * value
The string value of the argument.
char * name
The name of the argument.
int argumentCount
The number of arguments sent with this request.
Argument * arguments
The array of Arguments.

References Arguments::argumentCount, Arguments::arguments, Argument::name, and Argument::value.

◆ getJsonRoot()

json_value * getJsonRoot ( json_value *  jsonValue)
Skip root element if it is _array otherwise return unchanged

This is because our json parser can't process arrays at the top level and so we insert
an object at the top level with an "_array" element if we find an array at the top level
Parameters
jsonValuethe json value traverse
Returns
json value

Definition at line 404 of file aida_pva_server_helper.c.

405{
406 if (jsonValue->type == json_object && jsonValue->u.object.length == 1
407 && strcmp(jsonValue->u.object.values[0].name, "_array") == 0) {
408 jsonValue = jsonValue->u.object.values[0].value;
409 }
410 return jsonValue;
411}

Referenced by getJsonValue().

◆ getJsonValue()

json_value * getJsonValue ( Value value,
char *  passedInPath 
)

Get the json value from the given value identified by the path.

Parameters
valuethe given value
passedInPathis an absolute reference to the element within the json of the given value. e.g. root.collection[0].name
Returns
the json_value
Parameters
valuethe given value
passedInPathis an absolute reference to the element within the json of the given value. e.g. root.collection.[0].name
Returns
pointer to the json_value

Definition at line 347 of file aida_pva_server_helper.c.

348{
349 if (value->type != AIDA_JSON_TYPE || !value->value.jsonValue) {
350 return NULL;
351 }
352
353 json_value* jsonValue = getJsonRoot(value->value.jsonValue);
354
355 // If there is no path then we already have the json value
356 if (!passedInPath || strlen(passedInPath) == 0) {
357 return jsonValue;
358 }
359
360 // can't use const for strtok
361 char path[strlen(passedInPath) + 1];
362 strcpy(path, passedInPath);
363
364 int len;
365 char name[256];
366 char* arrayRef;
367
368 // Extract the first token
369 char* token = strtok(path, ".");
370
371 while (token) {
372 if (*token == '[') {
373 // if array is at top level
374 jsonValue = processArrayReference(jsonValue, token);
375 } else if ((arrayRef = strstr(token, "["))) {
376 // element followed by array ref
377 len = (int)(arrayRef - token);
378 strncpy(name, token, len);
379 name[len] = 0x0;
380 jsonValue = navigateToObjectElement(jsonValue, name);
381
382 jsonValue = processArrayReference(jsonValue, arrayRef);
383 } else {
384 // element only
385 jsonValue = navigateToObjectElement(jsonValue, token);
386 }
387
388 // Next token
389 token = strtok(NULL, ".");
390 }
391
392 return jsonValue;
393}
json_value * getJsonRoot(json_value *jsonValue)
@ AIDA_JSON_TYPE
Argument was provided as JSON text.
ValueContents value
The value's contents, either a string or parsed json.
Type type
AIDA_STRING_TYPE or AIDA_JSON_TYPE.
json_value * jsonValue
The parsed json_value of this Value if the type is AIDA_JSON_TYPE.

References AIDA_JSON_TYPE, getJsonRoot(), ValueContents::jsonValue, Value::type, and Value::value.

◆ getNamedArrayValue()

Value getNamedArrayValue ( JNIEnv *  env,
Arguments  arguments,
char *  name 
)

Get array value from a named argument in the provided arguments structure.

Parameters
envenv
argumentsprovided arguments structure
nameprovided name
Returns
the extracted Value

Get array value from a named argument in the provided arguments structure.

Parameters
envthe JNI environment. Used in all functions involving JNI
argumentsprovided arguments structure
nameprovided name
Returns
the extracted Value

Definition at line 335 of file aida_pva_server_helper.c.

336{
337 return getNamedValueImpl(env, arguments, name, true);
338}

Referenced by getArrayValue().

◆ getNamedValue()

Value getNamedValue ( JNIEnv *  env,
Arguments  arguments,
char *  name 
)

Get value from a named argument in the provided arguments structure.

Parameters
envenv
argumentsprovided arguments structure
nameprovided name
Returns
the extracted Value
Parameters
envthe JNI environment. Used in all functions involving JNI
argumentsprovided arguments structure
nameprovided name
Returns
the extracted Value

Definition at line 322 of file aida_pva_server_helper.c.

323{
324 return getNamedValueImpl(env, arguments, name, false);
325}

Referenced by getValue().