|
A DTS Programming Example in C
You may download the original source files from here.
|
| |||||||||
/***************************************************************************/
/* */
/* Example DTS front-end application */
/* */
/* Perform a simple query to the remote handler HELLO */
/* */
/* Language: VAX C */
/* Date: 25-NOV-1991 */
/* */
/***************************************************************************/
/************************* C include header files **************************/
#include stdio /* Include standard I/O defs */
/*************************** Symbol definitions ****************************/
#define OUR_NAME "TestProgram" /* Our name for the remote rtn */
#define RECEIVER_NODE "REMOTE " /* Receiver DTS node name */
#define FUNCTION_CODE "01" /* Inquiry-type transaction */
#define REMOTE_HANDLER "HELLO " /* Remote user handler name */
#define USER_DATA_MAX 31900 /* Max user data area length */
/******************* Data structures and global variables ******************/
typedef struct /* Structure definition for the */
{ /* 39-byte DTS header block */
char Timestamp[12]; /* - unique message timestamp */
char Status; /* - resend status */
char Sender[8]; /* - sender node name */
char Receiver[8]; /* - receiver node name */
char FunctionCode[2]; /* - function code */
char Handler[8]; /* - remote handler name */
} DtsHeader;
struct /* DTS input message buffer */
{
DtsHeader Hdr; /* First 39 b - DTS header */
char UserData[USER_DATA_MAX]; /* Rest of the data - user msg */
} InputMessage;
struct /* DTS output message buffer */
{
char ReturnCode[2]; /* 2-byte DTS return code */
char UserData[USER_DATA_MAX]; /* Rest of the data - user msg */
} OutputMessage;
unsigned short InputLength; /* Input message actual length */
unsigned short OutputLength; /* Output message actual length */
/***************************** Begin of code ******************************/
main ( )
{
memcpy(InputMessage.Hdr.Receiver, /* Set receiver node name */
RECEIVER_NODE,8); /* (8 chars, space-padded) */
memcpy(InputMessage.Hdr.FunctionCode, /* Set DTS function code */
FUNCTION_CODE,2); /* (always 2 bytes) */
memcpy(InputMessage.Hdr.Handler, /* Set remote handler name */
REMOTE_HANDLER,8); /* (8 chars, space-padded) */
strcpy(InputMessage.UserData,OUR_NAME); /* Put user data to input buff */
InputLength = /* Input message length = */
sizeof(DtsHeader)+strlen(OUR_NAME); /* DTS header + our own data */
YFIAPPC(&InputMessage,&InputLength, /* Call DTS front-end service */
&OutputMessage,&OutputLength); /* routine YFIAPPC */
OutputMessage. /* Null to the end of output */
UserData[OutputLength-2] = 0; /* data to help str processing */
if ( memcmp(OutputMessage.ReturnCode, /* If nonzero return status, */
"00",2) != 0 )
{
printf("Call failed : %s\n", /* Display DTS return code and */
&OutputMessage); /* error message */
exit(0); /* and terminate the program */
}
/* Successful call: */
printf("Message received :\n%s\n", /* Display received response */
OutputMessage.UserData); /* message */
exit(0); /* and terminate the program */
}
/****************************** End of source ******************************/
/***************************************************************************/
/* */
/* Example DTS back-end application HELLO */
/* */
/* Return a simple 'Hello' message to the calling f/e. */
/* */
/* Language: VAX C */
/* Date: 25-NOV-1991 */
/* */
/***************************************************************************/
/*************************** Symbol definitions ****************************/
#define DTS_HEADER_LEN 39 /* DTS header length, 39 bytes */
#define DTS_RETCODE_LEN 2 /* DTS return code length, 2 b */
/************************* Subroutine entry point **************************/
void HELLO ( InputMessage, InputLength, OutputMessage, OutputLength )
/*********************** Function call parameters **************************/
char *InputMessage; /* Input message buffer */
unsigned short *InputLength; /* Input message length */
char *OutputMessage; /* Output message buffer */
unsigned short *OutputLength; /* Output message length */
{
/***************************** Begin of code ******************************/
InputMessage[*InputLength] = 0; /* Null to the end of input */
/* data to help str processing */
sprintf
(OutputMessage+DTS_RETCODE_LEN, /* Format response message to */
"Hello %s. I'm your remote routine", /* the output buffer */
InputMessage+DTS_HEADER_LEN);
*OutputLength = /* Output message length = */
strlen(OutputMessage+DTS_RETCODE_LEN) /* our response data + */
+DTS_RETCODE_LEN; /* DTS return code */
return; /* End of subroutine task */
}
/****************************** End of source ******************************/
| ||||||||||
|