! Server part of "closed" Remote should NOT send messages over network
!
! <cntrl> - The parent macro object
! <port>  - The KNOWN port of the server. Client can use any available port.
!
! @bug     1633 RMIF: Closed remotes still send messages
! @author  Neon Ngo
! @since   NeXtMidas 2.7.3
!
startmacro O:cntrl L:port
  switch DEBUG   debug        GET DEF=false SDEF=true
  switch VERBOSE verbose      GET DEF=false SDEF=true
  switch STATEM  statemachine GET DEF=false SDEF=true

  set reg.cntrl cntrl
  set wait      1.0   ! Number of seconds to wait for extra messages at end

  pipe on
    rmif/id=RMIF/msgid=main/STATEM=^statemachine/VERBOSE=^verbose ^port
    message FUNC=send ID=cntrl NAME=SERVER_STARTED INFO=0 DATA={TEST=PASS}
  pipe off

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if debug then
    say "^reg.main.name: Got message name=^msg.name fid=^msg.fid info=^msg.info data=^msg.data"
  endif

  if msg.name eqs "STOP_TEST" then
    rem reg.cntrl ! we put this in manually, now remove it
    pipe stop     ! sent by ctrl

  elseif msg.name eqs "START_TEST" then
    ! do nothing
  elseif msg.name eqs "OPEN" then
    ! do nothing
  elseif msg.name eqs "NULL" then
    ! ignore

  elseif msg.name eqs "CLOSE" then
    ! wait a few seconds to see if extra messages are sent.
    set this.timer(0) wait

  elseif msg.name eqs "TIMER" then
    ! done waiting for any extra messages
    ! let control macro know that we are done
    message FUNC=send ID=cntrl NAME=SERVER_DONE DATA={TEST=TRUE}

  elseif msg.name eqs "LINKERR" then
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 DATA={TEXT="got unexpected error",TEST=FALSE}

  elseif msg.name eqs "SET" then
    ! RMIF should NOT receive any SET messages from RMIF remote client
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
            DATA={TEXT="should not receive any SET message, data=^msg.data",TEST=FALSE}
  else
    ! RMIF should NOT receive any other unknown messages from RMIF remote client
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
            DATA={TEXT="got unhandled message name=^msg.name",TEST=FALSE}
  endif
return
