ibm-information-center/dist/eclipse/plugins/i5OS.ic.apiref_5.4.0.1/apiexcremac.htm

234 lines
11 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Creating a batch machine" />
<meta name="abstract" content="This program enters commands to be processed onto a queue called 'TESTQ' in Library 'QGPL'." />
<meta name="description" content="This program enters commands to be processed onto a queue called 'TESTQ' in Library 'QGPL'." />
<meta name="DC.Relation" scheme="URI" content="apiexmp.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="apiexcremac" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Creating a batch machine</title>
</head>
<body id="apiexcremac"><a name="apiexcremac"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Creating a batch machine</h1>
<div><p>This program enters commands to be processed onto a queue called
'TESTQ' in Library 'QGPL'.</p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
legal information.</div>
<p>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:</p>
<ul><li>Create User Queue (QUSCRTUQ)</li>
<li>Execute Command (QCMDEXC)</li>
</ul>
</div>
<div class="section"><h4 class="sectiontitle">Requester program ($USQEXREQ)</h4><p>The following is a
requester program using ILE C:</p>
<pre>/********************************************************************/
/* 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 &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;miqueue.h&gt;
#include &lt;miptrnam.h&gt;
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 ==&gt; %.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,&amp;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,&amp;e_msg_prefix,INMsg);
} /* $USQEXREQ */</pre>
<p>To create the requester program using ILE C, specify the following:</p>
<pre>CRTBNDC PGM(QGPL/$USQEXREQ) SRCFILE(QGPL/QCSRC)</pre>
</div>
<div class="section"><h4 class="sectiontitle">Server program ($USQEXSRV)</h4><p>The following is the
server program using ILE C:</p>
<pre>/********************************************************************/
/* 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 &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;micomput.h&gt;
#include &lt;miqueue.h&gt;
#include &lt;miptrnam.h&gt;
#include &lt;quscrtuq.h&gt;
#include &lt;qcmdexc.h&gt;
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(&amp;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), &amp;pack_name_lngth,
NUM_DESCR(_T_SIGNED,4,0), &amp;cmd_name_lngth);
/********************************************************************/
/* Execute the command extracted from the queue */
/********************************************************************/
QCMDEXC(OUTMsg,pack_name_lngth,igc_param);
} /* while */
} /* $USQEXSRV */</pre>
<p>To create the server program using ILE C, specify the following:</p>
<pre>CRTBNDC PGM(QGPL/$USQEXSRV) SRCFILE(QGPL/QCSRC)</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="apiexmp.htm" title="Contains example programs that use APIs and exit programs.">Examples: APIs</a></div>
</div>
</div>
</body>
</html>