VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtVreBackendConnector Class Reference

Detailed Description

DtVreBackendConnector manages the full lifecycle of the VR-Engage simulation backend: configuration of the backend's simulation address, building and launching the backend process, loading scenarios, stopping the backend, and monitoring backend status changes.

In addition, it bridges chat events between the VRF event manager and the VR-Engage message bus, and handles wind state queries via the VRF remote environment controller.

#include <vreBackendConnector.h>

Inheritance diagram for makVre::DtVreBackendConnector:
[legend]

Public Member Functions

 DtVreBackendConnector ()
 
virtual ~DtVreBackendConnector () override
 
virtual void install (makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection, makVrf::DtVrlinkVrfRemoteController *vrfRemoteController)
 
virtual void tick (double dt) override
 
virtual void shutdown () override
 
bool hasBackendAddress () const
 
DtSimulationAddress backendAddress () const
 
void setStartupTimeoutSeconds (int seconds)
 
virtual DtVreMessageResult handleSetBackendConfig (DtVreMessage *message)
 
virtual DtVreMessageResult handleStartBackend (DtVreMessage *message)
 
virtual DtVreMessageResult handleStopBackend (DtVreMessage *message)
 
virtual DtVreMessageResult handleRequestBackendStatus (DtVreMessage *message)
 
virtual DtVreMessageResult handleLoadBackend (DtVreMessage *message)
 
virtual DtVreMessageResult handleChatEvent (DtVreMessage *message)
 
virtual DtVreMessageResult handleWindRequest (DtVreMessage *message)
 
- Public Member Functions inherited from makVre::DT_PROTOCOL_NAMESPACE::DtSimEventConnector
 DtSimEventConnector ()
 
virtual ~DtSimEventConnector () override
 
virtual void install (makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection *connection)
 
- Public Member Functions inherited from makVre::DtConnector
 DtConnector ()
 
virtual ~DtConnector ()
 
virtual DtConnectorType type ()
 
virtual std::string name ()
 

Static Public Member Functions

static void BackendDiscovered (const DtSimulationAddress &addr, void *usr)
 
static void BackendRemoved (const DtSimulationAddress &addr, void *usr)
 
static void ifLoadCompleteMessageCallback (DtSimMessage *msg, void *usr)
 
static bool backendRemapper (DtBackendMap *map, const std::set< DtSimulationAddress > &expectedBackends, void *usr)
 
- Static Public Member Functions inherited from makVre::DtConnector
static std::string extension (DtConnectorType type)
 

Protected Member Functions

virtual void processBackendDiscovered (const DtSimulationAddress &addr)
 
virtual void processBackendRemoved (const DtSimulationAddress &addr)
 
virtual void processLoadCompleteMessage (DtSimMessage *msg)
 
virtual void processChatEvent (const makVrfEvents::DtEvent &evt)
 
virtual void updateBackendStatus ()
 
virtual void sendBackendStatusMessage ()
 
virtual bool remapBackends (DtBackendMap *map, const std::set< DtSimulationAddress > &expectedBackends)
 
virtual void sendTerrainScenario (DtScenario &scenario, const LoadBackendMessage *loadMsg, const std::set< std::string > &sessionSmsList, const DtFilename &terrain, const DtFilename &guiTerrain)
 
virtual void sendSessionSmsUpdate ()
 
virtual void * launchVrfBackend (const DtSimulationAddress &address, int sessionId, int simType, const std::vector< std::string > &pluginBaseNames, bool showConsole, std::string &additionalArguments)
 
std::string vrfSimEngineCommand (const DtSimulationAddress &address, int sessionId, int simType, const std::vector< std::string > &pluginBaseNames, std::string &additionalArguments)
 
virtual std::string application () const
 
virtual std::string connectionParameters (const DtSimulationAddress &address, std::string &additionalArguments) const
 
virtual std::string protocol () const
 
void clearBackendState ()
 

Protected Attributes

void * myBackendProcessHandle = nullptr
 
makVrf::DtVrlinkVrfRemoteController * myVrfRemoteController = nullptr
 
boost::signals2::scoped_connection myChatEventConnection
 
const DtExerciseConnInitializer * myExerciseConnInitializer = nullptr
 
int mySessionId = 1
 
std::vector< std::string > myPlugins
 
bool myShowConsole = false
 
std::string myArguments
 
DtSimulationAddress myBackendStartingAddress
 
bool myTookSnapshot = false
 
double mySnapshotSimTime = 0.0
 
std::chrono::steady_clock::time_point myBackendLaunchTime
 
