|
|
1.1 root 1: /* Customer.c
2: *
3: * This program emulates the gatekeeper placing requests in a queue that
4: * will be read by the headwaiter (see server.c). The following functions
5: * are illustrated here:
6: * DOSOPENQUEUE, DOSWRITEQUEUE, DOSCLOSEQUEUE
7: *
8: * This example first allocates a shared segment. It loops trying to open
9: * the queue until successful. It loops (for an arbitrary number of times)
10: * placing data in the shared segment and writing an element (with
11: * DataAddress pointing to the data in the shared segment) to the queue.
12: * The data is contained in the static array CustData. Each word represents
13: * a byte containing the priority of the request and a byte for the table.
14: * It writes the last element with RequestID set to indicate that this
15: * will be the last element to be written to the queue. It then frees the
16: * shared segment and then closes the queue.
17: *
18: * Compile as: cl -AL -G2 -Lp customer.c
19: *
20: * Copyright (C) Microsoft Corp. 1986
21: */
22:
23: #include <doscalls.h> /* 286DOS function declarations */
24: #include "defines.h" /* definitions for example programs */
25: #include <dos.h> /* contains FP_SEG and FP_OFF macros */
26:
27: #define ERROR_QUE_NAME_NOT_EXIST 343
28:
29: void main (argc, argv, envp)
30: int argc;
31: char *argv[];
32: char *envp;
33: {
34: register unsigned i; /* loop control variable */
35: unsigned TableID, /* table where a customer group is seated */
36: Priorty, /* Priority of Table */
37: *SharedSeg; /* pointer to shared segment */
38: unsigned OwnerPID, /* queue owner's PID */
39: QueueHandle, /* handle of queue */
40: SharedSel; /* selector to shared segment */
41: char type; /* type of example selected */
42: static unsigned CustData[MAXQWRITES] = {0x0600, 0x0501, 0x0802, 0x0003,
43: 0x0104, 0x0305, 0x0406, 0x0707};
44: /* represents customers requests */
45: /* in Format PPTT, where PP is */
46: /* priority and TT is table number */
47:
48: if (argc > 1){
49: ++argv;
50: type = *argv[0];
51: }
52: else type = 'd';
53:
54: /* allocate shared segment */
55: DOSALLOCSHRSEG ((unsigned) SEGSIZE, SEGNAME, &SharedSel);
56:
57: /* open the queue */
58: while (DOSOPENQUEUE (&OwnerPID, &QueueHandle, QUEUENAME) ==
59: ERROR_QUE_NAME_NOT_EXIST) /* keep trying to open the queue...*/
60: DOSSLEEP(1000L); /* ...until the server creates it */
61:
62: /* compute the address to the shared segment */
63: FP_SEG(SharedSeg) = SharedSel;
64: FP_OFF(SharedSeg) = 0;
65:
66: /* write some requests to the queue, emulating customer's requests */
67: TableID = 1;
68: if ((type == 'L') || (type == 'l')){
69: /* write data in LIFO format */
70:
71: DOSWRITEQUEUE (QueueHandle, NOMORE, DATALENGTH,
72: (char *) &SharedSeg[TableID++], /* any prio OK - not used */
73: LIFOPRIO);
74:
75: for (i = 0; i < MAXQWRITES; ++i){
76: SharedSeg[TableID] = CustData[i];
77: DOSWRITEQUEUE (QueueHandle, REQWAITER, DATALENGTH,
78: (char *) &SharedSeg[TableID++], LIFOPRIO);
79:
80: } /* endfor */
81:
82: } else {
83: /* write data in fifo/prio format */
84:
85: for (i = 0; i < MAXQWRITES; ++i){
86: SharedSeg[TableID] = CustData[i];
87: Priorty = CustData[i] >> 8; /* Priority must be a WORD */
88: DOSWRITEQUEUE (QueueHandle, REQWAITER, DATALENGTH,
89: (char *) &SharedSeg[TableID++], Priorty);
90: } /* endfor */
91:
92:
93: /* indicate there are no more customers */
94: DOSWRITEQUEUE (QueueHandle, NOMORE, DATALENGTH,
95: (char *) &SharedSeg[TableID], /* any prio OK - not used */
96: ELEMPRIORITY);
97: } /* endif */
98:
99:
100: /* free the shared segment */
101: DOSFREESEG (SharedSel);
102:
103: /* close the queue */
104: DOSCLOSEQUEUE (QueueHandle);
105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.