Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: INHVTAPR

INHVTAPR.m

Go to the documentation of this file.
  1. INHVTAPR ; DGH, CHEM ; 07 Oct 1999 18:23 ; Generic receiver, enhanced functions
  1. ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
  1. ;COPYRIGHT 1991-2000 SAIC
  1. ;CHCS TOOLS_460; GEN 3; 17-JUL-1997
  1. ;COPYRIGHT 1994 SAIC
  1. ;
  1. ;This is an interactive transmitter/receiver routine supporting
  1. ;enhanced functionality. It is the mirror of INHVTAPT.
  1. ;It receives a message, sends an ack, receives a message, etc.
  1. ;The process can function as either a server or a client, depending
  1. ;on the parameters. See notes below.
  1. ;INPUT:
  1. ; INBPN = Background processor
  1. ;
  1. EN ;Main starting point
  1. N RC,INDEST,ING,INDSTR,INUSEQ,INSEND,INERR,INUIF,INLOOP,OUT,RCVE,OK,UIF,X,ER,INCHNL,INIP,INMEM,INQP,INQT,INNORSP,SYSTEM,RUN,I,Y,INXDST,CLISRV,INBPNM,INTRNSNT,INSTOP,INDISCNT ;CM
  1. S X="ERR^INHVTAPR",@^%ZOSF("TRAP"),(INSTOP,INDISCNT)=0
  1. D PARM^INHVTAPU
  1. G:INSTOP EXIT
  1. ;Set array of valid destinations
  1. D:$G(INDEBUG) LOG^INHVCRA1("Setting valid destination(s)",8) ;CM
  1. F I=1:1 S X=$T(DEST+I) Q:X'[";;" S Y=$TR($P(X,";;")," ",""),INDEST(Y)=$P(X,";;",2) ;CM
  1. ;Set values for the destination of the receiver and whether this
  1. ;receiver should use sequence number protocol.
  1. S INDSTR=+$P(^INTHPC(INBPN,0),U,7),INUSEQ=$P(^INRHD(INDSTR,0),U,9)
  1. OPEN ;Open the TCP/IP connection
  1. S OK=$$OPEN^INHVTAPU(INBPN,CLISRV,.INIP,INDEBUG,.INCHNL,.INMEM) G:'OK EXIT
  1. ;If initialization parameters are specified, run handshaking log
  1. I $L(INIP("INIT"))+$L(INIP("ACK")) S OK=$$INIT^INHVTAPU I 'OK D:CLISRV CLOSE^INHVTAPU G:CLISRV OPEN G EXIT
  1. ;
  1. RUN ;With port open, start receive/send. This is main loop of routine.
  1. S RUN=$$INRHB^INHUVUT1(INBPN,"Idle") G:'RUN EXIT
  1. ;Update background process audit
  1. D:$D(XUAUDIT) ITIME^XUSAUD(INBPNM)
  1. ;Loop until a transaction is received
  1. S (INNORSP,INSEND)=0
  1. RECEIVE ;Receive incoming message. If none, hang and go back to run
  1. S (RCVE,OUT)=0 F D Q:'$D(^INRHB("RUN",INBPN))!OUT
  1. .S ING="INDATA" K @ING
  1. .S RUN=$$INRHB^INHUVUT1(INBPN,"Waiting")
  1. .S ER=$$RECEIVE^INHUVUT(.ING,.INCHNL,.INIP,.INERR,.INMEM)
  1. .I 'ER S OUT=1 Q
  1. .;If ER, some error or timeout has occurred
  1. .;Log transceiver error if fatal, don't update message status
  1. .I ER>1 D ENR^INHE(INBPN,INERR) D:$G(INDEBUG) LOG^INHVCRA1(INERR_" "_INBPNM,7)
  1. .;if other system dropped connection, quit the receive loop
  1. .I ER=3 S OUT=1 Q
  1. .S RCVE=RCVE+1 I RCVE>INIP("RTRY") S OUT=1 H INIP("RHNG")
  1. ;--Blank and/or error conditions from receive
  1. ;If ER=3, the other side has dropped the connection. Close and reopen
  1. I ER=3 D G:INSTOP EXIT G OPEN
  1. .S RUN=$$INRHB^INHUVUT1(INBPN,"Remote end disconnect")
  1. .D:$G(INDEBUG) LOG^INHVCRA1("Remote end disconnect on "_INBPNM,5)
  1. .Q:CLISRV
  1. .;if this is a client, must close socket then open
  1. .D CKDISCNT^INHVTAPU Q:INSTOP D CLOSE^INHVTAPU K INCHNL,INMEM,INERR D:$G(INDEBUG) LOG^INHVCRA1("Waiting "_INIP("DHNG")_" seconds for open retry following disconnect on "_INBPNM_". Attempt "_INDISCNT,7) H INIP("DHNG")
  1. ;If nothing was received, loop back (this isn't an error)
  1. I '$D(@ING) H INIP("RHNG") G RUN
  1. G:ER=1 RUN
  1. ;Error condition 2 is unlikely unless INIP("RTRY") is set to 0
  1. ;If it occurs, go back to run.
  1. G:ER=2 RUN
  1. ;
  1. ;
  1. EVAL ;Evaluate incoming message
  1. K INACKID,INERR,INSEND
  1. ;Start transaction audit, transaction type not known.
  1. ;Stop of audit is in INHUSEN
  1. D:$D(XUAUDIT) TTSTRT^XUSAUD("","",INBPNM,"","RECEIVE")
  1. S RUN=$$INRHB^INHUVUT1(INBPN,"Evaluating message")
  1. S ER=$$IN^INHUSEN(ING,.INDEST,INDSTR,0,.ACKUIF,.INERR,.INXDST)
  1. ;ER=3 means out of synch, stop tranceiver (NOT checking for this tcvr)
  1. ;ER=2 is fatal error
  1. ;ER=1 is non-fatal error. Log it, but move on to next transmission
  1. ;ER=0 is no error
  1. ;Log error message
  1. I $D(INERR) D ENR^INHE(INBPN,.INERR) D:$G(INDEBUG) LOG^INHVCRA1(.INERR,5)
  1. K @ING
  1. S:ER<2 INDISCNT=0
  1. ;
  1. SEND ;Send outgoing ack. Try only once, then listen for next message
  1. I ACKUIF D
  1. .;Start transaction audit for transmission of ack.
  1. .D:$D(XUAUDIT) TTSTRT^XUSAUD(ACKUIF,"",INBPNM,"","TRANSMIT")
  1. .S RUN=$$INRHB^INHUVUT1(INBPN,"Transmitting commit acknowledgement")
  1. .D:$G(INDEBUG) LOG^INHVCRA1("Transmitting commit acknowledgement",7)
  1. .S ER=$$SEND^INHUVUT(ACKUIF,INCHNL,.INIP)
  1. ;Stop transaction audit
  1. D:$D(XUAUDIT) TTSTP^XUSAUD(ER)
  1. ;Currently ER will always be returned as 0, but INHUVUT may get smarter
  1. ;Loop back to run
  1. S RUN=$$INRHB^INHUVUT1(INBPN,"Successful transmission",2)
  1. D:$G(INDEBUG) LOG^INHVCRA1("Successful transmission on "_INBPNM,8)
  1. G:'RUN EXIT
  1. G RUN
  1. ;
  1. ERR ;Error module
  1. ;Handle known non-fatal error conditions
  1. I $$ETYPE^%ZTFE("O") D G EN
  1. .S X="ERR^INHVTAPR",@^%ZOSF("TRAP") D:$D(INCHNL) CLOSE^%INET(INCHNL)
  1. .D:$G(INDEBUG) LOG^INHVCRA1("Non-fatal error encountered in "_INBPNM,6)
  1. ;If unanticipated error is encounterd close port and quit receiver
  1. D ERR^INHVTAPU
  1. Q
  1. ;
  1. EXIT ;Main exit module
  1. D:$G(INDEBUG) LOG^INHVCRA1("Receiver Exiting.",5)
  1. D EXIT1^INHVTAPU
  1. Q
  1. ;
  1. DEST ;The following tags identify message destination.
  1. TST ;;TEST CONTROL - VMS IN
  1. ORUR01 ;;HL AP LOGIN/RESULT - IN
  1. ;
  1. ;Allowable formats for message destinations are as follows.
  1. XXX ;;Name field in transaction type file
  1. XXXYYY ;;Name field in transaction type file
  1. ;where XXX is the message type and YYY is the event type
  1. ;
  1. ;ORM;;HL CIW - IN