Previous Topic: Communication-specific DetailsNext Topic: Tuxedo C Proxy Support


Overview of an Example C Program

Your C program needs sections for:

An overview of an example C program follows. Information referenced in the generated header file is shown in bold. This example is derived from the CA Gen sample proxy source file, but does not include the entire file content. Selected code fragments have been extracted for discussion purposes.

Description

Example C Program

Comments describing program

This sample's purpose is to provide a C programmer a starting point for coding a C proxy routine.

This sample builds upon the CA (R) Gen sample model that is included with the CA Gen Toolset. The Gen server module used by this proxy example is packaged within the sample model as load module P900. This proxy example will only exercise a small amount of the sample models capabilities.

Include the CA Gen C Proxy generated header file. This file must be generated using the same CA Gen model used to create the target server load module.

#include "p900.h"

Include other standard libraries as needed

#include <malloc.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Declare variables

/* Contains communication information */

static ProxyParam* psParamBlock;

 
/* Error message length can be from 0-2048. This will determine how much of the error message will be returned by ProxyExecute. A shorter message may be returned depending on the error.
*/

#define errMsgLen 2048
char errMsg[errMsgLen];

/* Return code from routines {Failure, Success}  */
ProxyExecuteReturnValues ReturnVal;
/* Integer return code */

int nRC;

Beginning of main program

int main (void)
{
 printf ("Beginning of sample C proxy application \n\n");

ProxyStartTracing opens a file for debug/status information. ProxyStopTracing is used to close the file.

ProxyStartTracing((char*)"cproxy.out",

(char *)"0xFFFFFFFF");

ProxyTraceOut writes a message to the trace file. These messages are interspersed with standard debugging messages. This function call is optional.

ProxyTraceOut(NULL, (char *)"cproxy.c - ***** Beginning program");

ProxyAllocateParamBlock is used to create the parameter block (data structure) that contains information required for the transaction. A NULL return indicates an error in the creation of the parameter block. This function call is required.

psParamBlock = ProxyAllocateParamBlock();
  if (NULL == psParamBlock)
  {
  printf("Unsuccessful return -
  ProxyAllocateParamBlock\n");
  return (Failure);
  }

ProxyConfigureComm is used to set communication options. This call to ProxyConfigureComm uses the file commcfg.ini.

nRC = ProxyConfigureComm(&SERVER_DETAIL_DIVISION,SERVER_DETAIL_DIVISION.service, NULL);
if (nRC == FALSE)
{
  printf("Unsuccessful return from
  ProxyConfigureComm\n");
  return (Failure);
}

Load example data into the import record.

strcpy(server_detail_division.importRequest_command.value, Command);

ProxyExecute executes the transaction to the server as a synchronous, blocked cooperative flow. Export data and messages are returned to the application. This function uses the following parameters:

SERVER_DETAIL_DIVISION transaction structure that contains import and export views

psParamBlock parameter structure that contain communication information

errMsg returns any error message from the server

errMsgLen specifies the number of characters to write to errMsg

This function call is required.

If (ProxyExecute(&SERVER_DETAIL_DIVISION, psParamBlock, errMsg, errMsgLen) != Success)

{

  printf("Unsuccessful return from ProxyExecute \n");

  printf("errMsg = %s\n",errMsg);

  ProxyTraceOut(NULL, errMsg);

  return (Failure);

}

The ProxyClear set of functions is used to clear the parameter block. Each part of the parameter block can be cleared individually, or the ProxyClearParamBlock function can be used to clear the entire parameter block. This function call is optional.

nRC =
  ProxyClearParamBlock(psParamBlock);
if (ReturnVal == Failure)
{
  printf("Unsuccessful return from
  ProxyClearParamBlock\n");
  return (Failure);
}

The ProxyDeleteParamBlock function is used to delete the psParamBlock structure. This function call is optional, but recommended.

nRC =
  ProxyDeleteParamBlock(psParamBlock);
if (ReturnVal == Failure)
{
  printf("Unsuccessful return from
  ProxyDeleteParamBlock\n");
  return (Failure);
}

Export View processing-displays the export view.

printf("\n Here is the export \n");

/* Prints the returned division name */

printf("Division Name %s\n",

server_detail_division.export_division.name);

 

End of program

return (TRUE);
}

ProxyStopTracing is used to close the trace file opened by ProxyStartTracing. This function is optional, but is recommended if ProxyStartTracing is used.

ProxyStopTracing();


More information:

Function Calls

Repeating Group Views