Custom servers that wait to be called by state tables

If your custom server is of the first type, it should call the CA_Receive_DT_Msg() subroutine when it is ready to receive data from the state table. When a state table sends data to a custom server user function, CA_Receive_DT_Msg() returns control to the custom server. The custom server should then call CA_Get_DT_Parameters() to copy the data from the state table variables into custom server variables, and call the specified user function.

To return data to the state table, the custom server first passes the output data to the CA_Put_DT_Parameters() subroutine to create a message, then calls CA_Send_DT_Msg() to send the message to the channel process. Alternatively, the custom server can use CA_Send_DT_Error() to indicate to the state table that a problem occurred while processing the input data. See User function parameters for a description of the possible formats of the input and output parameters.

If your custom server requirements can be handled by a system-generated main() function, then these function calls are generated automatically for you when you build your custom server. If you need to code the main() function yourself, you may find it helpful to study the following example, which is the system-generated main() function for a custom server called TEST_PARMS. It has one user function, a TEST_PARMS_func1 (defined on Function 1). Note that the case statement uses <functionname>_func_id to determine which function is to be called. <functionname>_func_id is defined in the system-generated file <customservername>_hdr.h. The function id is also used in the CA_Get_DT_Parameters() subroutine.

The maximum amount of data you can exchange between a state table and a custom server is 3800 bytes, the rest of the buffer is used by Blueworx Voice Response.

/*----------------------------------------------------------------------
* TEST_PARMS_main.c
* Description :
*   Test exchanging data with a state table
* Descriptive File Name: Custom Server : main() module
*-----------------------------------------------------------------------
* Blueworx Voice Response Custom Server
* 5765-B81(C) Copyright by IBM Corp. 1991, 1997.  All rights reserved
*-----------------------------------------------------------------------
*                This file was generated on Thu May 29 11:22:56 1997
* from Custom Server Properties modified on Wed Apr 23 15:14:54 1997
*----------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include "CA_header.h"       /* customer application definitions */
#include "TEST_PARMS_hdr.h"  /* declarations, defines and tables */
struct ST1
{
  long aa;
  char bb[20];
  short cc;
};
struct ST2
{
  long x;
  long y;
  char z;
};
DT_MSG_INFO_ST DT_msg_info_st;
void main (int argc, char *argv[])
{
  int rc;
#ifdef MULTI
  CA_Set_Options (MULTI_PROCESS_CA, NULL);
#endif
  if (CA_Set_CA_Version (CA_VERSION_ID) != 0)
  {
    exit (1);
  }
  if (CA_Init (APPL_NAME) != 0)
  {
    exit (1);
  }
  while (TRUE)
  {
    if (CA_Receive_DT_Msg (&DT_msg_info_st, CA_WAIT) == -1)
    {
      if (CA_errno == CA_SIGNAL_RECEIVED ||	/* interrupted by signal */
          CA_errno == CA_NO_MSG_RECV)		/* timed out */
        continue;
      else
      {
        CA_Terminate (1);
        break;
      }
    }
    switch (DT_msg_info_st.func_id)
    {
      case TEST_PARMS_func1_func_id :
        if (CA_Get_DT_Parameters (
              &DT_msg_info_st,
              &TEST_PARMS_func1_a,
              &TEST_PARMS_func1_b) != 0)
        {
          CA_Send_DT_Error (&DT_msg_info_st);
          break;
        }
        TEST_PARMS_func1_z = TEST_PARMS_func1 (
          TEST_PARMS_func1_a,
          TEST_PARMS_func1_b);
        if (CA_Put_DT_Parameters (
              &DT_msg_info_st,
              &TEST_PARMS_func1_z) != 0)
          CA_Send_DT_Error (&DT_msg_info_st);
        else
          CA_Send_DT_Msg (&DT_msg_info_st);
        break;
/*
.
.   case statements for other user functions are added here
.
*/
      default :
        CA_Send_DT_Error (&DT_msg_info_st);
        break;
    } /* end switch */
  } /* end while */
} /* end of main() */