!
! Server part of RMIF basic sample test
!
! @author  Jay Hallam
!
! <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
    sendto cntrl "SERVER_STARTED" {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 ! sent by control macro
    rem reg.cntrl ! we put this in manually, now remove it
    pipe stop

  elseif msg.name eqs "OPEN" then
    sendto cntrl "SERVER_DONE" {TEST=TRUE}

  elseif msg.name eqs "START_TEST" then
    ! do nothing

  elseif msg.name eqss "CLOSE" then
    ! ignore CLOSE and CLOSED messages

  elseif msg.name eqs "NULL" then
    ! ignore

  elseif msg.name eqs "LINKERR" then
    sendto cntrl "SERVER_TEST" {TEXT="got unexpected error",TEST=FALSE}

  else
    sendto cntrl "SERVER_TEST" {TEXT="got unhandled message name=^msg.name",TEST=FALSE}
  endif
return
