home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / test80.zip / TEST80.TXT < prev    next >
Text File  |  1994-01-11  |  6KB  |  140 lines

  1.             Example of RxQueue & Intertask Communication
  2.  
  3. This package and its contents were written by Dick Goran, author of
  4. the "REXX Reference Summary Handbook" (CIS 72200,347; IBMLink
  5. DEV4672; FIDO 1:209/705; Internet 72200.347@compuserve.com), in
  6. response to a question posted on the CompuServe OS2DF1 forum. It is
  7. released to the general domain with the hope that it might help
  8. others understand the use of REXX queues and intertask
  9. communication and synchronization between multiple programs using
  10. REXX.
  11.  
  12. This package should contain the following files:
  13.  
  14.      TEST80A.CMD    The parent program.
  15.      TEST80B.CMD    The child program.
  16.      TEST80.TXT     This file.
  17.      TEST80.TRC     An annotated TRACE R output of both programs
  18.                     showing the interaction of the two.
  19.  
  20. I have applied sequence numbers to both of the programs for two
  21. reasons: 1) to make discussion of them easier; 2) to correlate the
  22. source statements to the .TRC trace output file.
  23.  
  24. It is assumed that the user has loaded and registered the REXXUTIL
  25. DLL with:
  26.  
  27.      call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  28.      call SysLoadFuncs
  29.  
  30. This is best accomplished within a STARTUP.CMD since it is then
  31. accomplished automatically when OS/2 is IPL'ed (Initial Program
  32. Load).
  33.  
  34. The following indicates the functions of each program in a time-
  35. line fashion, of sorts. The numbers preceding each description
  36. relate to the sequence numbers in the respective source programs.
  37.  
  38. TEST80A   TEST80B
  39. -------   -------
  40. 02 - 03   The value of an environment variable, TRACE, is retrieved
  41.           for the session and used as and expression in a TRACE
  42.           command. If the environment variable has not been set, no
  43.           tracing will occur in either the parent or the child.
  44.  
  45.           The NOP command is present because of a quirk in the REXX
  46.           trace facility which can cause a trace line which would
  47.           be desired to be ignored. If an instruction is ignored,
  48.           it will be the NOP command.
  49.  
  50.           Since there is no way to use a similar environment
  51.           variable in the child's session, this value is passed to
  52.           the child as a calling parameter.
  53.  
  54. 06 - 08   A new queue, named TEST80, will be created and made the
  55.           active queue. The active queue at the times (normally
  56.           SESSION) is stored in the variable "old_queue" for later
  57.           restoration.
  58.  
  59. 11 - 14   Two lines, each containing "TEST80 - Line number n"
  60.           (where n is the line number) are stowed in the active
  61.           queue with the QUEUE command in a FIFO (first in, first
  62.           out) manner.
  63.  
  64. 16 - 19   The child, TEST80B.CMD is started, minimized (/MIN). This
  65.           new task will have a title of "Test80B Child" which will
  66.           appear in both the OS/2 task list (Ctrl-Esc) and the
  67.           title bar at the top of the session's window.
  68.  
  69.           Three parameters are passed to the child - the name of
  70.           the queue where the lines were QUEUED, the number of
  71.           lines in the queue, and the value of the TRACE=
  72.           environment variable from the parent. Commas are not used
  73.           to separate these three parameters as all of the data
  74.           following the program name (TEST80B.CMD) is passed as a
  75.           single string.
  76.  
  77. 20 - 23   The parent then "sleeps" for 2 seconds followed by
  78.           checking to see how many lines still exist in the queue.
  79.           If the queue has been drained (i.e. the number of lines
  80.           = 0) then the DO loop is exited; otherwise, the parent
  81.           iterates through this "wait and check" sequence. The
  82.           value of 2 seconds is arbitrary and any convenient value
  83.           could be used.
  84.  
  85.           07 - 08   The parameters passed to the child are parsed
  86.                     into the variables named in the template. I.e.
  87.                     queue name, number of lines queued and the
  88.                     value of the TRACE environment variable from
  89.                     the parent. All three parameters are received
  90.                     as a single string exactly as they were built
  91.                     by the parent.
  92.  
  93.                     The presence of the period (.) as a fourth
  94.                     expression in the template is used to cause
  95.                     any trailing spaces to be assigned to a dummy
  96.                     or null variable.
  97.  
  98.                     A TRACE command is issued with the same value
  99.                     used by the parent. A file, containing the
  100.                     trace output like the TEST80.TRC file included
  101.                     in this package, can be created by starting
  102.                     the parent with:
  103.  
  104.                          SET TRACE=R
  105.                          TEST80A 2>SYSTRACE
  106.  
  107.                     This would cause the trace output from both
  108.                     the parent and the child to be written to a
  109.                     file named SYSTRACE in the current directory.
  110.                     (Note: - This file will be locked by the child
  111.                     process until the child's session is ended
  112.                     with an EXIT command.)
  113.  
  114.           10 - 11   The line counter variable is initialized and
  115.                     the current REXX queue for the session is set
  116.                     to the same private queue that was used by the
  117.                     parent.
  118.  
  119.           13 - 17   Each line is retrieved from the queue and
  120.                     echoed on the display.
  121.  
  122.  
  123.           19 - 24   The two line counts are compared and the
  124.                     result is written to the display. The child
  125.                     task is then exited to the command line
  126.                     session. This incomplete ending (i.e. the
  127.                     session was still active) was left this way as
  128.                     specifically for the example.
  129.  
  130.                     The session could be terminated by passing an
  131.                     EXIT command to the command processor
  132.                     (CMD.EXE) from the REXX program by including
  133.                     'EXIT' (with the quotes) in place of the REXX
  134.                     EXIt command on line 24.
  135.  
  136. 26 - 32   When the queue has been depleted, the private queue
  137.           designation for the session is replaced with the original
  138.           queue, the result of the private queue being deleted is
  139.           checked and the program exits.
  140.