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

XOBVSKT.m

Go to the documentation of this file.
  1. XOBVSKT ;alb/mjk - VistaLink Socket Methods ;07/27/2002
  1. ;;1.6;VistALink;**3**;May 08, 2009;Build 17
  1. ;Per VHA Directive 6402, this routine should not be modified
  1. Q
  1. ;
  1. ; ------------------------------------------------------------------------------------
  1. ; Methods for Read from/to TCP/IP Socket
  1. ; ------------------------------------------------------------------------------------
  1. READ(XOBROOT,XOBREAD,XOBTO,XOBFIRST,XOBSTOP,XOBDATA,XOBHDLR) ;
  1. N X,EOT,OUT,STR,LINE,PIECES,DONE,TOFLAG,XOBCNT,XOBLEN,XOBBH,XOBEH,BS,ES,XOBOK,XOBX,SAML
  1. ;
  1. S STR="",EOT=$C(4),DONE=0,LINE=0,XOBOK=1,SAML=0
  1. ;
  1. ; -- READ tcp stream to global buffer | main calling tag NXTCALL^XOBVLL
  1. F R XOBX#XOBREAD:XOBTO S TOFLAG=$T D:XOBFIRST CHK D:'XOBSTOP!('DONE) Q:DONE
  1. . ;
  1. . ; -- if length of (new intake + current) is too large for buffer then store current
  1. . I $L(STR)+$L(XOBX)>400 D ADD(STR) S STR=""
  1. . S STR=STR_XOBX
  1. . ;
  1. . ; -- if end-of-text marker found then wrap up and quit
  1. . I STR[EOT S STR=$P(STR,EOT) D ADD(STR) S DONE=1 Q
  1. . ;
  1. . ; -- M XML parser cannot handle an element name split across nodes
  1. . S PIECES=$L(STR,">")
  1. . I PIECES>1 D ADD($P(STR,">",1,PIECES-1)_">") S STR=$P(STR,">",PIECES,999)
  1. .Q
  1. ;
  1. K ^TMP($J,"SAML")
  1. I $G(^XTMP($J,"SAML")) D
  1. . S NC=2,NC1=1 F S NC=$O(^XTMP($J,"SAML",NC)) Q:$G(NC)'>0 S ^TMP($J,"SAML",NC1)=$G(^XTMP($J,"SAML",NC)),NC1=NC1+1
  1. ;
  1. Q XOBOK
  1. ;
  1. ADD(TXT) ; -- add new intake line
  1. S LINE=LINE+1
  1. S @XOBROOT@(LINE)=TXT
  1. S:TXT["SAML"&($G(SAML)'=2) SAML=1 S:$G(SAML)=1&($G(TXT)["<soapenv:Envelope") SAML=2
  1. S:TXT["]]" SAML=3
  1. S:$G(SAML)=2 ^XTMP($J,"SAML",LINE)=$G(TXT)
  1. S:$G(SAML)=3 ^XTMP($J,"SAML",LINE)=$P(TXT,"]]",1)_"]]"
  1. Q
  1. ;
  1. CHK ; -- check if first read and change timeout and chars to read
  1. S XOBFIRST=0
  1. ;
  1. ; -- abort if time out occurred and nothing was read
  1. I 'TOFLAG,$G(XOBX)="" S XOBSTOP=1,DONE=1,XOBOK=0 Q
  1. ;
  1. ; -- intercept for transport sinks
  1. I $E(XOBX)'="<" D SINK
  1. ;
  1. ; -- set up for subsequent reads
  1. S XOBREAD=200,XOBTO=1
  1. Q
  1. ;
  1. ; ------------------------------------------------------------------------------------
  1. ; Execute Proprietary Format Reader
  1. ; ------------------------------------------------------------------------------------
  1. SINK ;
  1. ; -- get size of sink indicator >> then get sink indicator >> load req handler
  1. S XOBHDLR=$$MSGSINK^XOBVRH($$GETSTR(+$$GETSTR(2,.XOBX),.XOBX),.XOBHDLR)
  1. ;
  1. ; -- execute proprietary stream reader
  1. I $G(XOBHDLR(XOBHDLR)) X $G(XOBHDLR(XOBHDLR,"READER"))
  1. ;
  1. S DONE=1
  1. Q
  1. ;
  1. ; -- get string of length LEN from stream buffer
  1. GETSTR(LEN,XOBUF) ;
  1. N X
  1. F Q:($L(XOBUF)'<LEN) D RMORE(LEN-$L(XOBUF),.XOBUF)
  1. S X=$E(XOBUF,1,LEN)
  1. S XOBUF=$E(XOBUF,LEN+1,999)
  1. Q X
  1. ;
  1. ; -- read more from stream buffer but only needed amount
  1. RMORE(LEN,XOBUF) ;
  1. N X
  1. R X#LEN:1 S XOBUF=XOBUF_X
  1. Q
  1. ;
  1. ; ------------------------------------------------------------------------------------
  1. ; Methods for Opening and Closing Socket
  1. ; ------------------------------------------------------------------------------------
  1. OPEN(XOBPARMS) ; -- Open tcp/ip socket
  1. N I,POP
  1. S POP=1
  1. ;
  1. ; -- set up os var
  1. D OS
  1. ;
  1. ; -- preserve client io
  1. D SAVDEV^%ZISUTL("XOB CLIENT")
  1. ;
  1. F I=1:1:XOBPARMS("RETRIES") D CALL^%ZISTCP(XOBPARMS("ADDRESS"),XOBPARMS("PORT")) Q:'POP
  1. ; -- device open
  1. I 'POP U IO Q 1
  1. ; -- device not open
  1. Q 0
  1. ;
  1. CLOSE(XOBPARMS) ; -- close tcp/ip socket
  1. ; -- tell server to Stop() connection if close message is needed to close
  1. I $G(XOBPARMS("CLOSE MESSAGE"))]"" D
  1. . D PRE
  1. . D WRITE($$XMLHDR^XOBVLIB()_XOBPARMS("CLOSE MESSAGE"))
  1. . D POST
  1. ;
  1. D FINAL
  1. D CLOSE^%ZISTCP
  1. D USE^%ZISUTL("XOB CLIENT")
  1. D RMDEV^%ZISUTL("XOB CLIENT")
  1. Q
  1. ;
  1. INIT ; -- set up variables needed in tcp/ip processing
  1. K XOBNULL
  1. ;
  1. ; -- setup os var
  1. D OS
  1. ;
  1. ; -- set RPC Broker os variable (so $$BROKER^XWBLIB returns true)
  1. S XWBOS=XOBOS
  1. ;
  1. ; -- setup null device called "NULL"
  1. S %ZIS="0H",IOP="NULL" D ^%ZIS
  1. I 'POP D
  1. . S XOBNULL=IO
  1. . D SAVDEV^%ZISUTL("XOBNULL")
  1. Q
  1. ;
  1. OS ; -- os var
  1. S XOBOS=$S(^%ZOSF("OS")["OpenM":"OpenM",^("OS")["DSM":"DSM",^("OS")["UNIX":"UNIX",^("OS")["MSM":"MSM",1:"")
  1. Q
  1. ;
  1. FINAL ; -- kill variables used in tcp/ip processing
  1. ;
  1. ; -- close null device
  1. I $D(XOBNULL) D
  1. . D USE^%ZISUTL("XOBNULL")
  1. . D CLOSE^%ZISUTL("XOBNULL")
  1. . K XOBNULL
  1. ;
  1. K XOBOS,XWBOS
  1. ;
  1. Q
  1. ;
  1. ; ------------------------------------------------------------------------------------
  1. ; Methods for Writing to TCP/IP Socket
  1. ; ------------------------------------------------------------------------------------
  1. PRE ; -- prepare socket for writing
  1. S $X=0
  1. Q
  1. ;
  1. WRITE(STR) ; -- Write a data string to socket
  1. I XOBOS="MSM" W STR Q
  1. ;
  1. ; -- handle a short string
  1. I $L(STR)<511 D:($X+$L(STR))>511 FLUSH W STR Q
  1. ;
  1. ; -- handle a long string
  1. D FLUSH
  1. F Q:'$L(STR) W $E(STR,1,511) D FLUSH S STR=$E(STR,512,99999)
  1. ;
  1. Q
  1. ;
  1. POST ; -- send eot and flush socket buffer
  1. D WRITE($C(4))
  1. D FLUSH
  1. Q
  1. ;
  1. FLUSH ; flush buffer
  1. I XOBOS="OpenM" W ! Q
  1. I XOBOS="DSM" W:$X>0 ! Q
  1. ;IF XOBOS="GTM" WRITE # QUIT
  1. Q
  1. ;