!
! Server (receiver) side of test case to verify status of RMIF link when the Server (Remote)
! side of the link is arbitrarily killed and brought back up on the same port.
! Test case does not fit into our RMIF test framework yet. The Server side has to
! be killed and restarted manually. Working on automating it.
! Discrepency noted by Jeremy N.
!
! Scenario we are trying to emulate
!     Start Server
!     Start Client
!     Kill Server
!     Start Server
!
! <cntrl>   - The parent control macro object
! <port>    - The KNOWN port of the server.  Client uses any available port.
!
! @bug     1541
! @author  Jim Roush
! @since   NeXtMidas 2.7.0
!
startmacro O:cntrl L:port[9013]
  switch TRACE   trace        GET DEF=false SDEF=true
  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   ! control macro
  set count 0
  set passFail "PASS"   ! Overall status

  pipe on
    ! startup RMIF server (to receive messages from client)
    rmif/id=RECEIVER/msgid=MAIN/STATEM=^statemachine/VERBOSE=^verbose ^port
    invoke ,, RECEIVER.rmif.setverbose(debug)    ! "invoke"s were provided by
    invoke ,, RECEIVER.rmif.setDebug(debug)      ! Jeremy to emulate his operating
!    invoke ,, RECEIVER.rmif.setMaxQueue(5120)   ! conditions. Most of them had no
!    invoke ,, RECEIVER.rmif.setWindow(1)        ! bearing on the issues that
!    invoke ,, RECEIVER.rmif.setRetry(10)        ! caused the problem. They are
!    invoke ,, RECEIVER.rmif.setTimeOut(120)     ! included here for completeness.
!    invoke ,, RECEIVER.rmif.setTimePing(15)
!    invoke ,, RECEIVER.rmif.setTimeDrop(130)
    set this.timer(0) 1

!    message FUNC=send ID=cntrl NAME=SERVER_STARTED INFO=0 DATA={TEST=PASS} ! for use with framework

  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 "OPEN" then
    ! ignore
  elseif msg.name eqss "CLOSE" then
    ! ignore CLOSE and CLOSED messages
  elseif msg.name eqs "NULL" then
    ! ignore
  elseif msg.name eqs "TIMER" then
    calc L:count count 1 +
    timex now x
    if debug isfalse then
      say "TIMER: processMessage() received ^msg.name message ^count at time=^x"
!      say "TIMER ^count: Got message name=^msg.name from=^msg.from info=^msg.info data=^msg.data time=^x"
    endif
    message send RECEIVER ,, "ACK",, "{UPDATE=s:^x, TIMER=s:^count}"
  else
    say "Got message name=^msg.name from=^msg.from info=^msg.info data=^msg.data"
  endif
return
