(FILECREATED " 8-Mar-85 15:12:08" {ERIS}<SPEECH>MAILREADER>PROSE-PHONE.;22 6583   

      changes to:  (FNS PROSE.OPERATOR)

      previous date: " 1-Mar-85 19:09:04" {ERIS}<SPEECH>MAILREADER>PROSE-PHONE.;21)


(* 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 " 8-Mar-85 15:11")
                                                             (* 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)
	  (DISMISS 2000)                                     (* Holding for the phone company to set up the billing)
	  (P.CHUNK 
" This is the Interlisp-D mail reader.  Please enter your user name or push zero 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 6496 (PHONEINPUT.MONITOR 484 . 2074) (PROSE.OPERATOR 2076 . 3440) (
START.OPERATOR.PROCESS 3442 . 4121) (START.TONE.MONITOR.PROCESS 4123 . 5130) (TONE.MONITOR.PROCESS 
5132 . 6494)))))
STOP