1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Bull Inc., 1987                *
  4    *                                                         *
  5    * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6    *                                                         *
  7    *********************************************************** */
  8 
  9 /* HISTORY COMMENTS:
 10   1) change(86-07-11,Westcott), approve(87-07-13,MCR7580),
 11      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12      Created.
 13                                                    END HISTORY COMMENTS */
 14 
 15 /* : PROCEDURE FUNCTION (i_getbgm)
 16 
 17 Get the next enqueued message from a background application that was sent
 18 to the foreground application. This routine should only be called by a
 19 foreground application since the messages are assumed to be intended for
 20 a human being.
 21 */
 22 
 23 #include <dos.h>
 24 #include <alloc.h>
 25 #include <cat.h>
 26 #include <ws_dcls.h>
 27 #include <ws_error.h>
 28 #include <ws_msg.h>
 29 #include <ws_fgb.h>
 30 #include <wsmincap.h>
 31 
 32 #define NULL 0
 33 
 34 extern struct fgbstr *bgbfptr;         /* first buffer on linked list */
 35 extern struct fgbstr *bgblptr;         /* last buffer on linked list */
 36 extern struct fgbstr *sgbfptr;         /* first buffer on linked list */
 37 extern struct fgbstr *sgblptr;         /* last buffer on linked list */
 38 extern struct allocstr *bgaptr;        /* allocation data for linked list*/
 39 extern int bgcount;                    /* count of bg messages in linked list */
 40 
 41 i_getbgm (p_param)
 42 
 43 struct gbgmsg_struc *p_param;
 44 {
 45 int i;                  /* copy counter */
 46 char *s1;               /* pointer to source for copy */
 47 char *d1;               /* pointer to destination of copy */
 48 struct fgbstr *bgbp;    /* pointer to current message structure */
 49 struct query_msg *qrp;  /* definition of query/reply message */
 50 
 51 /* : if a status message is desired
 52      - If no status messages on queue return WSNOMESS
 53      - Remove bg buffer from queue    */
 54 
 55    if (p_param -> bg_type == STATUS_REPLY) {
 56       if (sgbfptr == NULL) {
 57          sgblptr = NULL;
 58          return (WSNOMESS);
 59       }
 60 
 61       bgbp = sgbfptr;
 62       sgbfptr = bgbp -> fgb_next;
 63       if (sgbfptr == NULL)
 64          sgblptr = NULL;
 65    }
 66 
 67 /* : else if a background message is desired
 68      - If no bg messages on queue, reset bgcount, and return WSNOMESS
 69      - Remove bg buffer from queue    */
 70 
 71    else {
 72       if (bgbfptr == NULL) {
 73          bgcount = 0;
 74          bgblptr = NULL;
 75          return (WSNOMESS);
 76       }
 77 
 78       bgbp = bgbfptr;
 79       bgbfptr = bgbp -> fgb_next;
 80       --bgcount;
 81       if (bgbfptr == NULL) {
 82          bgcount = 0;
 83          bgblptr = NULL;
 84       }
 85    }
 86 
 87 /* : copy buffer contents to p_param     */
 88 
 89    p_param -> length = bgbp -> fgb_length - 2;        /* Subtract out sysid, cap */
 90    qrp = (struct query_msg *) &bgbp -> fgb_minor;
 91    d1 = &p_param -> bgmsg[0];
 92    s1 = &qrp -> msg_data[0];
 93    for(i = 0; i < p_param -> length; i++)
 94       *d1++ = *s1++;
 95 
 96 /* : insert sender major and type into structure */
 97 
 98    c_pack (qrp -> source_system, qrp -> source_major, &p_param -> sender_major);
 99    p_param -> bg_type = (int) bgbp -> fgb_minor;
100 
101 /* : Free the buffer */
102 
103    wsfree(bgaptr,bgbp);
104 
105    return(0);
106 }
107 ^Z