![]() |
VR-Forces 4.0.4 Class Documentation
|
Messages are received by registering callback functions for the interface message content types of interest.
Objects can register a callback to be fired upon receipt of a given kind of interface message through the DtVrfMessageInterface. Message callback functions are specified as:
static void messageCallback(DtSimMessage * msg, void * usrData);
The callback receives a pointer to a DtSimMessage (simMsg.h), which is the base class from which DtSimInterfaceMessage is derived. (This is because the radio message callback mechanism use the same kind of callback - but with a different derived type of DtSimMessage, a DtVrfObjectMessage (vrfObjectMessage.h).) The message received can be cast to a DtSimInterfaceMessage so that its contents can be retrieved. A callback must not delete the messages it receives. The specification for the DtVrfMessageInterface member function for adding a callback is:
virtual void addMessageCallback(int type, DtMessageCallbackFcn fcn, void* usrData);
where:
The following example shows a callback being registered for a DtIfDeleteVrfObject with an instance of a DtSimManager pointed to by mySimManager. It provides its "this" pointer as usrData.
mySimManager->messageInterface()->addMessageCallback( DtIfDeleteVrfObjectType, MyClass::deleteObjectCallback, this); void deleteObjectCallback(DtSimMessage* msg, void * usrData) { // We know the type of DtSimMesssage is a DtSimInterfaceMessage. DtSimInterfaceMessage * ifMsg = (DtSimInterfaceMessage *) msg; // We know that the content of the incoming message will be of type // DtIfDeleteVrfObject. DtIfDeleteVrfObject * deleteVrfObjectInfo = (DtIfDeleteVrfObject*)ifMsg->interfaceContent(); DtInfo("Received delete object message for object %s\n", deleteVrfObjectInfo->objectName().string()); }
[<< Sending an Interface Message] [Home] [Top of Page] [Creating New Interface Content >>]