home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12191.ZIP / Q3.BAS next >
BASIC Source File  |  1990-02-02  |  5KB  |  189 lines

  1. '===== Q3.BAS =====
  2. REM $INCLUDE: 'queue.bi'
  3.  
  4. 'Function for dealing with shared memory (UTIL.BAS)
  5. DECLARE FUNCTION STRINGPOKE%(_
  6.               P1  AS ADDRESS,_
  7.               P2  AS STRING,_
  8.               P3  AS INTEGER)
  9. DECLARE FUNCTION STRINGPEEK%(_
  10.               P1  AS ADDRESS,_
  11.               P2  AS STRING,_
  12.               P3  AS INTEGER)
  13. DEFINT A-Z
  14. DIM info  AS ADDRESS
  15. DIM ep    AS STRING*1
  16.  
  17. 'Queue name
  18. QNAME$="\QUEUES\NANCY"+CHR$(0)
  19. QUEUETYPE=0    'FIFO
  20.  
  21. 'Create the Queue
  22. PRINT
  23. PRINT "Creating the Queue"
  24. PRINT
  25. x=DosCreateQueue%(QHandle,QueueType,varseg(Qname$),sadd(Qname$))
  26. IF (x) THEN
  27.    Print "An error occurred.  The number is : ";x
  28.    stop
  29. ELSE
  30.    Print "The QUEUE ";qname$;" was CREATED"
  31.    PRINT "The HANDLE is : ";qhandle
  32. END IF
  33.  
  34. 'Allocate memory for the Queue
  35. PRINT
  36. PRINT "Allocating Memory"
  37. PRINT
  38. SIZE=1024
  39. ALLOCFLAGS=7
  40. x=DosAllocSeg%(size,selector,allocflags)
  41. IF (x) THEN
  42.    Print "An error occurred.  The number is : ";x
  43.    stop
  44. ELSE
  45.    Print "The SEGMENT ";selector;" was CREATED"
  46. END IF
  47.  
  48. 'Place the data into memory and write the item to the Queue
  49. PRINT
  50. PRINT "Writing Data to the Queue
  51. PRINT
  52. FOR i = 0 to 5
  53.    info.segment=selector
  54.    info.offset=i*10
  55.    st$="ITEM"+str$(i)
  56.    strlen=len(st$)
  57.    IF (stringpoke%(info,st$,strlen)) THEN
  58.       PRINT "ERROR"
  59.    ELSE
  60.       x=DosWriteQueue%(QHandle,i+5,strlen,info.segment,info.offset,0)
  61.       IF (x) THEN
  62.          Print "An error occurred.  The number is : ";x
  63.      END IF
  64.    END IF
  65. NEXT i
  66. PRINT
  67. PRINT "Loop until information is in the Queue"
  68. PRINT
  69. 'Loop until an error or item in the Queue
  70. DO
  71.    x=DosQueryQueue%(Qhandle,number)
  72. 'loop until error or number > 0:
  73. LOOP WHILE ( (x <> 0)  and (number <> 0) )
  74.  
  75. PRINT
  76. PRINT "Read the Information from the Queue"
  77. PRINT
  78. 'If error continue or read from the Queue
  79. IF (x) THEN
  80.    Print "An Error Occurred.  The number is : ";x
  81. ELSE
  82.    PRINT "There are ";number;" items in the QUEUE"
  83.    FOR i = 1 to number
  84.       x=DosReadQueue%(Qhandle,pr&,dlen,_
  85.                       item&,0%,1%,varseg(ep),varptr(ep),1&)
  86.       IF (x) THEN
  87.          Print "An error occurred.  The number is : ";x
  88.       ELSE
  89.          info.segment=item& \ (2^16)
  90.          info.offset=item& mod (2^16)
  91.  
  92.          IF (stringpeek(info,st$,dlen)) THEN
  93.             PRINT "ERROR"
  94.          ELSE
  95.             Print "The item in the QUEUE was : ";st$
  96.          END IF
  97.       END IF
  98.    NEXT i
  99. END IF
  100. PRINT "Hit Any Key to Continue..."
  101. WHILE INKEY$="" : WEND
  102. PRINT
  103. PRINT "Writing More information to the Queue"
  104.  
  105. 'Write more information into the Queue
  106. FOR i = 6 to 11
  107.    info.segment=selector
  108.    info.offset=i*10
  109.    st$="ITEM"+str$(i)
  110.    strlen=len(st$)
  111.    IF (stringpoke%(info,st$,strlen)) THEN
  112.       PRINT "ERROR"
  113.    ELSE
  114.       x=DosWriteQueue%(QHandle,i+5,strlen,info.segment,info.offset,0)
  115.       IF (x) THEN
  116.          Print "An error occurred.  The number is : ";x
  117.      END IF
  118.    END IF
  119. NEXT i
  120. 'loop until error or number > 0
  121. DO
  122.    x=DosQueryQueue%(Qhandle,number)
  123. LOOP WHILE ( (x <> 0)  and (number <> 0) )
  124. PRINT
  125. PRINT "Peeking in the Queue (Note: The items aren't removed)"
  126. PRINT
  127.  
  128. 'Look at items in the Queue, but don't remove them
  129. IF (x) THEN
  130.    Print "An Error Occurred.  The number is : ";x
  131. ELSE
  132.    PRINT "There are ";number;" items in the QUEUE"
  133.    FOR i = 1 to number
  134.       x=DosPeekQueue%(Qhandle,pr&,dlen,item&,elm,1%,_
  135.                       varseg(ep),varptr(ep),1&)
  136.       IF (x) THEN
  137.          Print "An error occurred.  The number is : ";x
  138.       ELSE
  139.          info.segment=item& \ (2^16)
  140.          info.offset=item& mod (2^16)
  141.          IF (stringpeek(info,st$,dlen)) THEN
  142.             PRINT "ERROR"
  143.          ELSE
  144.             Print "The item in the QUEUE was : ";st$
  145.          END IF
  146.       END IF
  147.    NEXT i
  148. END IF
  149. PRINT
  150. PRINT "Peek Complete. View number of items in the Queue"
  151. PRINT
  152.  
  153. 'See how many items are left
  154. x=DosQueryQueue%(Qhandle,number)
  155. IF (x) THEN
  156.    Print "An error occurred.  The number is : ";x
  157. ELSE
  158.    PRINT "There are ";number;" items in the QUEUE"
  159. END IF
  160. 'Delete the items in the Queue
  161. PRINT
  162. PRINT "Purge the Queue"
  163. PRINT
  164. x=DosPurgeQueue%(Qhandle)
  165. IF (x) THEN
  166.    Print "An error occurred.  The number is : ";x
  167. ELSE
  168.    Print "The QUEUE was PURGED"
  169. END IF
  170.  
  171. 'See how many items are left
  172. x=DosQueryQueue%(Qhandle,number)
  173. IF (x) THEN
  174.    Print "An error occurred.  The number is : ";x
  175. ELSE
  176.    PRINT "There are ";number;" items in the QUEUE"
  177. END IF
  178. PRINT
  179. PRINT "Close the Queue"
  180. PRINT
  181. 'Close the Queue
  182. x=DosCloseQueue%(Qhandle)
  183. IF (x) THEN
  184.    Print "An error occurred.  The number is : ";x
  185. ELSE
  186.    Print "The QUEUE was closed."
  187. END IF
  188. END
  189.