Date: Tue, 13 Jul 2010 09:13:18 +1000
Subject: Re: [C400-L] keyed user queue
On 13/07/2010, at 7:29 AM, Victor Gonzalez wrote:
I need to make an application that use keyed user
queue. All examples in ibm site are with FIFO user queue.
wondering if anyone in this mailing list have a simple example on
use user queue with key, or any documentation where i can read in
detail about the api for user queue ( i already checked ibm site )
You didn't look very hard then. See the Information Centre:
Programming->APIs by category->Objects->User Queue APIs->Using User
This page says you need to use MI instructions to access the queue.
The "batch machine" example on this page shows that MI instructions
ENQ and DEQ (or rather the C function interfaces--enq() and deq() are
used). Knowing that these are MI instructions might prompt you to look
Programming->Machine interface programming->Machine interface
instructions->i5/OS machine interface
where you will find documentation for the MI instructions. Also, the
ILE C/C++ MI Library Reference (SC09-2418), which hasn't been updated
in over a decade, provides documentation for the C function interfaces
to MI. Note that they are really ILE interfaces and can be called from
any ILE language that supports the necessary data types.
The MI Library Reference lists the C header files for each function.
You will need to use the header file and the MI instruction
documentation to determine appropriate values for keyed operations.
These are found in the QSYSINC library if the optional System Openness
Includes have been installed on your system.
Essentially, create the user queue via QUSCRTUQ API specifying
suitable key length and message size. Then in your program allocate
sufficient space to a pointer of type _ENQ_Msg_Prefix_T. Populate the
Msg_Len field with the length of the text address by parameter 2,
populate the Msg array with the key value, then invoke enq passing a
resolved system pointer to the queue object, the prefix pointer (i.e.,
key structure), and the address of the message text. Fetching a queue
entry is essentially the reverse process; allocate sufficient space to
a pointer of type _DEQ_Msg_Prefix_T. Populate wait time fields, the
search relationship field (EQ, GT, etc.), and the search key and pass
it to deq().
Declare system pointer Q
Declare pointer E of type _ENQ_Msg_Prefix_T
Declare pointer D of type _DEQ_Msg_Prefix_T
Declare field T of type char large enough for message text
Declare field rc of type integer
/* Create a keyed user queue with key-length 32 bytes and message
length 500 bytes */
/* Initially has room for 100 messages and will expand by 10
messages as it fills up */
CALL QUSCRTUQ( "QUEUENAME LIBNAME ", "EXT ATTR ", "K", 32, 500,
100, 10, "*USE ", "Description")
set Q to resolved address of user queue object
allocate space for E: 4-byte length plus key size
set Msg_Len field in E to length of message text
set Msg field in E to key value
set T to message text
/* invoke MI enq instruction to add message to queue */
rc = enq( Q, E, T )
if rc is 0 then handle error
allocate space for D: room for two 8-byte time stamps, integer, bit
fields, plus twice key size
set Key_Relation field in D to _DEQ_GEQ (or whatever search
relationship you want)
set Key field in D to key search criteria--partial key is allowed
set Wait_Time in D to MI time-stamp of time at which to end waiting
set Wait_Forever field in D to true
/* invoke MI deq instruction to fetch message from queue */
rc = deq( D, T, Q );
if rc is 1 then process message in T
etc. etc. etc.
FlyByNight Software OS/400, i5/OS Technical Specialists
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
ASCII Ribbon campaign against HTML E-Mail / \
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
As an Amazon Associate we earn from qualifying purchases.
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.