Handling custom parameters and return values
Custom parameters are passed to the RAM using the void**
params
parameter. params
is an array of void
pointers
that point to variables of several types. If these custom parameters
have been defined as required parameters for a given function in the
CARMA VSAM clusters (see Customizing a RAM API using the CAF for
more information), it should be assumed that the client has set up
the params
properly. To retrieve the parameters,
simply typecast the variables in params
back to their
proper types. Notice how params
uses a char* for
strings instead of a char**. Use the following C code as an example:
int param0;
char param1[30];
double param2;
param0= *( (int*) params[0]);
memcpy(param1, params[1], 30);
param2 = *( (double*) params[2]);
A pointer to an unallocated custom return values array is passed
to the RAM as void*** customReturn
. If custom return
values are defined in the CARMA VSAM clusters, the RAM must allocate
memory for customReturn
and fill it appropriately.
Because the client must free the memory created in the RAM, it is
important RAM developers allocate memory for each return value separately.
The following C code demonstrates returning an int, a string, and
a double:
/* These are defined at the top */
int* return0;
char* return1;
double* return2;
/* Program body */
return0 = malloc(sizeof(int));
*return0 = 5;
return1 = malloc(sizeof(char) * 10);
memcpy(return1, "THE STRING", 10);
return2 = malloc(sizeof(double));
*return2 = 3.41;
/* Allocate and fill the return value structure */
*customReturn = malloc(sizeof(void*) * 3);
(*customReturn)[0] = (void*) return0;
(*customReturn)[1] = (void*) return1;
(*customReturn)[2] = (void*) return2;
If no custom return values are defined in the CARMA VSAM clusters, customReturn
should
be set to NULL
.