- RALOCK01 ;HCIOFO/SG - INTERNAL LOCK UTILITIES ; 5/14/08 3:22pm
- ;;5.0;Radiology/Nuclear Medicine;**90**;Mar 16, 1998;Build 20
- ;
- ; Entry points of this routine use the ^XTMP("RALOCK",...) global
- ; nodes to store lock descriptors (see ^RALOCK routine for details).
- ;
- Q
- ;
- ;***** DELETES STRAY LOCK DESCRIPTORS
- ;
- ; NOTE: This is a service procedure. Do not call it from
- ; regular applications!
- ;
- PURGE() ;
- N NDX,NODE
- S NDX=0
- F S NDX=$O(^XTMP("RALOCK",NDX)) Q:$E(NDX,1)'="^" D
- . S NODE=$S(NDX["(":NDX_")",1:NDX)
- . D LOCK^DILF(NODE) E Q
- . K ^XTMP("RALOCK",NDX) L -@NODE
- Q
- ;
- ;+++++ FINDS THE LOCK DESCRIPTOR FOR THE GLOBAL NODE(S)
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- LDSC(NODELIST) ;
- N DESCR,IENS,L,NDX,NODE,RAMSG,SP,TMP
- S:$D(NODELIST)<10 NODELIST(NODELIST)=""
- S (DESCR,NODE)=""
- F S NODE=$O(NODELIST(NODE)) Q:NODE="" D
- . ;--- The Node itself
- . S SP=$$XLNDX(NODE),TMP=$G(^XTMP("RALOCK",SP))
- . S:TMP>DESCR DESCR=TMP
- . ;--- Left Siblings and Ancestors
- . S NDX=SP
- . F S NDX=$O(^XTMP("RALOCK",NDX),-1),L=$L(NDX) Q:(NDX="")!(NDX'=$E(SP,1,L)) D
- . . S TMP=$G(^XTMP("RALOCK",NDX)) S:TMP>DESCR DESCR=TMP
- . ;--- Right Siblings and Descendants
- . S NDX=SP,L=$L(SP)
- . F S NDX=$O(^XTMP("RALOCK",NDX)) Q:(NDX="")!($E(NDX,1,L)'=SP) D
- . . S TMP=$G(^XTMP("RALOCK",NDX)) S:TMP>DESCR DESCR=TMP
- ;--- Prepare the lock descriptor
- S:'DESCR $P(DESCR,U)=$$NOW^XLFDT
- D:$P(DESCR,U,3)>0
- . S IENS=+$P(DESCR,U,3)_","
- . S $P(DESCR,U,2)=$$GET1^DIQ(200,IENS,.01,,,"RAMSG") ; User Name
- S:$P(DESCR,U,2)="" $P(DESCR,U,2)="UNKNOWN"
- Q $P(DESCR,U,1,5)
- ;
- ;+++++ LOCKS THE SINGLE NODE
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- LOCK1(FILE,IENS,FIELD,TO,NAME,FLAGS) ;
- N DESCR,NDX,NODE,TMP
- S NODE=$$NODE(FILE,IENS,FIELD)
- Q:NODE<0 NODE
- ;--- Try to lock the object
- I FLAGS'["D" L +@NODE:TO E Q $$LDSC(NODE)
- ;--- Create the lock descriptor
- S DESCR=$$NOW^XLFDT_U_NAME_U_U_$JOB_U_$G(ZTSK)
- S:NAME="" $P(DESCR,U,3)=$G(DUZ)
- ;--- Calculate the lock counter
- S NDX=$$XLNDX(NODE),TMP=$G(^XTMP("RALOCK",NDX))
- S $P(DESCR,U,6)=$S($P(TMP,U,4)=$JOB:$P(TMP,U,6)+1,1:1)
- ;--- Store the descriptor
- S ^XTMP("RALOCK",NDX)=DESCR
- Q 0
- ;
- ;+++++ RETURNS THE GLOBAL NODE OF THE OBJECT
- ;
- ; FILE File/subfile number
- ; IENS IENS of the record or subfile
- ; FIELD Field number
- ;
- ; Return Values:
- ; <0 Error code
- ; Closed root
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- NODE(FILE,IENS,FIELD) ;
- N FGL,IEN,NODE,RAMSG,RC
- I IENS'="" Q:'$$VALIENS^RAUTL22(IENS,"S") $$IPVE^RAERR("IENS")
- S IEN=+IENS
- I IEN S $P(IENS,",")="" S:IENS="," IENS=""
- ;--- Closed root of the (sub)file
- S NODE=$$ROOT^DILFD(FILE,IENS,1)
- I NODE="" D Q RC
- . S RC=$$ERROR^RAERR(-50,,FILE,IENS)
- Q:'IEN NODE
- ;--- The record node
- S NODE=$NA(@NODE@(IEN))
- Q:'FIELD NODE
- ;--- Field node
- S FGL=$$GET1^DID(FILE,FIELD,,"GLOBAL SUBSCRIPT LOCATION",,"RAMSG")
- I $G(DIERR) D Q RC
- . S RC=$$DBS^RAERR("RAMSG",-9,FILE)
- S:$P(FGL,";")'="" NODE=$NA(@NODE@($P(FGL,";")))
- Q NODE
- ;
- ;+++++ COMPILES THE LIST OF GLOBAL NODES
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- NODELIST(NODELIST,FILE,IENS,FIELD) ;
- N NODE,PI,RC K NODELIST
- S NODELIST="",RC=0
- ;--- Main object
- I $G(FILE)>0 D Q:RC<0 RC
- . S NODE=$$NODE(FILE,IENS,FIELD)
- . I NODE<0 S RC=+NODE Q
- . S NODELIST=NODELIST_","_NODE
- . S NODELIST(NODE)=""
- ;--- Linked objects
- S PI="FILE"
- F S PI=$Q(@PI) Q:PI="" D Q:RC<0
- . S NODE=$$NODE($QS(PI,1),$QS(PI,2),$QS(PI,3))
- . I NODE<0 S RC=+NODE Q
- . S NODELIST=NODELIST_","_NODE
- . S NODELIST(NODE)=""
- Q:RC<0 RC
- ;---
- S NODELIST=$P(NODELIST,",",2,999)
- Q RC
- ;
- ;+++++ UNLOCKS THE SINGLE NODE
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- UNLOCK1(FILE,IENS,FIELD) ;
- N DESCR,NDX,NODE
- S NODE=$$NODE(FILE,IENS,FIELD)
- Q:NODE<0 NODE
- ;--- Remove the lock descriptor
- S NDX=$$XLNDX(NODE),DESCR=$G(^XTMP("RALOCK",NDX))
- D:$P(DESCR,U,4)=$JOB
- . I $P(DESCR,U,6)>1 D
- . . S $P(^XTMP("RALOCK",NDX),U,6)=$P(DESCR,U,6)-1
- . E K ^XTMP("RALOCK",NDX)
- ;--- Unlock the object
- L -@NODE
- Q 0
- ;
- ;+++++ RETURNS SUBSCRIPT OF THE NODE IN THE DESCRIPTOR TABLE
- ;
- ; NOTE: This is an internal entry point. Do not call it from
- ; any routines except RALOCK and RALOCK01
- ;
- XLNDX(NODE) ;
- N L S L=$L(NODE)
- Q $S($E(NODE,L)=")":$E(NODE,1,L-1),1:NODE)
- RALOCK01 ;HCIOFO/SG - INTERNAL LOCK UTILITIES ; 5/14/08 3:22pm
- +1 ;;5.0;Radiology/Nuclear Medicine;**90**;Mar 16, 1998;Build 20
- +2 ;
- +3 ; Entry points of this routine use the ^XTMP("RALOCK",...) global
- +4 ; nodes to store lock descriptors (see ^RALOCK routine for details).
- +5 ;
- +6 QUIT
- +7 ;
- +8 ;***** DELETES STRAY LOCK DESCRIPTORS
- +9 ;
- +10 ; NOTE: This is a service procedure. Do not call it from
- +11 ; regular applications!
- +12 ;
- PURGE() ;
- +1 NEW NDX,NODE
- +2 SET NDX=0
- +3 FOR
- SET NDX=$ORDER(^XTMP("RALOCK",NDX))
- IF $EXTRACT(NDX,1)'="^"
- QUIT
- Begin DoDot:1
- +4 SET NODE=$SELECT(NDX["(":NDX_")",1:NDX)
- +5 DO LOCK^DILF(NODE)
- IF '$TEST
- QUIT
- +6 KILL ^XTMP("RALOCK",NDX)
- LOCK -@NODE
- End DoDot:1
- +7 QUIT
- +8 ;
- +9 ;+++++ FINDS THE LOCK DESCRIPTOR FOR THE GLOBAL NODE(S)
- +10 ;
- +11 ; NOTE: This is an internal entry point. Do not call it from
- +12 ; any routines except RALOCK and RALOCK01
- +13 ;
- LDSC(NODELIST) ;
- +1 NEW DESCR,IENS,L,NDX,NODE,RAMSG,SP,TMP
- +2 IF $DATA(NODELIST)<10
- SET NODELIST(NODELIST)=""
- +3 SET (DESCR,NODE)=""
- +4 FOR
- SET NODE=$ORDER(NODELIST(NODE))
- IF NODE=""
- QUIT
- Begin DoDot:1
- +5 ;--- The Node itself
- +6 SET SP=$$XLNDX(NODE)
- SET TMP=$GET(^XTMP("RALOCK",SP))
- +7 IF TMP>DESCR
- SET DESCR=TMP
- +8 ;--- Left Siblings and Ancestors
- +9 SET NDX=SP
- +10 FOR
- SET NDX=$ORDER(^XTMP("RALOCK",NDX),-1)
- SET L=$LENGTH(NDX)
- IF (NDX="")!(NDX'=$EXTRACT(SP,1,L))
- QUIT
- Begin DoDot:2
- +11 SET TMP=$GET(^XTMP("RALOCK",NDX))
- IF TMP>DESCR
- SET DESCR=TMP
- End DoDot:2
- +12 ;--- Right Siblings and Descendants
- +13 SET NDX=SP
- SET L=$LENGTH(SP)
- +14 FOR
- SET NDX=$ORDER(^XTMP("RALOCK",NDX))
- IF (NDX="")!($EXTRACT(NDX,1,L)'=SP)
- QUIT
- Begin DoDot:2
- +15 SET TMP=$GET(^XTMP("RALOCK",NDX))
- IF TMP>DESCR
- SET DESCR=TMP
- End DoDot:2
- End DoDot:1
- +16 ;--- Prepare the lock descriptor
- +17 IF 'DESCR
- SET $PIECE(DESCR,U)=$$NOW^XLFDT
- +18 IF $PIECE(DESCR,U,3)>0
- Begin DoDot:1
- +19 SET IENS=+$PIECE(DESCR,U,3)_","
- +20 ; User Name
- SET $PIECE(DESCR,U,2)=$$GET1^DIQ(200,IENS,.01,,,"RAMSG")
- End DoDot:1
- +21 IF $PIECE(DESCR,U,2)=""
- SET $PIECE(DESCR,U,2)="UNKNOWN"
- +22 QUIT $PIECE(DESCR,U,1,5)
- +23 ;
- +24 ;+++++ LOCKS THE SINGLE NODE
- +25 ;
- +26 ; NOTE: This is an internal entry point. Do not call it from
- +27 ; any routines except RALOCK and RALOCK01
- +28 ;
- LOCK1(FILE,IENS,FIELD,TO,NAME,FLAGS) ;
- +1 NEW DESCR,NDX,NODE,TMP
- +2 SET NODE=$$NODE(FILE,IENS,FIELD)
- +3 IF NODE<0
- QUIT NODE
- +4 ;--- Try to lock the object
- +5 IF FLAGS'["D"
- LOCK +@NODE:TO
- IF '$TEST
- QUIT $$LDSC(NODE)
- +6 ;--- Create the lock descriptor
- +7 SET DESCR=$$NOW^XLFDT_U_NAME_U_U_$JOB_U_$G(ZTSK)
- +8 IF NAME=""
- SET $PIECE(DESCR,U,3)=$GET(DUZ)
- +9 ;--- Calculate the lock counter
- +10 SET NDX=$$XLNDX(NODE)
- SET TMP=$GET(^XTMP("RALOCK",NDX))
- +11 SET $PIECE(DESCR,U,6)=$SELECT($PIECE(TMP,U,4)=$JOB:$PIECE(TMP,U,6)+1,1:1)
- +12 ;--- Store the descriptor
- +13 SET ^XTMP("RALOCK",NDX)=DESCR
- +14 QUIT 0
- +15 ;
- +16 ;+++++ RETURNS THE GLOBAL NODE OF THE OBJECT
- +17 ;
- +18 ; FILE File/subfile number
- +19 ; IENS IENS of the record or subfile
- +20 ; FIELD Field number
- +21 ;
- +22 ; Return Values:
- +23 ; <0 Error code
- +24 ; Closed root
- +25 ;
- +26 ; NOTE: This is an internal entry point. Do not call it from
- +27 ; any routines except RALOCK and RALOCK01
- +28 ;
- NODE(FILE,IENS,FIELD) ;
- +1 NEW FGL,IEN,NODE,RAMSG,RC
- +2 IF IENS'=""
- IF '$$VALIENS^RAUTL22(IENS,"S")
- QUIT $$IPVE^RAERR("IENS")
- +3 SET IEN=+IENS
- +4 IF IEN
- SET $PIECE(IENS,",")=""
- IF IENS=","
- SET IENS=""
- +5 ;--- Closed root of the (sub)file
- +6 SET NODE=$$ROOT^DILFD(FILE,IENS,1)
- +7 IF NODE=""
- Begin DoDot:1
- +8 SET RC=$$ERROR^RAERR(-50,,FILE,IENS)
- End DoDot:1
- QUIT RC
- +9 IF 'IEN
- QUIT NODE
- +10 ;--- The record node
- +11 SET NODE=$NAME(@NODE@(IEN))
- +12 IF 'FIELD
- QUIT NODE
- +13 ;--- Field node
- +14 SET FGL=$$GET1^DID(FILE,FIELD,,"GLOBAL SUBSCRIPT LOCATION",,"RAMSG")
- +15 IF $GET(DIERR)
- Begin DoDot:1
- +16 SET RC=$$DBS^RAERR("RAMSG",-9,FILE)
- End DoDot:1
- QUIT RC
- +17 IF $PIECE(FGL,";")'=""
- SET NODE=$NAME(@NODE@($PIECE(FGL,";")))
- +18 QUIT NODE
- +19 ;
- +20 ;+++++ COMPILES THE LIST OF GLOBAL NODES
- +21 ;
- +22 ; NOTE: This is an internal entry point. Do not call it from
- +23 ; any routines except RALOCK and RALOCK01
- +24 ;
- NODELIST(NODELIST,FILE,IENS,FIELD) ;
- +1 NEW NODE,PI,RC
- KILL NODELIST
- +2 SET NODELIST=""
- SET RC=0
- +3 ;--- Main object
- +4 IF $GET(FILE)>0
- Begin DoDot:1
- +5 SET NODE=$$NODE(FILE,IENS,FIELD)
- +6 IF NODE<0
- SET RC=+NODE
- QUIT
- +7 SET NODELIST=NODELIST_","_NODE
- +8 SET NODELIST(NODE)=""
- End DoDot:1
- IF RC<0
- QUIT RC
- +9 ;--- Linked objects
- +10 SET PI="FILE"
- +11 FOR
- SET PI=$QUERY(@PI)
- IF PI=""
- QUIT
- Begin DoDot:1
- +12 SET NODE=$$NODE($QSUBSCRIPT(PI,1),$QSUBSCRIPT(PI,2),$QSUBSCRIPT(PI,3))
- +13 IF NODE<0
- SET RC=+NODE
- QUIT
- +14 SET NODELIST=NODELIST_","_NODE
- +15 SET NODELIST(NODE)=""
- End DoDot:1
- IF RC<0
- QUIT
- +16 IF RC<0
- QUIT RC
- +17 ;---
- +18 SET NODELIST=$PIECE(NODELIST,",",2,999)
- +19 QUIT RC
- +20 ;
- +21 ;+++++ UNLOCKS THE SINGLE NODE
- +22 ;
- +23 ; NOTE: This is an internal entry point. Do not call it from
- +24 ; any routines except RALOCK and RALOCK01
- +25 ;
- UNLOCK1(FILE,IENS,FIELD) ;
- +1 NEW DESCR,NDX,NODE
- +2 SET NODE=$$NODE(FILE,IENS,FIELD)
- +3 IF NODE<0
- QUIT NODE
- +4 ;--- Remove the lock descriptor
- +5 SET NDX=$$XLNDX(NODE)
- SET DESCR=$GET(^XTMP("RALOCK",NDX))
- +6 IF $PIECE(DESCR,U,4)=$JOB
- Begin DoDot:1
- +7 IF $PIECE(DESCR,U,6)>1
- Begin DoDot:2
- +8 SET $PIECE(^XTMP("RALOCK",NDX),U,6)=$PIECE(DESCR,U,6)-1
- End DoDot:2
- +9 IF '$TEST
- KILL ^XTMP("RALOCK",NDX)
- End DoDot:1
- +10 ;--- Unlock the object
- +11 LOCK -@NODE
- +12 QUIT 0
- +13 ;
- +14 ;+++++ RETURNS SUBSCRIPT OF THE NODE IN THE DESCRIPTOR TABLE
- +15 ;
- +16 ; NOTE: This is an internal entry point. Do not call it from
- +17 ; any routines except RALOCK and RALOCK01
- +18 ;
- XLNDX(NODE) ;
- +1 NEW L
- SET L=$LENGTH(NODE)
- +2 QUIT $SELECT($EXTRACT(NODE,L)=")":$EXTRACT(NODE,1,L-1),1:NODE)