|
VR-Engage
2.2
|
This class provides the foundation for forwarding VREngage messages across networks. It handles message bundling for efficient transmission and provides mechanisms for forwarding specific message types. Derived classes implement the actual network transport specifics by overriding the pure virtual flush() method and optionally the netSendMessage() method.
#include <networkForwarder.h>
Public Member Functions | |
| DtNetworkForwarder (DtVreMessageFactory *factory) | |
| virtual | ~DtNetworkForwarder () |
| virtual void | flush ()=0 |
| virtual bool | enable () |
| virtual void | disable () |
| virtual void | forwardEvents (const std::string &messageType) |
| virtual void | stopForwardingEvents (const std::string &messageType) |
| virtual void | setApplicationName (const std::string &applicationName) |
| virtual std::string | applicationName () |
Static Public Member Functions | |
| static int | maxBundleSize () |
Protected Member Functions | |
| virtual makVre::DtVreMessageResult | netSendMessage (makVre::DtVreMessage *msg) |
| virtual makVre::DtVreMessageResult | handleForwardMessage (makVre::DtVreMessage *msg) |
| virtual makVre::DtVreMessageResult | handleStopForwardMessage (makVre::DtVreMessage *msg) |
| virtual makVre::DtVreMessageResult | handleRequestForwardMessage (makVre::DtVreMessage *msg) |
| virtual makVre::DtVreMessageResult | handleRequestStopForwardMessage (makVre::DtVreMessage *msg) |
Protected Attributes | |
| DtVreMessageFactory * | myMessageFactory |
| UInt64 | myId |
| std::vector< DtVreMessageBundle * > | myMessageBundles |
| std::string | myApplicationName |
| makVre::DtNetworkForwarder::DtNetworkForwarder | ( | DtVreMessageFactory * | factory | ) |
Constructor.
| factory | Pointer to the message factory for creating messages from raw data |
Initializes a new network forwarder with the specified message factory. The message factory is used to create messages from incoming raw data. This constructor also initializes the first message bundle for outgoing messages.
|
virtual |
Virtual destructor.
Calls disable() to unregister message handlers and performs cleanup.
|
pure virtual |
Flushes bundled messages to the network.
This pure virtual method must be implemented by derived classes to send accumulated message bundles over the network. Because messages are bundled for efficiency, this method should be called once per frame to ensure timely delivery of messages.
Implemented in makVre::DtExerciseConnNetworkForwarder, and makVre::DtUdpNetworkForwarder.
|
virtual |
Enables the network forwarder.
This method enables the network forwarder by registering message handlers for forwarding control messages. When enabled, the forwarder will process incoming control messages and forward outgoing messages of registered types. It also initializes the unique ID for this forwarder instance.
Reimplemented in makVre::DtExerciseConnNetworkForwarder, and makVre::DtUdpNetworkForwarder.
|
virtual |
Disables the network forwarder.
This method disables the network forwarder by unregistering all message handlers. When disabled, the forwarder will not process incoming control messages or forward outgoing messages.
Reimplemented in makVre::DtExerciseConnNetworkForwarder, and makVre::DtUdpNetworkForwarder.
|
virtual |
Starts forwarding messages of the specified type.
| messageType | The type of messages to forward |
This method registers a handler for messages of the specified type to forward them over the network. Messages of this type will be bundled and sent when flush() is called.
|
virtual |
Stops forwarding messages of the specified type.
| messageType | The type of messages to stop forwarding |
This method unregisters the handler for messages of the specified type, stopping their forwarding over the network.
|
virtual |
Sets the application name for this network forwarder.
| applicationName | The name to set for this application instance |
This method sets the application name used to filter incoming forwarding request messages. Only requests targeting this application name will be processed.
References applicationName().
|
virtual |
Gets the current application name.
Returns the application name previously set with setApplicationName().
Referenced by setApplicationName().
|
static |
Gets the maximum size of a message bundle.
This static method returns the maximum size of a message bundle, which is calculated to fit within a single UDP packet including headers.
|
protectedvirtual |
Sends a message through the network.
| msg | Pointer to the message to send |
This method bundles the message for efficient network transmission. If the message was not previously forwarded (originatingApplicationId is 0), it is added to an appropriate message bundle and tagged with this forwarder's ID. The actual transmission occurs when flush() is called.
Derived classes may override this method to implement custom message handling.
Reimplemented in makVre::DtExerciseConnNetworkForwarder.
|
protectedvirtual |
Handles ForwardMessage control messages.
| msg | Pointer to the received message |
This method processes ForwardMessage control messages, which request forwarding of a specific message type. It calls forwardEvents() with the specified message type.
|
protectedvirtual |
Handles StopForwardMessage control messages.
| msg | Pointer to the received message |
This method processes StopForwardMessage control messages, which request stopping forwarding of a specific message type. It calls stopForwardingEvents() with the specified message type.
|
protectedvirtual |
Handles RequestForwardMessage control messages.
| msg | Pointer to the received message |
This method processes RequestForwardMessage control messages, which request forwarding of a specific message type from a specific host. If the request is for this host (matching applicationName), it calls forwardEvents().
|
protectedvirtual |
Handles RequestStopForwardMessage control messages.
| msg | Pointer to the received message |
This method processes RequestStopForwardMessage control messages, which request stopping forwarding of a specific message type from a specific host. If the request is for this host (matching applicationName), it calls stopForwardingEvents().
|
protected |
Pointer to the message factory for creating messages from raw data.
|
protected |
Unique identifier for this network forwarder instance.
This ID is used to tag outgoing messages to prevent processing loops when messages are received from the network.
|
protected |
Vector of message bundles for outgoing messages.
Messages are accumulated in these bundles until flush() is called. New bundles are created as needed when existing ones are full.
|
protected |
Application name for filtering forwarding request messages.
Only forwarding requests targeting this application name will be processed.