;       SCCSID = @(#)smrbound.asm	6.2 92/03/18
;       SCCSID @(#)smrbound.asm	6.2 92/03/18
PAGE 60,132    ;
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;************************************************************************
;
; Source File Name:     SMRBOUND.ASM
;
; Subroutine Name:      GETBOUNDSESSION
;
; Descriptive Name:     Get parent's bound child session ID
;
; Function:     Determines if the specified session ID is a parent
;               session and returns the child session ID bound to
;               the parent.
;
; Notes:
;       Dependencies:   None
;
;       Restrictions:   None
;
; Change History:
;  CJ59  03/18/92  PTR B734620 Trap when checking for parent session.
;
; Entry Point:
;       Linkage:  EXTRN GETBOUNDSESSION:NEAR
;                       CALL    GETBOUNDSESSION
; Inputs:
;       BX      ParentID      Potential parent session ID
;
; Exit Normal:
;       AX      Returncode    Value=0,Bound child session returned
;       BX      BoundChildID  Session ID bound to the parent
;       FS:SI   BoundChildID's (or parent, if no bond) SGCB
;
; Exit Errors:
;       AX      Returncode error_smg_session_not_parent
;                          error_smg_session_not_bound
;
; Effects:       All other registers preserved.
;
; Internal References:
;          Data:        SESDATA - Commom segment with active session data
;                                 returned from DOSSMGETSTATUS (SMRSTAT.INC)
;                                 sessionbound - session id bound to parent
;                                 sessiontype  - independent/parent/child
;                                                session
;                       RDATA   - Common segment with router data
;                                 statusindex table (See SMRQSTAT.ASM)
;          Routines:
;
; External References:
;          Routines:
;
;************************************************************************
ifdef I1
;
;  DOSSMGETSGCB (Get potential parent's sgcb)
;  IF (No error)
;    Check if this is a parent
;  ENDIF
;  IF (This is a parent)
;    IF (It is bound to a child)
;      Get bound session ID
;      Set RC = No error
;    ELSE
;      Set RC = Error_SMG_Not_Bound
;    ENDIF
;  ELSE
;    RC = Error_SMG_Session_Not_Parent
;  ENDIF
;
;************************************************************************
else

.386C
    EXTRN   DOSSMGETSGCB : FAR
.xlist
.xcref
    INCLUDE ERROR2.INC                  ; Error equates
    INCLUDE SMRRDATA.INC                ; Router shared segment definition
    INCLUDE SMRSGCB.INC                 ; SGCB Definitions
    INCLUDE STRUC.INC
.cref
.list

CODE SEGMENT WORD PUBLIC 'CODE' USE16
    ASSUME CS:CODE,DS:NOTHING,SS:NOTHING,ES:NOTHING

    PUBLIC GETBOUNDSESSION
GETBOUNDSESSION PROC NEAR

    Local_Bytes EQU 4
    Local_Var1 EQU SS:[BP][-2]          ; Local variable on stack
    Local_Var2 EQU SS:[BP][-4]          ; Local variable on stack

    ENTER Local_Bytes,0

;   *******************************************************
;   *  Get potential parent sessions active session data  *
;   *******************************************************
    LEA  SI, Local_Var2                 ; @ return @ of SGCB
    PUSH SS
    PUSH SI
    PUSH BX                             ; Parent's SGID
    PUSH SGID_Lookup + 8000H            ; Look up SGID not PID and      ;CJ10
    CALL DOSSMGETSGCB                   ;   don't serialize QueueRamSem

    .IF  < zero AX >                    ; No error                      ;CJ59

      LFS  SI, Local_Var2                  ; FS:[SI] --> Parent's SGCB
;     ***************************************************************
;     *  Is parentid a parent session and bound to a child session  *
;     ***************************************************************
      TEST FS:[SI].SGCB_FamilyType, Parent ; Parent session?
      .IF  < nz >                          ; Yes,
        .IF  < FS:[SI].SGCB_Bound ne 0 >
          MOV  BX, FS:[SI].SGCB_Bound      ; Get bound session ID
          SUB  AX, AX                                                   ;CJ10
        .ELSE
          MOV  AX, Error_SMG_Not_Bound     ; Parent not bound
        .ENDIF
      .ELSE
        MOV  AX, Error_SMG_Session_Not_Parent ; Assume error condition
      .ENDIF

    .ENDIF                                                              ;CJ59

    LEAVE
    RET

GETBOUNDSESSION ENDP

CODE ENDS
endif
    END
