|
|
Microsoft OS/2 SDK 03-01-1988
/* Customer.c
*
* This program emulates the gatekeeper placing requests in a queue that
* will be read by the headwaiter (see server.c). The following functions
* are illustrated here:
* DosOpenQueue, DosWriteQueue, DosCloseQueue
*
* This example first allocates a shared segment. It loops trying to open
* the queue until successful. It loops (for an arbitrary number of times)
* placing data in the shared segment and writing an element (with
* DataAddress pointing to the data in the shared segment) to the queue.
* The data is contained in the static array CustData. Each word represents
* a byte containing the priority of the request and a byte for the table.
* It writes the last element with RequestID set to indicate that this
* will be the last element to be written to the queue. It then frees the
* shared segment and then closes the queue.
*
* Compile as: cl -AL -G2 -Lp customer.c
*
* Created by Microsoft Corp. 1986
*/
#define INCL_DOSMEMMGR
#define INCL_DOSQUEUES
#define INCL_DOSERRORS
#define INCL_DOSPROCESS
#include <os2def.h> /* contains SELECTOROF and
OFFSETOF macros */
#include <bse.h> /* MS OS/2 function declarations */
#include "defines.h" /* definitions for example programs */
void main (argc, argv, envp)
int argc;
char *argv[];
char *envp;
{
register unsigned i; /* loop control variable */
unsigned TableID, /* table where a customer group is seated */
Priorty, /* Priority of Table */
*SharedSeg; /* pointer to shared segment */
USHORT OwnerPID; /* queue owner's PID */
HQUEUE QueueHandle; /* handle of queue */
SEL SharedSel; /* selector to shared segment */
char type; /* type of example selected */
static unsigned CustData[MAXQWRITES] = {0x0600, 0x0501, 0x0802, 0x0003,
0x0104, 0x0305, 0x0406, 0x0707};
/* represents customers requests */
/* in Format PPTT, where PP is */
/* priority and TT is table number */
if (argc > 1){
++argv;
type = *argv[0];
}
else type = 'd';
/* allocate shared segment */
DosAllocShrSeg (SEGSIZE, SEGNAME, &SharedSel);
/* open the queue */
while (DosOpenQueue (&OwnerPID, &QueueHandle, QUEUENAME) ==
ERROR_QUE_NAME_NOT_EXIST) /* keep trying to open the queue...*/
DosSleep(1000L); /* ...until the server creates it */
/* compute the address to the shared segment */
SELECTOROF(SharedSeg) = SharedSel;
OFFSETOF(SharedSeg) = 0;
/* write some requests to the queue, emulating customer's requests */
TableID = 1;
if ((type == 'L') || (type == 'l')){
/* write data in LIFO format */
DosWriteQueue (QueueHandle, NOMORE, DATALENGTH,
(PBYTE) &SharedSeg[TableID++], /* any prio OK - not used */
LIFOPRIO);
for (i = 0; i < MAXQWRITES; ++i){
SharedSeg[TableID] = CustData[i];
DosWriteQueue (QueueHandle, REQWAITER, DATALENGTH,
(PBYTE) &SharedSeg[TableID++], LIFOPRIO);
} /* endfor */
} else {
/* write data in fifo/prio format */
for (i = 0; i < MAXQWRITES; ++i){
SharedSeg[TableID] = CustData[i];
Priorty = CustData[i] >> 8; /* Priority must be a WORD */
DosWriteQueue (QueueHandle, REQWAITER, DATALENGTH,
(PBYTE) &SharedSeg[TableID++], Priorty);
} /* endfor */
/* indicate there are no more customers */
DosWriteQueue (QueueHandle, NOMORE, DATALENGTH,
(PBYTE) &SharedSeg[TableID], /* any prio OK - not used */
ELEMPRIORITY);
} /* endif */
/* free the shared segment */
DosFreeSeg (SharedSel);
/* close the queue */
DosCloseQueue (QueueHandle);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.