int myStartupTimeoutSeconds = 30
 
std::set< DtSimulationAddress > mySimulationAddresses
 
DtAttributeHandleType< bool > mySessionPlayStateAttr
 
DtAttributeHandleType< std::set< std::string > > mySessionSmsListAttr
 
DtAttributeHandleType< bool > myBackendIsHostAttr
 
DtAttributeHandleType< BackendStatusMessage::BackendStatusData > myBackendStatusAttr
 
DtAttributeHandleType< VrfSessionStatusMessage::VrfSessionStatusData > mySessionStatusAttr
 
- Protected Attributes inherited from makVre::DT_PROTOCOL_NAMESPACE::DtSimEventConnector
makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection * myConnection
 
- Protected Attributes inherited from makVre::DtConnector
std::string myName
 
DtConnectorType myType
 
DtAttributeCallbackManager myAttributeCallbacks
 
DtVreMessageHandlerGroup myMessageHandlers
 

Additional Inherited Members

- Public Types inherited from makVre::DtConnector
enum  DtConnectorType {
  DIS , HLA13 , HLA1516 , HLA1516E ,
  HLA4
}
 

Constructor & Destructor Documentation

◆ DtVreBackendConnector()

makVre::DtVreBackendConnector::DtVreBackendConnector ( )

Default constructor. Initializes all state to default values.

◆ ~DtVreBackendConnector()

virtual makVre::DtVreBackendConnector::~DtVreBackendConnector ( )
overridevirtual

Virtual destructor.

Member Function Documentation

◆ install()

virtual void makVre::DtVreBackendConnector::install ( makVrv::DT_PROTOCOL_NAMESPACE::DtVrlinkConnection * connection,
makVrf::DtVrlinkVrfRemoteController * vrfRemoteController )
virtual

Installs the backend connector with shared infrastructure.

Parameters
connectionNon-owning pointer to the protocol-specific VR-Link connection.
vrfRemoteControllerNon-owning pointer to the shared VRF remote controller owned by DtConnectorAccessory.

Also binds handles from the global App attribute tree and locks write-protected handles (myBackendIsHostAttr, myBackendStatusAttr) to prevent unintended writes from other connectors. These handles are read-only for this connector.

◆ tick()

virtual void makVre::DtVreBackendConnector::tick ( double dt)
overridevirtual

Performs periodic backend status evaluation.

Calls updateBackendStatus() each tick to detect backend status changes and broadcast updates to the frontend.

Parameters
dtThe elapsed time in seconds since the last tick

Reimplemented from makVre::DT_PROTOCOL_NAMESPACE::DtSimEventConnector.

◆ shutdown()

virtual void makVre::DtVreBackendConnector::shutdown ( )
overridevirtual

Shuts down the connector.

Stops any running VRE backend process (sends DtIfExit), disconnects the chat boost signal, unregisters all VRE message handlers, and removes the DtLoadCompleteMessageType VRF callback.

Reimplemented from makVre::DT_PROTOCOL_NAMESPACE::DtSimEventConnector.

◆ handleSetBackendConfig()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleSetBackendConfig ( DtVreMessage * message)
virtual

Backend lifecycle message handlers.

Handles backend configuration (site ID and application ID for starting address)

Parameters
messagePointer to the SetBackendConfigMessage
Returns
HANDLED

◆ handleStartBackend()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleStartBackend ( DtVreMessage * message)
virtual

Handles a request to launch the VRE backend process.

Parameters
messagePointer to the StartBackendMessage
Returns
HANDLED

If a backend is already running, queues a StopBackend + restart sequence. Otherwise calls launchVrfBackend() to spawn the sim process and updates the backend address. Publishes myBackendIsHostAttr to the global App attribute tree.

◆ handleStopBackend()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleStopBackend ( DtVreMessage * message)
virtual

Handles a request to stop the VRE backend process.

Parameters
messagePointer to the StopBackendMessage (may be nullptr when called internally)
Returns
HANDLED

Sends DtIfExit to the backend, clears backend state via clearBackendState(), and resets snapshot state.

◆ handleRequestBackendStatus()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleRequestBackendStatus ( DtVreMessage * message)
virtual

Handles a request for the current backend status.

Parameters
messagePointer to the RequestBackendStatusMessage
Returns
HANDLED

◆ handleLoadBackend()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleLoadBackend ( DtVreMessage * message)
virtual

Handles a request to load a scenario on the VRE backend.

Parameters
messagePointer to the LoadBackendMessage
Returns
HANDLED

