Example: Creating a batch machine

This program enters commands to be processed onto a queue called 'TESTQ' in Library 'QGPL'.

Note: Read the Code license and disclaimer information for important legal information.

These ILE C programs emulate a batch machine. One program, $USQEXSRV, acts as a server and takes the entries off a user queue and then runs the request through the Execute Command (QCMDEXC) API. The other program, $USQEXREQ, acts as a requester and puts the entries into a user space. The APIs used in this example are:

Requester program ($USQEXREQ)

The following is a requester program using ILE C:

/********************************************************************/
/*  PROGRAM:  $USQEXREQ                                             */
/*                                                                  */
/*  LANGUAGE:  ILE C                                                */
/*                                                                  */
/*  DESCRIPTION:  THIS PROGRAM ENTERS COMMANDS TO BE PROCESSED ONTO */
/*    A QUEUE CALLED 'TESTQ' IN LIBRARY 'QGPL'.  THE USER WILL BE   */
/*    PROMPTED TO ENTER AS MANY COMMANDS (UNDER 51 CHARACTERS) AS   */
/*    IS DESIRED.  WHEN THE USER WISHES TO END THE PROGRAMS,        */
/*    ALL THAT NEED BE DONE IS ENTER 'quit' AT THE PROMPT.          */
/*                                                                  */
/*  APIs USED:                                                      */
/*                                                                  */
/********************************************************************/
#include <stdio.h>
#include <string.h>
#include <miqueue.h>
#include <miptrnam.h>


main()
{
_ENQ_Msg_Prefix_T e_msg_prefix;
_SYSPTR queue;
char INMsg[100];

/********************************************************************/
/*  Resolve to the queue created by $USQEXSRV.                      */
/********************************************************************/

queue = rslvsp(_Usrq,"TESTQ","QGPL",_AUTH_ALL);
e_msg_prefix.Msg_Len = 100;

/********************************************************************/
/*  Loop until the user enters 'quit' as the command.               */
/********************************************************************/

  while (1) {
    printf("\nEnter command to put on queue, or 'quit' \n ");
    scanf("%100s", INMsg);
    gets(INMsg);
    printf("\nCommand entered was ==> %.100s\n",INMsg);

/********************************************************************/
/*  Check to see if the user entered 'quit' as the command.         */
/*  If true then break out of the 'while' loop.                     */
/********************************************************************/

    if ((strncmp(INMsg,"quit",4) == 0)||(strncmp(INMsg,"QUIT",4) == 0))
      { break; }

/********************************************************************/
/*  Add the user-entered command to the queue.                      */
/********************************************************************/

    enq(queue,&e_msg_prefix,INMsg);
    strcpy(INMsg," ");
  } /*while*/

/********************************************************************/
/*  Add the command end to the queue which causes the               */
/*  server program ($USQEXSRV) to end                               */
/********************************************************************/

  strcpy(INMsg,"END");
  enq(queue,&e_msg_prefix,INMsg);
} /* $USQEXREQ */

To create the requester program using ILE C, specify the following:

CRTBNDC PGM(QGPL/$USQEXREQ) SRCFILE(QGPL/QCSRC)

Server program ($USQEXSRV)

The following is the server program using ILE C:

/********************************************************************/
/*  PROGRAM:  $USQEXSRV                                             */
/*                                                                  */
/*  LANGUAGE:  ILE C                                                */
/*                                                                  */
/*  DESCRIPTION:  THIS PROGRAM EXTRACTS COMMANDS TO BE RUN FROM     */
/*    A QUEUE CALLED 'TESTQ' IN LIBRARY 'QGPL'.  THE COMMANDS WILL  */
/*    BE EXTRACTED AND RUN IN FIFO ORDER.  THE QUEUE WILL BE        */
/*    CREATED PRIOR TO USE AND SHOULD BE DELETED AFTER EACH USE     */
/*    OF THIS EXAMPLE PROGRAM.  THIS PROGRAM END WHEN IT            */
/*    EXTRACTS THE COMMAND 'END' FROM THE QUEUE.                    */
/*       THE FLOW IS AS FOLLOWS:                                    */
/*         (1)  CREATE THE USER QUEUE                               */
/*         (2)  ENTER LOOP                                          */
/*         (3)     WAIT FOREVER FOR A COMMAND ON THE QUEUE          */
/*         (4)      IF COMMAND IS 'END' THEN EXIT LOOP              */
/*         (5)      ELSE RUN COMMAND, RESTART LOOP                  */
/*         (6)  END LOOP                                            */
/*    FOR BEST RESULTS, THIS PROGRAM CAN BE CALLED BY THE USER, THEN*/
/*    THE $USQEXREQ SHOULD BE CALLED FROM ANOTHER SESSION.          */
/*                                                                  */
/* APIs USED:  QCMDEXC, QUSCRTUQ                                    */
/*                                                                  */
/********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <micomput.h>
#include <miqueue.h>
#include <miptrnam.h>
#include <quscrtuq.h>
#include <qcmdexc.h>


main()
{
_DEQ_Msg_Prefix_T d_msg_prefix;
_SYSPTR           queue;
char              OUTMsg[100];
int               cmd_name_lngth;
decimal(15,5)     pack_name_lngth;
char              igc_param[] = "IGC";

/********************************************************************/
/*    Set up the parameters to be used in the call to 'QUSCRTUQ'    */
/********************************************************************/

char q_name[]= "TESTQ     QGPL      ";
char ext_atr[]= "TESTER    ";
char q_type[]= "F";
int key_lngth = 0;
int max_msg_s = 100;
int int_msgs  = 10;
int add_msgs = 50;
char auth[]  = "*ALL      ";
char desc[] = "Description .....    ";

/********************************************************************/
/*  Call the 'QUSCRTUQ' program to create the user queue.           */
/********************************************************************/

  QUSCRTUQ(q_name,ext_atr,q_type,key_lngth,max_msg_s,int_msgs,
           add_msgs,auth,desc);

/********************************************************************/
/*  Resolve to the queue created above.                             */
/********************************************************************/

  queue = rslvsp(_Usrq,"TESTQ","QGPL",_AUTH_ALL);

/********************************************************************/
/*  Set the deq operation to wait for command indefinitely.         */
/********************************************************************/

  d_msg_prefix.Wait_Forever = 1;

/********************************************************************/
/*  Loop until the command 'END' is extracted from the queue        */
/********************************************************************/

  while (1) {
    deq(&d_msg_prefix,OUTMsg,queue);

/********************************************************************/
/*  Check to see if the command extracted is 'END'                  */
/*  If true then break out of the 'while' loop.                     */
/********************************************************************/

    if (strncmp(OUTMsg,"END",3) == 0)
      { break; }
    cmd_name_lngth = strlen(OUTMsg);

/********************************************************************/
/*  Convert the integer in cmd_name_lngth to a packed decimal       */
/********************************************************************/

    cpynv(NUM_DESCR(_T_PACKED,15,5), &pack_name_lngth,
          NUM_DESCR(_T_SIGNED,4,0), &cmd_name_lngth);

/********************************************************************/
/*  Execute the command extracted from the queue                    */
/********************************************************************/

    QCMDEXC(OUTMsg,pack_name_lngth,igc_param);
  } /* while */
}  /* $USQEXSRV */

To create the server program using ILE C, specify the following:

CRTBNDC PGM(QGPL/$USQEXSRV) SRCFILE(QGPL/QCSRC)