|
VR-Engage
2.2
|
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 DtVreMessageHandler & | messageHandler () |
| 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 DtVreMessageFactory & | messageFactory () |
| 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< DtConnectionDelegate > | myConnectionCallbacks |
| std::list< DtConnectionDelegate > | myDisconnectionCallbacks |
| 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 |
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)
| makRadarFx::DtRadarFxConnector::DtRadarFxConnector | ( | ) |
Default constructor.
Initializes a new RadarFx connector with default settings
|
virtual |
Virtual destructor.
Cleans up resources and stops the worker thread
|
virtual |
Establishes a connection to a remote RadarFX server.
| address | IP address or hostname of the RadarFX server |
| port | Network port the server is listening on (defaults to DtRadarFXPort) |
| attemptRetry | Whether 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.
|
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.
|
virtual |
Checks if the connection is valid.
Determines whether there is an active, valid connection to the RadarFX server
|
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.
|
virtual |
Sends a message to the RadarFX server.
| request | Reference 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.
|
inlinevirtual |
Gets the message handler for incoming message processing.
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.
|
virtual |
Registers a callback for successful connections.
| delegate | The callback delegate to register |
Adds a delegate that will be called when a connection to the RadarFX server is successfully established
|
virtual |
Unregisters a previously registered connection callback.
| delegate | The callback delegate to unregister |
Removes a delegate from the list of callbacks that are called when a connection is established
|
virtual |
Registers a callback for disconnections.
| delegate | The callback delegate to register |
Adds a delegate that will be called when the connection to the RadarFX server is lost
|
virtual |
Unregisters a previously registered disconnection callback.
| delegate | The callback delegate to unregister |
Removes a delegate from the list of callbacks that are called when a disconnection occurs
|
inlinevirtual |
Gets the message factory used for message creation.
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.
|
virtual |
Generates a unique message ID.
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.
|
virtual |
Gets a unique name for this client application.
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.
|
static |
Gets the default timeout for connection retry attempts.
Returns the time in seconds between reconnection attempts when automatic retry is enabled. The default value is 5 seconds.
|
static |
Sets the default timeout for connection retry attempts.
| val | New timeout value in seconds |
Sets the time in seconds between reconnection attempts when automatic retry is enabled.
|
static |
Gets the default heartbeat timeout.
Returns the timeout for heartbeat messages used to detect connection loss. The default value is 2.5 seconds.
|
static |
Sets the default heartbeat timeout.
| val | New timeout value in seconds |
Sets the timeout for heartbeat messages used to detect connection loss.
|
protected |
Finds the IP address of the first available network device.
| found | Set to true if an address was found, false otherwise |
Searches for and returns the IP address of the first available network device on the system
|
staticprotected |
Worker thread function that runs network communication.
| data | Pointer to the DtRadarFxConnector instance |
| stop | Pointer to a flag indicating if the thread should stop |
This static function is executed by the worker thread to handle network communication asynchronously
|
protected |
Message handler for processing incoming messages.
Referenced by messageHandler().
|
protected |
List of callbacks to invoke when connection is established.
|
protected |
List of callbacks to invoke when connection is lost.
|
protected |
Factory for creating and decoding messages.
Referenced by messageFactory().
|
protected |
Counter for generating unique message IDs.
|
protected |
Unique name for this client instance.
|
protected |
Thread-safe queue for outgoing messages.
|
protected |
Thread-safe queue for incoming messages.
|
protected |
Worker thread that handles network communication.
|
protected |
Socket for TCP communication with the server.
|
protected |
Flag indicating whether to automatically retry connections.
|
protected |
Time in seconds between connection retry attempts.
|
protected |
Server address to connect to.
|
protected |
Server port to connect to.
|
protected |
Flag indicating if the worker thread should terminate.
|
staticprotected |
Static storage for default heartbeat timeout.
|
staticprotected |
Static storage for default retry timeout.