!
! RMIF ADDC warning message test case
! SERVER
!
! See test_rmif_addc_client.mm for information regarding the different
! RMIF configuration scenarios used in the performance of this test.
!
! <cntrl>   - The parent control macro object
! <port>    - The KNOWN port of the server.  Client uses any available port.
!
! @bug     1057
! @author  Jim Roush
! @since   NeXtMidas 2.5.1
!
startmacro o:cntrl L:port
  switch DEBUG   debug        GET DEF=false SDEF=true
  switch VERBOSE verbose      GET DEF=false SDEF=true
  switch TRACE   trace        GET DEF=false SDEF=true
  switch STATEM  statemachine GET DEF=false SDEF=true

  set reg.cntrl cntrl  ! save reference to parent control macro
  set BAR 10

  pipe on
    ! Startup server (receiver) RMIF
    rmif/id=RECEIVER/msgid=main/PPT={VERBOSE=^trace}/STATEM=^statemachine/VERBOSE=^verbose ^port

    ! tell Controller that the RMIF thread has been started
    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 "START_TEST" then
    ! do nothing, waiting for client to send packets
  elseif msg.name eqs "OPEN" then
    message FUNC=send ID=cntrl NAME=SERVER_DONE INFO=0 DATA={TEST=TRUE}
  elseif msg.name eqs "OPENED" then
   ! do nothing
  elseif msg.name eqs "SET" then
    ! loop through the table values
    foreach key inTable msg.data
      res ^key msg.data.^key
    endfor

    ! send back the results, this USES broadcast
    message FUNC=send ID=RECEIVER NAME=ACK ,, DATA=^{msg.data}

  elseif msg.name eqs "CLOSE" then
    ! ignore
  elseif msg.name eqs "CLOSED" then
    ! ignore
  elseif msg.name eqs "NULL" then
    ! ignore
  elseif msg.name eqs "STOP_TEST" then
    rem reg.cntrl  ! we put this in manually, now remove it
    pipe stop      ! sent by cntrl
  elseif msg.name eqs "LINKERR" then
    ! notify control macro of link error as a failed test
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
            DATA={TEXT="got LINKERR data=^msg.data",TEST=FAIL}
  else
    ! notify control macro of unknown message as a failed test
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
            DATA={TEXT="got unhandled message name=^msg.name data=^msg.data",TEST=FAIL}
  endif
return
