VR-Engage  2.2
Loading...
Searching...
No Matches
makRadarFx::DtRadarFxConnector Class Reference

Detailed Description

The DtRadarFxConnector class provides a client interface for connecting to a RadarFX server. It manages the connection lifecycle, sends and receives messages, and provides callbacks for connection events. The class includes functionality for automatic reconnection and message queuing.

This connector operates with a worker thread that handles the actual network communication while presenting a thread-safe interface to client code.

#include <radarFxConnector.h>

Public Types

typedef DtDelegate< void, DtRadarFxConnector * > DtConnectionDelegate
 

Public Member Functions

 DtRadarFxConnector ()
 
virtual ~DtRadarFxConnector ()
 
virtual void connect (const std::string &address, int port=DtRadarFXPort, bool attemptRetry=true)
 
virtual void disconnect ()
 
virtual bool isOk ()
 
virtual void tick ()
 
virtual void sendMessage (DtBaseMessage &request)
 
virtual DtVreMessageHandlermessageHandler ()
 
virtual void addConnectedCallback (const DtConnectionDelegate &delegate)
 
virtual void removeConnectedCallback (const DtConnectionDelegate &delegate)
 
virtual void addDisconnectedCallback (const DtConnectionDelegate &delegate)
 
virtual void removeDisconnectedCallback (const DtConnectionDelegate &delegate)
 
virtual DtVreMessageFactorymessageFactory ()
 
virtual unsigned int nextId ()
 
virtual std::string & requesterName ()
 

Static Public Member Functions

static double defaultRetryTimeout ()
 
static void setDefaultRetryTimeout (double val)
 
static double defaultHeartbeatTimeout ()
 
static void setDefaultHeatbeatTimeout (double val)
 

Protected Member Functions

DtInetAddr findFirstNetworkDeviceAddress (bool &found) const
 

Static Protected Member Functions

static void workerFunction (void *data, volatile bool *stop)
 

Protected Attributes

DtVreMessageHandler myMessageHandler
 
std::list< DtConnectionDelegatemyConnectionCallbacks
 
std::list< DtConnectionDelegatemyDisconnectionCallbacks
 
DtVreMessageFactory myMessageFactory
 
unsigned int myNextId
 
std::string myRequestorName
 
DtLocklessQueue< DtBaseMessage * > myOutgoingQueue
 
DtLocklessQueue< DtBaseMessage * > myIncomingQueue
 
DtThread * myWorkerThread
 
DtInetTcpSocket * mySocket
 
bool myShouldRetryConnect
 
double myRetryTimeout
 
std::string myAddress
 
int myPort
 
bool myShouldQuit
 

Static Protected Attributes

static double theDefaultHeatbeatTimeout
 
static double theDefaultRetryTimeout
 

Member Typedef Documentation

◆ DtConnectionDelegate

Type definition for connection state change callback delegates.

This delegate type is used for callbacks that are triggered when the connection state changes (connected or disconnected)

Constructor & Destructor Documentation

◆ DtRadarFxConnector()

makRadarFx::DtRadarFxConnector::DtRadarFxConnector ( )

Default constructor.

Initializes a new RadarFx connector with default settings

◆ ~DtRadarFxConnector()

virtual makRadarFx::DtRadarFxConnector::~DtRadarFxConnector ( )
virtual

Virtual destructor.

Cleans up resources and stops the worker thread

Member Function Documentation

◆ connect()

virtual void makRadarFx::DtRadarFxConnector::connect ( const std::string & address,
int port = DtRadarFXPort,
bool attemptRetry = true )
virtual

Establishes a connection to a remote RadarFX server.

Parameters
addressIP address or hostname of the RadarFX server
portNetwork port the server is listening on (defaults to DtRadarFXPort)
attemptRetryWhether to automatically retry connection if it fails or disconnects

Initiates a connection to the specified RadarFX server. When the connection is established, all registered connection callbacks will be executed. If attemptRetry is true, the connector will automatically attempt to reconnect if the initial connection fails or if the connection is lost.

References makRadarFx::DtRadarFXPort.

◆ disconnect()

virtual void makRadarFx::DtRadarFxConnector::disconnect ( )
virtual

Disconnects from the RadarFX server.

