(FILECREATED "27-Feb-85 21:56:24" {ERIS}<SPEECH>MAILREADER>PROSE-PHONE.;18 6546   

      changes to:  (FNS PROSE.OPERATOR)

      previous date: "25-Feb-85 18:47:39" {ERIS}<SPEECH>MAILREADER>PROSE-PHONE.;15)


(* Copyright (c) 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT PROSE-PHONECOMS)

(RPAQQ PROSE-PHONECOMS ((FNS PHONEINPUT.MONITOR PROSE.OPERATOR START.OPERATOR.PROCESS 
			     START.TONE.MONITOR.PROCESS TONE.MONITOR.PROCESS)))
(DEFINEQ

(PHONEINPUT.MONITOR
  [LAMBDA NIL                                                (* edited: "17-Jan-85 12:17")
                                                             (* Wakes up the P.PROCESS whenever a command has been 
							     completed as determined by the contents of PHONEINPUT 
							     and the state of the mailreader)
    (PROG (DUMMY)                                            (* Interrupt)
          [COND
	    ((AND (EQ (fetch (STATE STATEINFO TALKING) of STATE)
		      (QUOTE TALKING))
		  (EQ (CAR (fetch PHONEINPUT of STATE))
		      11))
	      (RETURN (replace (STATE STATEINFO HALTSPEECH) of STATE with T]
          (COND
	    ([OR (EQ (QUOTE 11)
		     (CAR (fetch PHONEINPUT of STATE)))
		 (EQ (QUOTE 12)
		     (CAR (fetch PHONEINPUT of STATE]
	      (COND
		((PROCESSP (fetch PROCESS of STATE)))
		(T                                           (* There was no live process so we have to start one)
		   (START.PROSE.PROCESS)                     (* Has to block to make sure the process gets started 
							     before we try to wake it in the next statement)
		   (BLOCK 1000)))
	      (DSUBST (QUOTE *)
		      11
		      (fetch PHONEINPUT of STATE))
	      (DSUBST (QUOTE #)
		      12
		      (fetch PHONEINPUT of STATE))
	      (DSUBST 0 10 (fetch PHONEINPUT of STATE))
	      (WAKE.PROCESS (fetch PROCESS of STATE)
			    T])

(PROSE.OPERATOR
  [LAMBDA NIL                                                (* bbb: "27-Feb-85 21:56")
                                                             (* Waits for an incoming call;
							     answers, wakes up the touch tone monitoring process;
							     and loops back to the call waiting state)
    (while T
       do (WAIT.FOR.CALL)
	  (BLOCK 3000)
	  (OFF.HOOK)                                         (* Holding for the phone company to set up the billing)
	  (P.CHUNK 
	      " Interlisp-D mail reader.  Please enter you user name or 0 sharp sign for help.  ")
	  [if (AND (BOUNDP (QUOTE MAILREADERLOGFILE))
		   (OPENP MAILREADERLOGFILE))
	      then (printout MAILREADERLOGFILE (DATE)
			     ": Call received." T)
	    else (SETQ MAILREADERLOGFILE (OPENFILE (QUOTE {DSK}MAILREADERLOG)
						   (QUOTE APPEND]
	  [if (NOT (OPENP (QUOTE {DSK}NAME.HASH)))
	      then (SETQ MAILREADERUSERSFILE (OPENHASHFILE (QUOTE {DSK}NAME.HASH)
							   (QUOTE BOTH]
	  (P.RESET.TIMER)
	  (BLOCK 1000)
	  (WAKE.PROCESS \TONE.MONITOR.PROCESS T)
	  (SUSPEND.PROCESS \PROSE.OPERATOR.PROCESS)
	  (printout MAILREADERLOGFILE (DATE)
		    ": Call completed." T])

(START.OPERATOR.PROCESS
  [LAMBDA NIL                                                (* pkh: "19-Dec-84 18:36")

          (* * comment)


    (USEDFREE \PROSE.OPERATOR.PROCESS)
    (COND
      ((AND (BOUNDP (QUOTE \PROSE.OPERATOR.PROCESS))
	    (PROCESSP \PROSE.OPERATOR.PROCESS))              (* Checking to see whether there is a running process 
							     already)
	(replace (STATE OPERATORPROCESS) of STATE with \PROSE.OPERATOR.PROCESS))
      (T [SETQ \PROSE.OPERATOR.PROCESS (ADD.PROCESS (QUOTE (PROSE.OPERATOR]
	 (replace (STATE OPERATORPROCESS) of STATE with \PROSE.OPERATOR.PROCESS])

(START.TONE.MONITOR.PROCESS
  [LAMBDA NIL                                                (* pkh: " 8-Jan-85 23:47")
                                                             (* Starts the process which 
							     (a) monitors the phone for ringing, and 
							     (b) monitors for incoming touch tones)
                                                             (* The handle on this porcess may not need to be kept)
    (USEDFREE \TONE.MONITOR.PROCESS)
    (COND
      ((AND (BOUNDP (QUOTE \TONE.MONITOR.PROCESS))
	    (PROCESSP \TONE.MONITOR.PROCESS))                (* Checking to see whether there is a running process 
							     already)
	(replace (STATE TONEPROCESS) of STATE with \TONE.MONITOR.PROCESS))
      (T (SETQ \TONE.MONITOR.PROCESS (ADD.PROCESS (QUOTE (TONE.MONITOR.PROCESS))
						  (QUOTE SUSPEND)
						  T))
	 (replace (STATE TONEPROCESS) of STATE with \TONE.MONITOR.PROCESS])

(TONE.MONITOR.PROCESS
  [LAMBDA NIL                                                (* edited: "17-Jan-85 12:25")

          (* Watches for touch tones and pushes them on the list which is in the PHONEINPUT field of (STATE; Calls 
	  PHONEINPUT.MONITOR whenever a touch tone has been received to see whether a command has been completed))


    (while T
       do [for THE.TONE as I from 0 to 2000
	     do (BLOCK)
		(COND
		  ((NEQ (LOGAND (BUS.INPUT CTRL)
				TONE)
			0)                                   (* There is a touch tone)
		    (SETQ THE.TONE (LOGAND 15 (BUS.INPUT DTMF)))
		    (BUS.OUTPUT DTMF 0)
		    (replace (STATE PHONEINPUT) of STATE with (push (fetch (STATE PHONEINPUT)
								       of STATE)
								    THE.TONE))
		    (P.RESET.TIMER)
		    (SETQ \TIMEOUTFLG NIL)
		    (PHONEINPUT.MONITOR]
	  (COND
	    (\IGNORETIMER T)
	    ((AND (NOT \IGNORETIMER)
		  (TIMEREXPIRED? P.TIMEOUTTIMER (QUOTE TICKS))
		  (NOT \TIMEOUTFLG))
	      (SETQ \TIMEOUTFLG T)
	      (P.CHUNK " Please type a key to maintain the connection. ")
	      (P.RESET.TIMER))
	    ((AND (TIMEREXPIRED? P.TIMEOUTTIMER (QUOTE TICKS))
		  \TIMEOUTFLG)
	      (SETQ \TIMEOUTFLG NIL)
	      (P.BYE])
)
(PUTPROPS PROSE-PHONE COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (474 6459 (PHONEINPUT.MONITOR 484 . 2074) (PROSE.OPERATOR 2076 . 3403) (
START.OPERATOR.PROCESS 3405 . 4084) (START.TONE.MONITOR.PROCESS 4086 . 5093) (TONE.MONITOR.PROCESS 
5095 . 6457)))))
STOP