!
! RMIF OPEN (REMOTE1) -> CLOSE (REMOTE1) -> OPEN (REMOTE2) to Remote on
! same the host:port test case for rouge CLOSED messages to Remote.
!
! In this scenario, the client side macro, should WAIT for a CLOSED message
! before proceeding with the OPEN, otherwise an in-transit CLOSED message
! from the server to RMIF on REMOTE1 will be sent to REMOTE2. The RMIF explain
! file has been updated to note this behavoir.
!
! <sPort>   - The KNOWN port of the server.  Client uses any available port.
! <timeout> - The timeout (max time) that this test should run before aborting
!
! @bug     1054
! @author  Neon Ngo
! @since   NeXtMidas 2.5.3
!
startmacro L:sPort[-1] D:timeout[15]
  switch DEBUG         debug        GET DEF=false    SDEF=true
  switch DEBUGSERVER   debugs       GET DEF=^debug   SDEF=true
  switch DEBUGCLIENT   debugc       GET DEF=^debug   SDEF=true
  switch VERBOSE       verbose      GET DEF=false    SDEF=true
  switch VERBOSESERVER verboses     GET DEF=^verbose SDEF=true
  switch VERBOSECLIENT verbosec     GET DEF=^verbose SDEF=true
  switch STATEM        statemachine GET DEF=false    SDEF=true

  res z:mytrue  true
  res z:myfalse false
  invoke classRmifSM nxm.sys.lib.ReflectUtil.getClassForName(nxm.sys.net.RmifSM)
  res z:no_statem_subclass TEST(classRmifSM EQS NULL)
  res z:statem_subclass    TEST(no_statem_subclass ISFALSE)

  if statemachine AND statem_subclass then ! Switch to legacy remote names, just for this test case
    info "^reg.main.name: Test being skipped in /STATEM as it requires reusing closed remote"
  else
    if statemachine then
      ! for some reason back to STATEM logic in Rmif (no RmifSM subclass)
      invoke previousLegacyRemote nxm.sys.net.Rmif.getStatemUsesLegacyRemoteNames()
      invoke ,, nxm.sys.net.Rmif.setStatemUsesLegacyRemoteNames(^mytrue)
      invoke ,, nxm.sys.net.Rmif.setStatemDoesFullCloseAndRemoteRemoval(^myfalse)
    endif

    timer set

    ! call RMIF test framewwork standard setup (see included standard_rmif_procs.mminc)
    call standardSetup timeout sPort
    pipe on
      %test_rmif_open_close_open_server/id=SERVER/STATEM=^statemachine/DEBUG=^debugs/VERBOSE=^verboses/BG this ^sPort
      %test_rmif_open_close_open_client/id=CLIENT/STATEM=^statemachine/DEBUG=^debugc/VERBOSE=^verbosec/BG this ^sPort
    pipe off

    timer elapse
  endif
  if statemachine AND no_statem_subclass then
    invoke ,, nxm.sys.net.Rmif.setStatemUsesLegacyRemoteNames(^previousLegacyRemote)
    invoke ,, nxm.sys.net.Rmif.setStatemDoesFullCloseAndRemoteRemoval(^mytrue)
  endif
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 false then ! Your message name goes here
    !
    ! Your message(s) processing goes here
    !
  else
    call processStandardMessages
  endif
return

! These are a set of standard procedures
include standard_rmif_procs.mminc