Closes the connection to the server and stops any automatic reconnection attempts. All registered disconnection callbacks will be executed.

◆ isOk()

virtual bool makRadarFx::DtRadarFxConnector::isOk ( )
virtual

Checks if the connection is valid.

Returns
True if the connection has been established and is currently valid

Determines whether there is an active, valid connection to the RadarFX server

◆ tick()

virtual void makRadarFx::DtRadarFxConnector::tick ( )
virtual

Processes queued messages and updates internal state.

This method must be called periodically (typically once per frame) to process incoming messages and execute associated callbacks. It also handles connection retries if enabled.

◆ sendMessage()

virtual void makRadarFx::DtRadarFxConnector::sendMessage ( DtBaseMessage & request)
virtual

Sends a message to the RadarFX server.

Parameters
requestReference to the message to send

Queues a message to be sent to the RadarFX server. A copy of the message is made internally, so the original message can safely go out of scope immediately after sendMessage is called. If the message has no ID or requester name set, these will be automatically assigned.

◆ messageHandler()

virtual DtVreMessageHandler & makRadarFx::DtRadarFxConnector::messageHandler ( )
inlinevirtual

Gets the message handler for incoming message processing.

Returns
Reference to the message handler used by this connector

Provides access to the message handler that dispatches incoming messages. Users should register their delegates with this handler to process specific message types when they are received from the server.

References myMessageHandler.

◆ addConnectedCallback()

virtual void makRadarFx::DtRadarFxConnector::addConnectedCallback ( const DtConnectionDelegate & delegate)
virtual

Registers a callback for successful connections.

Parameters
delegateThe callback delegate to register

Adds a delegate that will be called when a connection to the RadarFX server is successfully established

◆ removeConnectedCallback()

virtual void makRadarFx::DtRadarFxConnector::removeConnectedCallback ( const DtConnectionDelegate & delegate)
virtual

Unregisters a previously registered connection callback.

Parameters
delegateThe callback delegate to unregister

Removes a delegate from the list of callbacks that are called when a connection is established

◆ addDisconnectedCallback()

virtual void makRadarFx::DtRadarFxConnector::addDisconnectedCallback ( const DtConnectionDelegate & delegate)
virtual

Registers a callback for disconnections.

Parameters
delegateThe callback delegate to register

Adds a delegate that will be called when the connection to the RadarFX server is lost

◆ removeDisconnectedCallback()

virtual void makRadarFx::DtRadarFxConnector::removeDisconnectedCallback ( const DtConnectionDelegate & delegate)
virtual

Unregisters a previously registered disconnection callback.

Parameters
delegateThe callback delegate to unregister

Removes a delegate from the list of callbacks that are called when a disconnection occurs

◆ messageFactory()

virtual DtVreMessageFactory & makRadarFx::DtRadarFxConnector::messageFactory ( )
inlinevirtual

Gets the message factory used for message creation.

Returns
Reference to the message factory

Provides access to the message factory that creates and decodes messages. Users can add custom message decoders to this factory to handle application-specific message types.

References myMessageFactory.

◆ nextId()

virtual unsigned int makRadarFx::DtRadarFxConnector::nextId ( )
virtual

Generates a unique message ID.

Returns
A unique identifier for a message

Provides a unique ID for tracking message responses. This function is automatically used to assign IDs to messages that don't have one set (id field is 0) when sendMessage is called.

◆ requesterName()

virtual std::string & makRadarFx::DtRadarFxConnector::requesterName ( )
virtual

Gets a unique name for this client application.

Returns
String containing a unique requester name

Provides a unique name for the client derived from the IP address and process ID of the running application. This name is automatically assigned to messages that don't have a requester name set when sendMessage is called.

◆ defaultRetryTimeout()

static double makRadarFx::DtRadarFxConnector::defaultRetryTimeout ( )
static

Gets the default timeout for connection retry attempts.

Returns
Default retry timeout in seconds

Returns the time in seconds between reconnection attempts when automatic retry is enabled. The default value is 5 seconds.

◆ setDefaultRetryTimeout()

static void makRadarFx::DtRadarFxConnector::setDefaultRetryTimeout ( double val)
static

Sets the default timeout for connection retry attempts.

Parameters
valNew timeout value in seconds

