Annotation of os2sdk/demos/examples/queues/cust.c, revision 1.1.1.2

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:
1.1.1.2 ! root        6:  *     DosOpenQueue, DosWriteQueue, DosCloseQueue
1.1       root        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:  *
1.1.1.2 ! root       20:  * Created by Microsoft Corp. 1986
1.1       root       21:  */
                     22: 
1.1.1.2 ! root       23: #define INCL_DOSMEMMGR
        !            24: #define INCL_DOSQUEUES
        !            25: #define INCL_DOSERRORS
        !            26: #define INCL_DOSPROCESS
        !            27: 
        !            28: #include <os2def.h>                    /* contains SELECTOROF and
        !            29:                                           OFFSETOF macros */
        !            30: #include <bse.h>                       /* MS OS/2 function declarations */
1.1       root       31: #include "defines.h"                    /* definitions for example programs */
                     32: 
                     33: 
                     34: void main (argc, argv, envp)
                     35:     int argc;
                     36:     char *argv[];
                     37:     char *envp;
                     38: {
                     39:         register unsigned i;    /* loop control variable         */
                     40:         unsigned  TableID,      /* table where a customer group is seated */
                     41:                   Priorty,       /* Priority of Table */
                     42:                   *SharedSeg;   /* pointer to shared segment     */
1.1.1.2 ! root       43:        USHORT   OwnerPID;      /* queue owner's PID             */
        !            44:        HQUEUE   QueueHandle;   /* handle of queue               */
        !            45:        SEL      SharedSel;     /* selector to shared segment    */
1.1       root       46:         char     type;          /* type of example selected      */
                     47:         static unsigned CustData[MAXQWRITES] = {0x0600, 0x0501, 0x0802, 0x0003,
                     48:                                                 0x0104, 0x0305, 0x0406, 0x0707};
                     49:                                 /* represents customers requests */
                     50:                                 /* in Format PPTT, where PP is   */
                     51:                                 /* priority and TT is table number */
                     52: 
                     53:         if (argc > 1){
                     54:            ++argv;
                     55:            type = *argv[0];
                     56:         }
                     57:         else type = 'd';
                     58: 
                     59:         /* allocate shared segment */
1.1.1.2 ! root       60:        DosAllocShrSeg (SEGSIZE, SEGNAME, &SharedSel);
1.1       root       61: 
                     62:         /* open the queue */
1.1.1.2 ! root       63:        while (DosOpenQueue (&OwnerPID, &QueueHandle, QUEUENAME) ==
1.1       root       64:                ERROR_QUE_NAME_NOT_EXIST) /* keep trying to open the queue...*/
1.1.1.2 ! root       65:                  DosSleep(1000L);       /* ...until the server creates it  */
1.1       root       66: 
                     67:         /* compute the address to the shared segment */
1.1.1.2 ! root       68:        SELECTOROF(SharedSeg) = SharedSel;
        !            69:        OFFSETOF(SharedSeg) = 0;
1.1       root       70: 
                     71:         /* write some requests to the queue, emulating customer's requests  */
                     72:         TableID = 1;
                     73:         if ((type == 'L') || (type == 'l')){
                     74:            /* write data in LIFO format */
                     75: 
1.1.1.2 ! root       76:           DosWriteQueue (QueueHandle, NOMORE, DATALENGTH,
        !            77:                          (PBYTE) &SharedSeg[TableID++], /* any prio OK - not used */
1.1       root       78:                           LIFOPRIO);
                     79: 
                     80:            for (i = 0; i < MAXQWRITES; ++i){
                     81:              SharedSeg[TableID] = CustData[i];
1.1.1.2 ! root       82:             DosWriteQueue (QueueHandle, REQWAITER, DATALENGTH,
        !            83:                            (PBYTE) &SharedSeg[TableID++], LIFOPRIO);
1.1       root       84: 
                     85:            } /* endfor */
                     86: 
                     87:         } else {
                     88:            /* write data in fifo/prio format */
                     89: 
                     90:            for (i = 0; i < MAXQWRITES; ++i){
                     91:              SharedSeg[TableID] = CustData[i];
                     92:              Priorty = CustData[i] >> 8;      /* Priority must be a WORD */
1.1.1.2 ! root       93:             DosWriteQueue (QueueHandle, REQWAITER, DATALENGTH,
        !            94:                           (PBYTE) &SharedSeg[TableID++], Priorty);
1.1       root       95:            } /* endfor */
                     96: 
                     97: 
                     98:            /* indicate there are no more customers */
1.1.1.2 ! root       99:           DosWriteQueue (QueueHandle, NOMORE, DATALENGTH,
        !           100:                          (PBYTE) &SharedSeg[TableID], /* any prio OK - not used */
1.1       root      101:                           ELEMPRIORITY);
                    102:         } /* endif */
                    103: 
                    104: 
                    105:         /* free the shared segment */
1.1.1.2 ! root      106:        DosFreeSeg (SharedSel);
1.1       root      107: 
                    108:         /* close the queue */
1.1.1.2 ! root      109:        DosCloseQueue (QueueHandle);
1.1       root      110: }
1.1.1.2 ! root      111: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.