User function input and output parameters are processed by the SendData, GetFindData, and ReceiveData state table actions.
To define user function parameters, see Defining user functions and parameters.
Even if a system-generated main is not going to be used, it is useful to produce one and examine the user function parameters in the files customservername_main.c and customservername_hdr.c.
If system variables are passed, make sure that the appropriate Data Type is used, as defined in the table "System variables listed numerically" in the system variables appendix in the Blueworx Voice Response for AIX: Application Development using State Tables information.
For examples showing the formats in which various parameter combinations are expected by Blueworx Voice Response, see Example user function parameters.
The calling state table passes input parameters to a user function. Input parameters are restricted to the following data types:
Character strings are denoted by type char followed by length X, where X is the maximum length of the string including the NULL terminator. When character strings are returned, the string must be truncated to the length of the data including the NULL character. For examples of how to code this type of parameter, see Functions 1, 2, 3, and 4 in Example user function parameters.
A user function passes output parameters back to the calling state table. Output parameters are restricted to the following data types:
Character strings are denoted by type char followed by length X, where X is the maximum length of the string including the NULL terminator. When character strings are returned, the string must be truncated to the length of the data including the NULL character.
You can define one or more output parameters for a user function in the User Function window.
If there is only one output parameter the user function can use the C return statement, to reply to the calling state table. For examples, see Function 1 and Function 2.
If there is more than one output parameter you have two options:
Note that example Function 8 has only one output parameter, but it has a Return Type Multiple and therefore must return the address of a buffer containing successive values of the single output parameter. This is discussed below in Multiple instances of output parameters.
Output parameters can be returned indirectly from the user function by reserving one of the input parameters to contain the address of the output parameter. In this case, the user functions must be defined as int and return an int return code to indicate whether or not the execution was successful. For example, in the following function call, the return_code indicates whether execution of the function was successful or not, and the value of the output parameter is stored in output:
return_code = function_name(input1,input2,&output)
A system-generated main() function expects the value of return_code to be 0 if execution is successful, or -1 if it failed.
The output pointer variable can be the address of single parameters, multiple output parameters, or groups of single or multiple output parameters. For code examples see Functions 4, 5, 6, and 7 in Example user function parameters.
A user function can return multiple instances (an array) of the output parameters. In this case, you must allocate a buffer of contiguous memory. The buffer must be declared so that the data is persistent in the main function until the call to the CA_Put_DT_Parameters() subroutine.
For example, you might return a list of names that match a search string: this would be multiple instances of one char parameter (for a code example see also Function 8). To indicate the number of instances, the first four bytes of the buffer must be a long integer (for a code examples see Functions 9 and 10 in Example user function parameters) containing the number of instances being returned (the “name count” shown in Figure 1 and the “order count” shown in Figure 2).
To indicate that the user function can return multiple instances select the Return Type Multiple on the User Function window.
The state table can issue ReceiveData once per instance of the output parameters, stopping at count times.
When you define a user function you can identify those output parameters that are to be “ignored” by the calling state table (see 11). This does not affect the way the user function is written, but will determine which parameters are passed to the calling state table. In the state table, the ReceiveData action simply makes no mention of the ignored parameter.