Validates backend readiness, then loads either a session terrain (if a session is running), a full scenario file (if this backend can host), or a terrain-only scenario. Reads session state from DtSessionStatusConnector.

◆ handleChatEvent()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleChatEvent ( DtVreMessage * message)
virtual

Chat and environmental message handlers.

Handles chat send messages from the frontend → VRF backend

Parameters
messagePointer to the ChatMessage
Returns
HANDLED if a send-type message, IGNORED for receive-type

◆ handleWindRequest()

virtual DtVreMessageResult makVre::DtVreBackendConnector::handleWindRequest ( DtVreMessage * message)
virtual

Handles wind state request messages.

Parameters
messagePointer to the WindStateRequestMessage
Returns
HANDLED

Queries the VRF remote environment controller for wind speed and direction at the requested geocentric location and queues a WindStateResponseMessage.

◆ BackendDiscovered()

static void makVre::DtVreBackendConnector::BackendDiscovered ( const DtSimulationAddress & addr,
void * usr )
static

Static callbacks for VRF backend events.

Static callback invoked when a backend simulation address is discovered

◆ BackendRemoved()

static void makVre::DtVreBackendConnector::BackendRemoved ( const DtSimulationAddress & addr,
void * usr )
static

Static callback invoked when a backend simulation address is removed.

◆ ifLoadCompleteMessageCallback()

static void makVre::DtVreBackendConnector::ifLoadCompleteMessageCallback ( DtSimMessage * msg,
void * usr )
static

Static callback invoked when a VRE backend reports scenario load complete.

Parameters
msgPointer to the DtLoadComplete simulation message
usrPointer to the connector instance

◆ backendRemapper()

static bool makVre::DtVreBackendConnector::backendRemapper ( DtBackendMap * map,
const std::set< DtSimulationAddress > & expectedBackends,
void * usr )
static

Static callback for remapping backend addresses during scenario load.

Parameters
mapBackend address map to remap
expectedBackendsSet of expected backend addresses
usrPointer to the connector instance
Returns
true if remapping succeeded

◆ hasBackendAddress()

bool makVre::DtVreBackendConnector::hasBackendAddress ( ) const

Returns true if this connector has a pending or active VRE backend address.

True from the moment handleStartBackend() sets the address, even before the backend process connects. Use for lifecycle guards (stop, shutdown, timeout).

◆ backendAddress()

DtSimulationAddress makVre::DtVreBackendConnector::backendAddress ( ) const

Returns the current VRE backend simulation address.

Returns DtSimulationAddress::nullId() when no backend address is configured. The address is stored as the vreBackendStatus.SimAddress child attribute.

◆ setStartupTimeoutSeconds()

void makVre::DtVreBackendConnector::setStartupTimeoutSeconds ( int seconds)

Sets the startup timeout used to detect backends that fail to connect.

If the backend process does not appear in the backend listener within this many seconds of being launched, the connector clears the backend state. Defaults to 30 seconds. A process-exit check (Windows only) takes priority: if the launched process is detected as exited before the timeout elapses, the state is cleared immediately.

Parameters
secondsTimeout in seconds; must be positive

◆ processBackendDiscovered()

virtual void makVre::DtVreBackendConnector::processBackendDiscovered ( const DtSimulationAddress & addr)
protectedvirtual

Processes a backend discovery notification.

Parameters
addrSimulation address of the discovered backend

◆ processBackendRemoved()

virtual void makVre::DtVreBackendConnector::processBackendRemoved ( const DtSimulationAddress & addr)
protectedvirtual

Processes a backend removal notification.

Parameters
addrSimulation address of the removed backend

◆ processLoadCompleteMessage()

virtual void makVre::DtVreBackendConnector::processLoadCompleteMessage ( DtSimMessage * msg)
protectedvirtual

Processes a load-complete message from the VRE backend.

Parameters
msgPointer to the load-complete simulation message

Calls loadedScenario() on the VRF remote controller, then takes a base snapshot.

◆ processChatEvent()

virtual void makVre::DtVreBackendConnector::processChatEvent ( const makVrfEvents::DtEvent & evt)
protectedvirtual

Processes a chat event received from the VRF event manager.

Parameters
evtThe VRF chat event; ignored if not a DtChatMessageEvent

Connected via boost signal in install(). Converts the VRF chat event to a ChatMessage and queues it in the VRE message manager.

◆ updateBackendStatus()

virtual void makVre::DtVreBackendConnector::updateBackendStatus ( )
protectedvirtual