Sets the time in seconds between reconnection attempts when automatic retry is enabled.

◆ defaultHeartbeatTimeout()

static double makRadarFx::DtRadarFxConnector::defaultHeartbeatTimeout ( )
static

Gets the default heartbeat timeout.

Returns
Default heartbeat timeout in seconds

Returns the timeout for heartbeat messages used to detect connection loss. The default value is 2.5 seconds.

◆ setDefaultHeatbeatTimeout()

static void makRadarFx::DtRadarFxConnector::setDefaultHeatbeatTimeout ( double val)
static

Sets the default heartbeat timeout.

Parameters
valNew timeout value in seconds

Sets the timeout for heartbeat messages used to detect connection loss.

◆ findFirstNetworkDeviceAddress()

DtInetAddr makRadarFx::DtRadarFxConnector::findFirstNetworkDeviceAddress ( bool & found) const
protected

Finds the IP address of the first available network device.

Parameters
foundSet to true if an address was found, false otherwise
Returns
Network address of the first available device

Searches for and returns the IP address of the first available network device on the system

◆ workerFunction()

static void makRadarFx::DtRadarFxConnector::workerFunction ( void * data,
volatile bool * stop )
staticprotected

Worker thread function that runs network communication.

Parameters
dataPointer to the DtRadarFxConnector instance
stopPointer to a flag indicating if the thread should stop

This static function is executed by the worker thread to handle network communication asynchronously

Member Data Documentation

◆ myMessageHandler

DtVreMessageHandler makRadarFx::DtRadarFxConnector::myMessageHandler
protected

Message handler for processing incoming messages.

Referenced by messageHandler().

◆ myConnectionCallbacks

std::list<DtConnectionDelegate> makRadarFx::DtRadarFxConnector::myConnectionCallbacks
protected

List of callbacks to invoke when connection is established.

◆ myDisconnectionCallbacks

std::list<DtConnectionDelegate> makRadarFx::DtRadarFxConnector::myDisconnectionCallbacks
protected

List of callbacks to invoke when connection is lost.

◆ myMessageFactory

DtVreMessageFactory makRadarFx::DtRadarFxConnector::myMessageFactory
protected

Factory for creating and decoding messages.

Referenced by messageFactory().

◆ myNextId

unsigned int makRadarFx::DtRadarFxConnector::myNextId
protected

Counter for generating unique message IDs.

◆ myRequestorName

std::string makRadarFx::DtRadarFxConnector::myRequestorName
protected

Unique name for this client instance.

◆ myOutgoingQueue

DtLocklessQueue<DtBaseMessage*> makRadarFx::DtRadarFxConnector::myOutgoingQueue
protected

Thread-safe queue for outgoing messages.

◆ myIncomingQueue

DtLocklessQueue<DtBaseMessage*> makRadarFx::DtRadarFxConnector::myIncomingQueue
protected

Thread-safe queue for incoming messages.

◆ myWorkerThread

DtThread* makRadarFx::DtRadarFxConnector::myWorkerThread
protected

Worker thread that handles network communication.

◆ mySocket

DtInetTcpSocket* makRadarFx::DtRadarFxConnector::mySocket
protected

Socket for TCP communication with the server.

◆ myShouldRetryConnect

bool makRadarFx::DtRadarFxConnector::myShouldRetryConnect
protected

Flag indicating whether to automatically retry connections.

◆ myRetryTimeout

double makRadarFx::DtRadarFxConnector::myRetryTimeout
protected

Time in seconds between connection retry attempts.

◆ myAddress

std::string makRadarFx::DtRadarFxConnector::myAddress
protected

Server address to connect to.

◆ myPort

int makRadarFx::DtRadarFxConnector::myPort
protected

Server port to connect to.

◆ myShouldQuit

bool makRadarFx::DtRadarFxConnector::myShouldQuit
protected

Flag indicating if the worker thread should terminate.

◆ theDefaultHeatbeatTimeout

double makRadarFx::DtRadarFxConnector::theDefaultHeatbeatTimeout
staticprotected

Static storage for default heartbeat timeout.

◆ theDefaultRetryTimeout

double makRadarFx::DtRadarFxConnector::theDefaultRetryTimeout
staticprotected

Static storage for default retry timeout.


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