Previous Topic: API Return Codes

Next Topic: Performance Tuning


XcomQAPI Example

The XcomQAPI sample is an example of a queue request. It uses the XcomQAPI() routine to pass information to CA XCOM Data Transport. This sample API program is the qapitest.c file distributed with CA XCOM Data Transport.

Note: The API example provided on your distribution media may have been updated for your CA XCOM Data Transport system and may be different from the example shown below.

Example:

The following is a C language example of a program using the API to call the XcomQAPI.

/* qapitest.c - This is a sample program for calling the XcomQAPI. */
/*              Modify this according to your needs and make it    */
/*              with the sample 'qapitcp.mak' / 'qapisna.mak'      */
/*              in this directory.                                 */
/*              Please note that XcomQAPI is not thread safe.      */
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "xcomapi.h"
main(int argc,char **argv)
{
    int rc, i;
    XCOM_QUEUE_PARM *xcomqparm;
    /* allocate memory for structure of xcomqparm */
    xcomqparm = (XCOM_QUEUE_PARM *)malloc(sizeof(XCOM_QUEUE_PARM));
    if (xcomqparm == NULL)
       printf("Could not allocate memory to run QAPI process !\n");
    else {
          /* Reset allocated memory to all zeros */
          memset(xcomqparm,0,sizeof(XCOM_QUEUE_PARM));
          /* xcomqparm->nMax_Queue_Entries should equal to MAX_QUEUE_ENTRIES in xcom.glb file */
          xcomqparm->nMax_Queue_Entries = 50;
          /* allocate memory for structure of pQueue */
          xcomqparm->pQueue = (XCOM_QUEUE *)malloc(xcomqparm->nMax_Queue_Entries * sizeof(XCOM_QUEUE_ENTRY));
          if (xcomqparm->pQueue == NULL)
             printf("Could not allocate memory to run QAPI process !\n");
          else {
            /* Reset allocated memory to all zeros */
            memset(xcomqparm->pQueue,0,xcomqparm->nMax_Queue_Entries * sizeof(XCOM_QUEUE_ENTRY));
            printf("==== QAPI started ===\n");
            /* call option 'r' to display CA XCOM Data Transport version */
            xcomqparm->funccode[0] = 'r';
            rc=XcomQAPI(xcomqparm);
            if (strlen(xcomqparm->start_message))
               printf("%s", xcomqparm->start_message); 
            if (xcomqparm->nQueueEntries == 1)
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            /* call option 'd' to turn on trace file */
            xcomqparm->trace_level = 9;
            strcpy(xcomqparm->trace_filename, "c:\\xcomnt\\trace\\xcomqapi.tra");
            xcomqparm->funccode[0] = 'd';
            rc=XcomQAPI(xcomqparm);
            /* call option 'La' to list all queue entries */
            xcomqparm->funccode[0] = 'L';
            xcomqparm->funccode[1] = 'a';
            rc=XcomQAPI(xcomqparm); 
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* print detail information for all queue entries */
            for (i = 0; i < xcomqparm->nQueueEntries; i++) {
                printf("%s", (*xcomqparm->pQueue)[i].user_name);
                printf("%s", (*xcomqparm->pQueue)[i].array_message);
            }
            if ((xcomqparm->nQueueEntries == 0) && strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            /* call option 'Z' to list entries log messages */
            xcomqparm->funccode[0] = 'Z';
            strcpy(xcomqparm->tid, "000001");
            rc=XcomQAPI(xcomqparm); 
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* print detail information for all queue entries */
            for (i = 0; i < xcomqparm->nQueueEntries; i++) {
                printf("%s", (*xcomqparm->pQueue)[i].user_name);
                printf("%s", (*xcomqparm->pQueue)[i].array_message);
            }
            if ((xcomqparm->nQueueEntries == 0) && strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            /* call option 'Dxxxxxx' to display detail record information */
            memset(xcomqparm->lfile,0,sizeof(xcomqparm->lfile));
            memset(xcomqparm->rfile,0,sizeof(xcomqparm->rfile));
            strcpy(xcomqparm->tid, "000001");
            xcomqparm->funccode[0] = 'D';
            rc=XcomQAPI(xcomqparm);
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* display detail record information */
            if (strlen(xcomqparm->head_message))
               printf("%s", xcomqparm->head_message);
            if (strlen(xcomqparm->global_tid))
               printf("%s", xcomqparm->global_tid);
            if (strlen(xcomqparm->remote_tid))
               printf("%s", xcomqparm->remote_tid);
            if (strlen(xcomqparm->group_name))
               printf("%s", xcomqparm->group_name);
            if (strlen(xcomqparm->transfer_name))
               printf("%s", xcomqparm->transfer_name);
            if (strlen(xcomqparm->xferdata))
               printf("%s", xcomqparm->xferdata);
            if (strlen(xcomqparm->sysdata))
               printf("%s", xcomqparm->sysdata);
            if (strlen(xcomqparm->start_time))
               printf("%s", xcomqparm->start_time);
            if (strlen(xcomqparm->transfer_type))
               printf("%s", xcomqparm->transfer_type);
            if (strlen(xcomqparm->lfile))
               printf("%s", xcomqparm->lfile);
            if (strlen(xcomqparm->file))
               printf("%s", xcomqparm->file);
            if (strlen(xcomqparm->sdsmessage))
               printf("%s", xcomqparm->sdsmessage);
            if (strlen(xcomqparm->rfile))
               printf("%s", xcomqparm->rfile);
            if (strlen(xcomqparm->in_out))
               printf("%s", xcomqparm->in_out);
            if (strlen(xcomqparm->remote_system))
               printf("%s", xcomqparm->remote_system);
            if (strlen(xcomqparm->end_time))
               printf("%s", xcomqparm->end_time);
            if (strlen(xcomqparm->pid))
               printf("%s", xcomqparm->pid);
            if (strlen(xcomqparm->user_group))
               printf("%s", xcomqparm->user_group);
            if (strlen(xcomqparm->curr_cond))
               printf("%s", xcomqparm->curr_cond);
            if (strlen(xcomqparm->curr_status))
               printf("%s", xcomqparm->curr_status);
            if (strlen(xcomqparm->curr_state))
               printf("%s", xcomqparm->curr_state);
            if (strlen(xcomqparm->rec_read_write))
               printf("%s", xcomqparm->rec_read_write);
            if (strlen(xcomqparm->byte_read_write))
               printf("%s", xcomqparm->byte_read_write);
            if (strlen(xcomqparm->blocks_trans))
               printf("%s", xcomqparm->blocks_trans);
            if (strlen(xcomqparm->bytes_trans))
               printf("%s", xcomqparm->bytes_trans);
            if (strlen(xcomqparm->neg_cipher))
               printf("%s", xcomqparm->neg_cipher);
            if (strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            /* call option 'R*' to remove queue entries */
            xcomqparm->funccode[0] = 'R';
            xcomqparm->funccode[1] = '*';
            rc=XcomQAPI(xcomqparm);
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* display detail information for removed queue entries */
            for (i = 0; i < xcomqparm->nQueueEntries; i++) {
                printf("%s", (*xcomqparm->pQueue)[i].array_message);
                printf("%s", (*xcomqparm->pQueue)[i].array_message2);
            }
            if ((xcomqparm->nQueueEntries == 0) && strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message); 
            if (!rc)
               printf("==== Call XcomQAPI successful !\n");
            else
               printf("==== %s\n", msgstring(rc, 0));
            /* call option 'gxxxxxx' to display queue entry information */
            memset(xcomqparm->lfile,0,sizeof(xcomqparm->lfile));
            memset(xcomqparm->rfile,0,sizeof(xcomqparm->rfile));
            memset(xcomqparm->file_option,0,sizeof(xcomqparm->file_option));
            xcomqparm->funccode[0] = 'g';
            strcpy(xcomqparm->tid, "000001");
            rc=XcomQAPI(xcomqparm);
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* display queue entry information */
            if (strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            if (strlen(xcomqparm->group_name))
               printf("%s", xcomqparm->group_name);
            if (strlen(xcomqparm->lfile))
               printf("%s", xcomqparm->lfile);
            if (strlen(xcomqparm->rfile))
               printf("%s", xcomqparm->rfile);
            if (strlen(xcomqparm->user_name))
               printf("%s", xcomqparm->user_name);
            if (strlen(xcomqparm->transfer_type))
               printf("%s", xcomqparm->transfer_type);
            if (strlen(xcomqparm->file_type))
               printf("%s", xcomqparm->file_type);
            if (strlen(xcomqparm->file_option))
               printf("%s", xcomqparm->file_option);
            /* call option 'pxxxxxx' to change value: FILE_OPTION LOCAL_FILE REMOTE_FILE
               note: This option is only allowed to be called when xcbp->state is in PREALLOCATION_STATE */
            xcomqparm->funccode[0] = 'p';
            strcpy(xcomqparm->tid, "000001");
            strcpy(xcomqparm->file_option, "CREATE");
            strcpy(xcomqparm->lfile, "c:\\user\\user\\test.txt");
            strcpy(xcomqparm->rfile, "c:\\temp\\test.del");
            rc=XcomQAPI(xcomqparm);
            /* check for error message */
            if (strlen((*xcomqparm->pQueue)[0].array_err_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_err_message);
            /* print out queue entry information */
            if (strlen((*xcomqparm->pQueue)[0].array_message))
               printf("%s", (*xcomqparm->pQueue)[0].array_message);
            printf("====  QAPI ended  ===\n");
         }
    }
    /* free memory */
    if (xcomqparm->pQueue != NULL)
       free(xcomqparm->pQueue);
    if (xcomqparm != NULL)
       free(xcomqparm);
}