Evaluates the current backend status and broadcasts changes to the frontend.

Inspects the backend referenced by backendAddress() via the backend listener. Sends a late-join Run command if the session is already playing but the backend just became loaded. Broadcasts BackendStatusMessage when any field changes.

◆ sendBackendStatusMessage()

virtual void makVre::DtVreBackendConnector::sendBackendStatusMessage ( )
protectedvirtual

Sends the current cached backend status to the frontend.

◆ remapBackends()

virtual bool makVre::DtVreBackendConnector::remapBackends ( DtBackendMap * map,
const std::set< DtSimulationAddress > & expectedBackends )
protectedvirtual

Remaps all backend addresses in a scenario to the current VRE backend address.

Parameters
mapBackend address map to remap in-place
expectedBackendsSet of expected backend addresses (unused; provided by VRF API)
Returns
true if remapping succeeded

◆ sendTerrainScenario()

virtual void makVre::DtVreBackendConnector::sendTerrainScenario ( DtScenario & scenario,
const LoadBackendMessage * loadMsg,
const std::set< std::string > & sessionSmsList,
const DtFilename & terrain,
const DtFilename & guiTerrain )
protectedvirtual

Configures a scenario with terrain, SMS, and component attachment settings, then sends it to the backend.

Parameters
scenarioThe scenario object to configure and send
loadMsgThe load backend message supplying exercise start time and component attachment table
sessionSmsListThe set of simulation model set filenames to add to the scenario
terrainThe terrain database filename
guiTerrainThe GUI terrain database filename; uses terrain if empty

◆ sendSessionSmsUpdate()

virtual void makVre::DtVreBackendConnector::sendSessionSmsUpdate ( )
protectedvirtual

◆ launchVrfBackend()

virtual void * makVre::DtVreBackendConnector::launchVrfBackend ( const DtSimulationAddress & address,
int sessionId,
int simType,
const std::vector< std::string > & pluginBaseNames,
bool showConsole,
std::string & additionalArguments )
protectedvirtual

Launches a VR-Forces backend process with the specified parameters.

Builds a command line via vrfSimEngineCommand() and spawns the process via the platform process API.

Parameters
addressSite/application ID to use for the new backend
sessionIdVR-Engage session ID to pass to the backend
simTypeSimulation mode: full VR-Forces, ownship-only, or limited
pluginBaseNamesList of plugin base names to load
showConsoleWhether to open a console window for the backend process
additionalArgumentsAdditional command-line arguments (may be modified)
Returns
On Windows, the process handle for the launched backend process; nullptr on other platforms or if the process was not launched.

◆ vrfSimEngineCommand()

std::string makVre::DtVreBackendConnector::vrfSimEngineCommand ( const DtSimulationAddress & address,
int sessionId,
int simType,
const std::vector< std::string > & pluginBaseNames,
std::string & additionalArguments )
protected

Builds the full command-line string for the sim engine process.

Parameters
addressSite/application ID to use
sessionIdVR-Engage session ID
simTypeSimulation mode (full, ownship, limited)
pluginBaseNamesPlugin base names to include
additionalArgumentsAdditional arguments (may be modified to remove duplicates)
Returns
Full command string ready for process creation

◆ application()

virtual std::string makVre::DtVreBackendConnector::application ( ) const
protectedvirtual

Returns the sim engine executable name (protocol- and build-variant-aware)

Returns
Executable filename, e.g. "vrEngageSimDIS.exe"

◆ connectionParameters()

virtual std::string makVre::DtVreBackendConnector::connectionParameters ( const DtSimulationAddress & address,
std::string & additionalArguments ) const
protectedvirtual

Builds protocol-specific connection parameters for the sim engine command line.

Parameters
addressSite/application ID
additionalArgumentsAdditional arguments (duplicates are removed and warned)
Returns
Connection parameter string

◆ protocol()

virtual std::string makVre::DtVreBackendConnector::protocol ( ) const
protectedvirtual

Returns the protocol name string used in command-line arguments.

Returns
Protocol string, e.g. "DIS", "HLA1516e"

◆ clearBackendState()

void makVre::DtVreBackendConnector::clearBackendState ( )
protected

Clears all backend-owned state atomically.

Sets SimEngineAddress to nullId, Enabled to false, and resets snapshot state. Called from handleStopBackend, processBackendRemoved, startup timeout, and shutdown.

Member Data Documentation

◆ myBackendProcessHandle

void* makVre::DtVreBackendConnector::myBackendProcessHandle = nullptr
protected

