!
! Client 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 S:host["LOCALHOST"]
  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 L:anyAvailablePort -1

  pipe on
    rmif/id=RMIFC/msgid=main/STATEM=^statemachine/VERBOSE=^verbose anyAvailablePort
    message FUNC=sendw ID=RMIFC NAME="OPEN" DATA={ID=CLIENT,HP="^host:^port"}
  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 ! message sent by control macro
    rem reg.cntrl ! we put this in manually, now remove it
    pipe stop

  elseif msg.name eqs "START_TEST" then
    sendto cntrl "CLIENT_DONE" {TEST=PASS}

  elseif msg.name eqs "OPENED" then
    sendto cntrl "CLIENT_STARTED" {TEST=PASS}

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

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

  elseif msg.name eqs "NULL" then
    ! ignore

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