VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Network Access from Main Thread

Table of Contents

Since the main thread and the network thread cannot communicate directly to ensure thread safety, helper classes have been created to aid in the communcation with the network thread.

As referenced in How the Visuals and The Network Work Together the agents are the way the network communicates with the main thread and event signalers are the way that the main thread communicates with the network thread.

Shared Network Signaler

The makVrf::DtSharedNetworkSignaler is the main class used in order to send event signals to the network thread. This class is one of the lowest levels in the main thread to communicate with the network thread. This class will be used by other higher level classes which wrap it to do network thread communication.

The Remote Controller

The makVrf::DtGuiThreadVrfRemoteController class mirrors the DtVrfRemoteController class which is used to communicate with the back-end over the exercise connection. The remote controller class has a similar API that uses the shared network signaler to send messages to the network thread that will ultimately use the DtVrfRemoteController to communicate with the network. One of the more convenient ways to communicate to the network thread is via vrforces interface messages. The interface messages are protocol independent such that you can create a message in the front-end and send it to the back-end using the remote controller class

This message is processed on the network side and is used to call the network protocol remote controller

The Network Callback Manager

The makVrf::DtGuiThreadNetworkCallbackManager is the main threads interface to receipt of network messages (see Network Message Agent). These interface messages can be used in the main thread to process simulation information in a protocol independent way. This concept is used throughout the front-end, and, is used to connect to specific messages that want to be received by a particular class. There are some convenience macros defined that you can use to connect (or disconnect) for these messages:

#define CONNECT_FOR_SIM_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).simMessageSignal(_type).connect(_function);
#define DISCONNECT_FOR_SIM_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).simMessageSignal(_type).disconnect(_function);
#define CONNECT_FOR_OBJECT_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).objectMessageSignal(_type).connect(_function);
#define DISCONNECT_FOR_OBJECT_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).objectMessageSignal(_type).disconnect(_function);
#define CONNECT_FOR_COMMENT_INTERACTION(_function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).networkInterfaceMessageSignal(DtCommentInteractionInterface::theName()).connect(_function);
#define DISCONNECT_FOR_COMMENT_INTERACTION(_function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).networkInterfaceMessageSignal(DtCommentInteractionInterface::theName()).disconnect(_function);
#define CONNECT_FOR_INFLUENCE_INTERACTION(_function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).networkInterfaceMessageSignal(DtInfluenceInteractionInterface::theName()).connect(_function);
#define DISCONNECT_FOR_INFLUENCE_INTERACTION(_function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).networkInterfaceMessageSignal(DtInfluenceInteractionInterface::theName()).disconnect(_function);
#define CONNECT_FOR_RADIO_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).radioMessageSignal(_type).connect(_function);
#define DISCONNECT_FOR_RADIO_MESSAGE(_type, _function) makVrf::DtGuiThreadNetworkCallbackManager::instance(myDe).radioMessageSignal(_type).disconnect(_function);

When connecting to a callback, it is also important (when no longer needed or in an object destructor) to disconnect from this callback to prevent unexecpected message receipt or crashes if the system tries to make a callback to a deleted object. As you an see, there are different types of messages that can be received by the front-end, so, when making your connection, it is important to know which kind of message you are expecting to receive:

The most common kind of message send is the interface content message.

Attention
Note that the memory that is passed in will be deleted when all the calls have processed this message. If you wish to hold onto the message make a clone() of it.

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)