Handle to the launched backend process (Windows only; nullptr on other platforms)

Populated by launchVrfBackend() and cleared by clearBackendState(). Used to detect early process exit before the startup timeout fires.

◆ myVrfRemoteController

makVrf::DtVrlinkVrfRemoteController* makVre::DtVreBackendConnector::myVrfRemoteController = nullptr
protected

Infrastructure pointers (NON-OWNING — owned by DtConnectorAccessory)

Shared VRF remote controller (NON-OWNING)

Provides access to the VRF message interface, backend listener, remote control APIs, and remote environment controller. Lifetime managed by DtConnectorAccessory, guaranteed to outlive this connector.

◆ myChatEventConnection

boost::signals2::scoped_connection makVre::DtVreBackendConnector::myChatEventConnection
protected

Connection for chat event forwarding callback.

◆ myExerciseConnInitializer

const DtExerciseConnInitializer* makVre::DtVreBackendConnector::myExerciseConnInitializer = nullptr
protected

Launch configuration.

Exercise connection initializer used to build protocol-specific connection parameters

Non-owning pointer sourced from the VR-Link driver during install(). Lifetime is guaranteed to outlive this connector.

◆ mySessionId

int makVre::DtVreBackendConnector::mySessionId = 1
protected

VR-Engage session ID passed to the backend process on launch.

◆ myPlugins

std::vector<std::string> makVre::DtVreBackendConnector::myPlugins
protected

List of plugin base names to load in the backend process.

◆ myShowConsole

bool makVre::DtVreBackendConnector::myShowConsole = false
protected

Whether to open a console window for the backend process.

◆ myArguments

std::string makVre::DtVreBackendConnector::myArguments
protected

Additional command-line arguments for the backend process.

◆ myBackendStartingAddress

DtSimulationAddress makVre::DtVreBackendConnector::myBackendStartingAddress
protected

Backend state.

Starting simulation address used when launching a new backend process

Incremented if already in use (from mySimulationAddresses).

◆ myTookSnapshot

bool makVre::DtVreBackendConnector::myTookSnapshot = false
protected

True if a TakeBaseSnapshot save was issued after the scenario loaded.

◆ mySnapshotSimTime

double makVre::DtVreBackendConnector::mySnapshotSimTime = 0.0
protected

Simulation time at which the base snapshot was taken.

◆ myBackendLaunchTime

std::chrono::steady_clock::time_point makVre::DtVreBackendConnector::myBackendLaunchTime
protected

Time point at which the backend process was launched.

Used to detect backends that fail to start: if the backend has not appeared in the backend listener within a timeout period after launch, the connector clears the stale address.

◆ myStartupTimeoutSeconds

int makVre::DtVreBackendConnector::myStartupTimeoutSeconds = 30
protected

Startup timeout in seconds for detecting backends that fail to connect.

If the backend process has not appeared in the backend listener within this many seconds of being launched, the connector clears the stale backend address. Configurable via setStartupTimeoutSeconds(). Defaults to 30 seconds.

◆ mySimulationAddresses

std::set<DtSimulationAddress> makVre::DtVreBackendConnector::mySimulationAddresses
protected

Set of all discovered backend simulation addresses.

Used to avoid starting a new backend at an address already in use.

◆ mySessionPlayStateAttr

DtAttributeHandleType<bool> makVre::DtVreBackendConnector::mySessionPlayStateAttr
protected

True if the session is currently playing (not paused)

Attribute Store KeysessionPlayState

◆ mySessionSmsListAttr

DtAttributeHandleType<std::set<std::string> > makVre::DtVreBackendConnector::mySessionSmsListAttr
protected

Current set of simulation model set filenames for this session.

Attribute Store KeysessionSmsList

◆ myBackendIsHostAttr

DtAttributeHandleType<bool> makVre::DtVreBackendConnector::myBackendIsHostAttr
protected

Indicates whether this station is the backend host; true if started in full-forces (host) mode.

Attribute Store KeyvreBackendIsHost

◆ myBackendStatusAttr

DtAttributeHandleType<BackendStatusMessage::BackendStatusData> makVre::DtVreBackendConnector::myBackendStatusAttr
protected

Published backend status data.

Attribute Store KeyvreBackendStatus

◆ mySessionStatusAttr

DtAttributeHandleType<VrfSessionStatusMessage::VrfSessionStatusData> makVre::DtVreBackendConnector::mySessionStatusAttr
protected

Current cached session status data.

Attribute Store KeysessionStatus

The documentation for this class was generated from the following file: