next up previous contents
Next: EXAMPLE 3 - Up: EXAMPLES Previous: EXAMPLE 1 -

EXAMPLE 2 - ASYNCHRONOUS INPUT

This example contains several examples of Asynchronous Input. Two methods may be used to detect the presence of asynchronous input, polling repeatedly or establishing an AST Handler that wakes a hibernating program. Polling may be accomplished either by repeatedly calling the Input request subprogram, or by initiating the request and then repeatedly calling the test input subprogram, recalling the original input request subprogram once input has been detected. This example program illustrates all methods.

C------------------- EXAMPLE 2 CODE ------------------------


      PROGRAM EXAMPLE2
C
C       Description:-
C       =============
C       Example Program to exercise UIPACK Asynchronous Input
C       Subprograms.
C
C       Global Declarations:-
C       =====================
C
$$If VAX
      Implicit None
$$Endif
$$Include 'UIPack$Library:UINames.Inc'
$$Include 'UIPack$Library:UIParam.Inc'
$$Include 'UIPack$Library:UIError.Inc'
C
C       External Declarations:-
C       =======================
C
      EXTERNAL   MYAST
C
C       Local Declarations
C       ==================
C
      INTEGER     INTVAL,STATUS,COUNT
      CHARACTER*4 VERB
C
C       Executable Code:-
C       =================
C                                                               (1)
      STATUS = UIINIT()
C                                                               (2)
      STATUS = UIDFVB('GO')
      STATUS = UIDFVB('PAUSE')
C                                                               (3)
      STATUS = UIINMD(UIASYN)
      STATUS = UINOIN
100   CONTINUE
      IF (STATUS .EQ. UINOIN) THEN
         STATUS = UIGTVB('Prompt,VERB)
         IF (STATUS .EQ. UINOIN) THEN
            CALL LIB$WAIT(0.1)
C                                                               (4)
            GO TO 100
         ENDIF
      ENDIF
C                                                               (5)
      IF (STATUS .EQ. UISUCC) THEN
         IF     (VERB .EQ. 'GO  ') THEN
            TYPE *,'Verb was ',VERB
            GO TO 100
         ELSEIF (VERB .EQ. 'PAUS') THEN
            TYPE *,'Verb was ',VERB
         ENDIF
      ENDIF
C                                                               (6)
      STATUS = UINOIN
110   CONTINUE
      STATUS = UIGTVB('Prompt,VERB)
      IF (STATUS .EQ. UINOIN) THEN
120      CONTINUE
         CALL LIB$WAIT(0.1)
         IF (UITSIN() .EQ. UINOIN) GO TO 120
C                                                               (8)
         STATUS = UIGTVB('Prompt,VERB)
      ENDIF
      IF (STATUS .EQ. UISUCC) THEN
         IF     (VERB .EQ. 'GO  ') THEN
            TYPE *,'Verb was ',VERB
            GO TO 110
         ELSEIF (VERB .EQ. 'PAUS') THEN
            TYPE *,'Verb was ',VERB
         ENDIF
      ENDIF
C                                                               (9)
      COUNT = 0
      STATUS = UINOIN
130   CONTINUE
      IF (STATUS .EQ. UINOIN) THEN
         STATUS = UIGTVB('Prompt,VERB)
         IF (STATUS .EQ. UINOIN) THEN
            CALL LIB$WAIT(0.1)
            COUNT = COUNT + 1
            IF (COUNT .LE. 10) GO TO 130
         ENDIF
      ENDIF
      STATUS = UIGTMD(UISYNC)    
      STATUS = UIGTVB('Prompt,VERB)
C                                                               (10)
      STATUS = UIINMD(UIASYN)
      STATUS = UIGTMD(UIASYN)
      STATUS = UINOIN
140   CONTINUE
      IF (STATUS .EQ. UINOIN) THEN
         STATUS = UIGTIN('Prompt,INTVAL)
         IF (STATUS .EQ. UINOIN) THEN
            CALL LIB$WAIT(0.1)
            GO TO 140
         ELSEIF (STATUS .EQ. UISUCC) THEN
            TYPE *,INTVAL
            GO TO 140
         ENDIF
      ENDIF
C                                                               (11)
      STATUS = UIDFAS(MYAST)
      STATUS = UINOIN
140   CONTINUE
      IF (STATUS .EQ. UINOIN) THEN
         STATUS = UIGTIN('Prompt,INTVAL)
         IF (STATUS .EQ. UINOIN) THEN
            CALL SYS$HIBER
            GO TO 140
         ELSEIF (STATUS .EQ. UISUCC) THEN
            TYPE *,INTVAL
         ENDIF
      ENDIF
C                                                               (12)
      STATUS = UIFINI()
      STOP
      END
      SUBROUTINE MYAST
C                                                               (13)
      CALL SYS$WAKE(,)
      RETURN
      END
C
C
C ----------------- END OF EXAMPLE 2 -----------------------

Notes:

  1. This call initialises UIPACK with its default settings.
  2. This code defines two Verbs ``GO" and ``PAUSE" within the default Verb Group (zero).
  3. This code will loop until the Operator types a key on the keyboard. The call to UIINMD does not initiate the input request, but rather the repeated calls to UIGTVB do. If there is any text in the typeahead buffer this will cause a return from UIGTVB with a STATUS value other than UINOIN. If there is nothing already in the typeahead buffer then the first call to UIGTVB will initiate the input request and subsequent calls test whether any input has been received yet. Note that the Prompt will only be issued at the instant that the Operator touches a key on the keyboard rather than when the call to UIGTVB is made.
  4. Any Application Program Code should be inserted here.
  5. This section illustrates the alternative method of polling for the detection of input. The previous section is the preferred alternative however. As in the previous section, the call to UIGTVB will either receive any text already in the typeahead buffer, or initiate the input request. In the latter case, UITSIN is called repeatedly in order to detect input.
  6. This call to UIGTVB picks up the input that was detected by the calls to UITSIN.
  7. This section illustrates converting an unfulfilled asynchronous input request into a synchronous request. If there is no input detected within 10 tries, the program reverts to synchronous mode and forces the Operator to respond.
  8. This section illustrates the use of the Prompted Input Subprograms with asynchronous input. Both UIINMD and UIGTMD must have been called to enable asynchronous input with these subprograms, but otherwise this example is similar to the first one.
  9. This illustrates the use of an AST Handler (VAX/VMS only). The Subroutine MYAST contains a call to SYS$WAKE to awaken the program once input is detected. The program hibernates until this occurs.
  10. This code terminates the use of UIPACK.
  11. This is the AST Handler Subroutine that is called by UIPACK on the detection of asynchronous input. It should not call any UIPACK subprograms (or YBOS etc.) since these packages are not AST-reentrant.



next up previous contents
Next: EXAMPLE 3 - Up: EXAMPLES Previous: EXAMPLE 1 -



Liz Buckle
Fri Jan 13 17:20:31 CST 1995