!
! Server part of test for sending and receiving to and from an RMIF remote with
! the remote ID (RID) set on a client's OPEN message.
!
! @author  Neon Ngo
!
! <cntrl> - The parent macro object
! <port>  - The KNOWN port of the server.  Client uses any available port.
!
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

  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 "SET" then
    message FUNC=send ID=^msg.fid NAME="ACK" INFO=0 DATA="SERVER got message=^msg.data"
    message FUNC=send ID=^msg.fid NAME="SET" INFO=0 DATA="{TEXT=SERVER SET test message}"

  elseif msg.name eqs "ACK" then
      message FUNC=send ID=cntrl NAME=SERVER_DONE INFO=0 DATA={TEST=TRUE}

  elseif msg.name eqs "OPEN" then
    ! do nothing
  elseif msg.name eqss "CLOSE" then
    ! ignore CLOSE and CLOSED messages
  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 "NULL" then
    ! ignore
  else
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
            DATA={TEXT="got unhandled message name=^msg.name",TEST=FALSE}
  endif
return
