280 lines
15 KiB
HTML
280 lines
15 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 in ILE C: User queue" />
|
||
|
<meta name="abstract" content="This program illustrates how to use APIs to create and manipulate a user queue." />
|
||
|
<meta name="description" content="This program illustrates how to use APIs to create and manipulate a user queue." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="ExTaskDataque.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="exuqilec" />
|
||
|
<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 in ILE C: User queue</title>
|
||
|
</head>
|
||
|
<body id="exuqilec"><a name="exuqilec"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example in ILE C: User queue</h1>
|
||
|
<div><p>This program illustrates how to use APIs to create and manipulate
|
||
|
a user queue.</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>
|
||
|
<pre>/*********************************************************************/
|
||
|
/* */
|
||
|
/*Program Name: UQUEUEX */
|
||
|
/* */
|
||
|
/*Program Language: ILE C */
|
||
|
/* */
|
||
|
/*Description: This program illustrates how to use APIs to create */
|
||
|
/* and manipulate a user queue. */
|
||
|
/* */
|
||
|
/* */
|
||
|
/*Header Files Included: <stdio.h> */
|
||
|
/* <signal.h> */
|
||
|
/* <string.h> */
|
||
|
/* <stdlib.h> */
|
||
|
/* <miptrnam.h> */
|
||
|
/* <miqueue.h> */
|
||
|
/* <pointer.h> */
|
||
|
/* <quscrtuq.h> */
|
||
|
/* <qusdltuq.h> */
|
||
|
/* <qusec.h> */
|
||
|
/* */
|
||
|
/*APIs Used: QUSCRTUQ - Create a user queue */
|
||
|
/* QUSDLTUQ - Delete a user queue */
|
||
|
/* */
|
||
|
/*********************************************************************/
|
||
|
/*********************************************************************/
|
||
|
/*********************************************************************/
|
||
|
/* Includes */
|
||
|
/*********************************************************************/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <signal.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <milib.h> /* from QCLE/h */
|
||
|
#include <miptrnam.h> /* from QCLE/h */
|
||
|
#include <miqueue.h> /* from QCLE/h */
|
||
|
#include <pointer.h>
|
||
|
#include <quscrtuq.h> /* from QSYSINC/h */
|
||
|
#include <qusdltuq.h> /* from QSYSINC/h */
|
||
|
#include <qusec.h> /* from QSYSINC/h */
|
||
|
|
||
|
/*********************************************************************/
|
||
|
/* Structures */
|
||
|
/*********************************************************************/
|
||
|
|
||
|
typedef struct {
|
||
|
Qus_EC_t ec_fields;
|
||
|
char exception_data[100];
|
||
|
} error_code_struct;
|
||
|
|
||
|
/*********************************************************************/
|
||
|
/* */
|
||
|
/* Main */
|
||
|
/* */
|
||
|
/*********************************************************************/
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
char text_desc[50];
|
||
|
error_code_struct error_code;
|
||
|
_SYSPTR queuelib_sysptr,
|
||
|
user_queue_obj_sysptr;
|
||
|
_RSLV_Template_T rslvsp_template;
|
||
|
_ENQ_Msg_Prefix_T enq_msg_prefix;
|
||
|
_DEQ_Msg_Prefix_T deq_msg_prefix;
|
||
|
char enq_msg[50],
|
||
|
deq_msg[50];
|
||
|
int success=0;
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Create a library to create the user queue into. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
system("CRTLIB LIB(QUEUELIB)");
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Initialize the error code parameter. */
|
||
|
/*******************************************************************/
|
||
|
error_code.ec_fields.Bytes_Provided=sizeof(error_code_struct);
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Call the QUSCRTUQ API to create a user queue. */
|
||
|
/* */
|
||
|
/* This will create a user queue called EXAMPLEQ in library */
|
||
|
/* QUEUELIB, with the following attributes: */
|
||
|
/* */
|
||
|
/* 1. Extended attribute of "VALID ", which could have */
|
||
|
/* been any valid *NAME. */
|
||
|
/* 2. A queue type of "F", or First-in, first-out. */
|
||
|
/* 3. A key length of 0. If the queue is not keyed, this */
|
||
|
/* value must be 0. */
|
||
|
/* 4. A maximum message size of 10 bytes. This number can */
|
||
|
/* be as large as 64K bytes. */
|
||
|
/* 5. The initial number of messages set to 10. */
|
||
|
/* 6. Additional number of messages set to 10. */
|
||
|
/* 7. Public authority of *USE. */
|
||
|
/* 8. A valid text description. */
|
||
|
/* 9. Replace option of *YES. This means that if a user queue */
|
||
|
/* already exists by the name specified, in the library */
|
||
|
/* specified, that it will be replaced by this */
|
||
|
/* request. */
|
||
|
/* 10. Domain value of *USER. */
|
||
|
/* 11. Pointer value of *NO. Messages in the queue cannot */
|
||
|
/* contain pointer data. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
memcpy(text_desc, "THIS IS TEXT FOR THE EXAMPLE USER QUEUE ",
|
||
|
50);
|
||
|
|
||
|
QUSCRTUQ("EXAMPLEQ QUEUELIB ", /* Qualified user queue name */
|
||
|
"VALID ", /* Extended attribute */
|
||
|
"F", /* Queue type */
|
||
|
0, /* Key length */
|
||
|
10, /* Maximum message size */
|
||
|
10, /* Initial number of messages */
|
||
|
10, /* Additional number of messages */
|
||
|
"*ALL ", /* Public authority */
|
||
|
text_desc, /* Text Description */
|
||
|
"*YES ", /* Replace existing user queue */
|
||
|
&error_code, /* Error code */
|
||
|
"*USER ", /* Domain of user queue */
|
||
|
"*NO "); /* Allow pointer data */
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* If an exception occurred, the API would have returned the */
|
||
|
/* exception in the error code parameter. The bytes available */
|
||
|
/* field will be set to zero if no exception occurred and greater */
|
||
|
/* than zero if an exception did occur. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
if (error_code.ec_fields.Bytes_Available > 0)
|
||
|
{
|
||
|
printf("ATTEMPT TO CREATE A USER QUEUE FAILED WITH EXCEPTION:%.7s",
|
||
|
error_code.ec_fields.Exception_Id);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Send information to the queue. */
|
||
|
/* */
|
||
|
/* We will need to use MI instructions to accomplish this. */
|
||
|
/* There are three steps that must be done: */
|
||
|
/* */
|
||
|
/* 1. Resolve a system pointer to the library containing the user */
|
||
|
/* queue object. */
|
||
|
/* 2. Using the system pointer to the library, resolve a system */
|
||
|
/* pointer to user queue object in the library. */
|
||
|
/* 3. Enqueue the entry using the system pointer for the user */
|
||
|
/* queue. */
|
||
|
/* */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* First we must resolve to library QUEUELIB. */
|
||
|
/*******************************************************************/
|
||
|
memset(rslvsp_template.Obj.Name,' ',30);
|
||
|
memcpy(rslvsp_template.Obj.Name,"QUEUELIB",8);
|
||
|
rslvsp_template.Obj.Type_Subtype = _Library; /* found in milib.h */
|
||
|
rslvsp_template.Auth = _AUTH_NONE; /* found in milib.h */
|
||
|
|
||
|
_RSLVSP6(&queuelib_sysptr, /* system pointer to be set */
|
||
|
&rslvsp_template, /* resolve template */
|
||
|
&rslvsp_template.Auth); /* authority to set in sysptr */
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* We can now resolve to the user queue object. We will pass the */
|
||
|
/* system pointer to library QUEUELIB to RSLVSP so the resolve */
|
||
|
/* will only search library QUEUELIB for the user queue object. */
|
||
|
/* This is necessary so that we ensure that we are using the */
|
||
|
/* correct object. */
|
||
|
/*******************************************************************/
|
||
|
memset(rslvsp_template.Obj.Name,' ',30);
|
||
|
memcpy(rslvsp_template.Obj.Name, "EXAMPLEQ", 8);
|
||
|
rslvsp_template.Obj.Type_Subtype = _Usrq; /* found in milib.h */
|
||
|
rslvsp_template.Auth = _AUTH_ALL; /* found in milib.h */
|
||
|
|
||
|
_RSLVSP8(&user_queue_obj_sysptr, /* system pointer to be set */
|
||
|
&rslvsp_template, /* resolve template */
|
||
|
&queuelib_sysptr, /* sysptr to library */
|
||
|
&rslvsp_template.Auth); /* authority to set in sysptr */
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Enqueue the entry. */
|
||
|
/*******************************************************************/
|
||
|
enq_msg_prefix.Msg_Len = 10;
|
||
|
enq_msg_prefix.Msg[0] = '\0'; /* Only used for keyed queues*/
|
||
|
memcpy(enq_msg, "EXAMPLE ", 10);
|
||
|
|
||
|
_ENQ(&user_queue_obj_sysptr, /* system pointer to user queue */
|
||
|
&enq_msg_prefix, /* message prefix */
|
||
|
(_SPCPTR)enq_msg); /* message text */
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Dequeue the entry. */
|
||
|
/*******************************************************************/
|
||
|
success = _DEQI(&deq_msg_prefix, /* message prefix */
|
||
|
(_SPCPTR)deq_msg, /* message text */
|
||
|
&user_queue_obj_sysptr); /* sys ptr to user queue */
|
||
|
|
||
|
if(success)
|
||
|
{
|
||
|
printf("Queue entry information: %.10s\n", deq_msg);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("Entry not dequeued\n");
|
||
|
}
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Delete the user queue. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
QUSDLTUQ("EXAMPLEQ QUEUELIB ", /* Qualified user queue name */
|
||
|
&error_code); /* Error code */
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* If an exception occurred, the API would have returned the */
|
||
|
/* exception in the error code parameter. The bytes available */
|
||
|
/* field will be set to zero if no exception occurred and greater */
|
||
|
/* than zero if an exception did occur. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
if (error_code.ec_fields.Bytes_Available > 0)
|
||
|
{
|
||
|
printf("ATTEMPT TO DELETE A USER QUEUE FAILED WITH EXCEPTION:%.7s",
|
||
|
error_code.ec_fields.Exception_Id);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
/*******************************************************************/
|
||
|
/* Delete the library created for this example. */
|
||
|
/*******************************************************************/
|
||
|
|
||
|
system("DLTLIB LIB(QUEUELIB)");
|
||
|
}
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="ExTaskDataque.htm" title="Data queues and user queues both provide a means for one or more processes to communicate asynchronously. The queues can be processed FIFO (first-in first-out), LIFO (last-in first-out), or by key.">Examples: Using data queues or user queues</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|