#include <OMKEventListenerCallBack.h>
Inheritance diagram for OMK::EventListenerCallBack< CallerClass >:
Public Types | |
typedef bool(CallerClass::*) | CallBackFct (Event *event) |
Define type of the callback method. | |
Protected Member Functions | |
Inherited from EventListener | |
virtual bool | processEvent (Event *event) |
Process an event. | |
virtual void | registerEvents () |
Member function used to register the event the eventListener has to react to. | |
Protected Attributes | |
Attributs | |
CallerClass * | _callerInstance |
Pointer to the associated simulated object, owner of the listener and the callback method. | |
CallBackFct | _callBackFct |
Pointer to the callback method of the associated simulated object. | |
EventIdentifier | _eventId |
Identifier of the listened event. |
This listener is a template class, the parameter is:
class MySimulatedObject : public SimulatedObject { //... protected: // The event listener EventListenerCallBack<MySimulatedObject>* _p_eventListener ; // The callback method which will be called bool myCallBackMethod( Event* e ) ; //... };
The listener is created in the init method of the simulated object. Since it is automatically registered it cannot be created in the constructor of the simulated object.
void MySimulatedObject::init() { //... _p_eventListener = new EventListenerCallBack<MySimulatedObject>( *this, myCallBackMethod, TheEventEmitter::s_eventId ) ; //... }
The callback is a member method of the simulated object:
bool MySimulatedObject::myCallBackMethod( Event* e ) { //...To do }
The registration and the cancel are handled by the simulated object. So, to receive or stop a signal the object must use registerForSignal (or registerForSignalBy for a specific sender) or cancelRegistrationForSignal (respectively cancelRegistrationForSignalBy).
The sender will use fireSignal or fireValuedSignal methods.
If the sender uses sendEvent or sendValuedEvent the listener receives automatically the event and calls the callback method.
Definition at line 92 of file OMKEventListenerCallBack.h.
typedef bool(CallerClass::*) OMK::EventListenerCallBack< CallerClass >::CallBackFct(Event *event) |
Define type of the callback method.
The callback is a member method of the simulated object which is the owner of the listener. The prototype of the callback method is:
bool myCallBackMethod( Event* e ) ;
[in] | \b | event the event to processed. |
If you want to prevent the event from being seen by the other event listeners but want it seen by the object, call owner.processEvent and return true. Warning, if owner.processEvent returns false, you will have a problem because the event will be destroyed while the owner thinks it can still use it safely.
Definition at line 118 of file OMKEventListenerCallBack.h.
OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack | ( | CallerClass & | owner, | |
CallBackFct | callBackFct, | |||
const EventIdentifier & | eventId | |||
) | [inline] |
Constructor.
[in] | owner | the simulated object owner of the listener and of the callback (ex:*this ). |
[in] | callBackFct | the callback method. |
[in] | eventId | identifier of the event to listen. |
Call the ancestor and store the callback method pointer.
Automatically register the event identifier.
The constructor must be called in the init method of the owner.
Definition at line 131 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_callBackFct, OMK::EventListenerCallBack< CallerClass >::_callerInstance, OMK::EventListener::_owner, OMK::SimulatedObject::addEventListener(), and OMASSERTM.
00134 : EventListener( owner ), _callerInstance( &owner ), _callBackFct( callBackFct ), _eventId( eventId ) 00135 { 00136 // The owner instance and the callback method must be set 00137 OMASSERTM( _callerInstance && _callBackFct, "The owner instance and the callback method must be set" ); 00138 _owner.addEventListener( *this ) ; 00139 }
OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack | ( | SimulatedObject & | owner, | |
CallerClass * | callerInstance, | |||
CallBackFct | callBackFct, | |||
const EventIdentifier & | eventId | |||
) | [inline] |
Constructor.
[in] | owner | the simulated object owner of the listener (ex:*this ). |
[in] | callerInstance | the object which be called for the callback. |
[in] | callBackFct | the callback method. |
[in] | eventId | identifier of the event to listen. |
Call the ancestor and store the callback method pointer.
Automatically register the event identifier.
The constructor must be called in the init method of the owner.
Definition at line 152 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_callBackFct, OMK::EventListenerCallBack< CallerClass >::_callerInstance, OMK::EventListener::_owner, OMK::SimulatedObject::addEventListener(), and OMASSERTM.
00155 : EventListener( owner ), _callerInstance( callerInstance ), _callBackFct( callBackFct ), _eventId( eventId ) 00156 { 00157 // The owner instance and the callback method must be set 00158 OMASSERTM( _callerInstance && _callBackFct, "The owner instance and the callback method must be set" ); 00159 _owner.addEventListener( *this ) ; 00160 }
virtual OMK::EventListenerCallBack< CallerClass >::~EventListenerCallBack | ( | ) | [inline, virtual] |
OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack | ( | CallerClass & | owner, | |
CallBackFct | callBackFct, | |||
const EventIdentifier & | eventId | |||
) | [inline] |
Constructor.
[in] | owner | the simulated object owner of the listener and of the callback (ex:*this ). |
[in] | callBackFct | the callback method. |
[in] | eventId | identifier of the event to listen. |
Call the ancestor and store the callback method pointer.
Automatically register the event identifier.
The constructor must be called in the init method of the owner.
Definition at line 131 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_callBackFct, OMK::EventListenerCallBack< CallerClass >::_callerInstance, OMK::EventListener::_owner, OMK::SimulatedObject::addEventListener(), and OMASSERTM.
00134 : EventListener( owner ), _callerInstance( &owner ), _callBackFct( callBackFct ), _eventId( eventId ) 00135 { 00136 // The owner instance and the callback method must be set 00137 OMASSERTM( _callerInstance && _callBackFct, "The owner instance and the callback method must be set" ); 00138 _owner.addEventListener( *this ) ; 00139 }
OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack | ( | SimulatedObject & | owner, | |
CallerClass * | callerInstance, | |||
CallBackFct | callBackFct, | |||
const EventIdentifier & | eventId | |||
) | [inline] |
Constructor.
[in] | owner | the simulated object owner of the listener (ex:*this ). |
[in] | callerInstance | the object which be called for the callback. |
[in] | callBackFct | the callback method. |
[in] | eventId | identifier of the event to listen. |
Call the ancestor and store the callback method pointer.
Automatically register the event identifier.
The constructor must be called in the init method of the owner.
Definition at line 152 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_callBackFct, OMK::EventListenerCallBack< CallerClass >::_callerInstance, OMK::EventListener::_owner, OMK::SimulatedObject::addEventListener(), and OMASSERTM.
00155 : EventListener( owner ), _callerInstance( callerInstance ), _callBackFct( callBackFct ), _eventId( eventId ) 00156 { 00157 // The owner instance and the callback method must be set 00158 OMASSERTM( _callerInstance && _callBackFct, "The owner instance and the callback method must be set" ); 00159 _owner.addEventListener( *this ) ; 00160 }
virtual OMK::EventListenerCallBack< CallerClass >::~EventListenerCallBack | ( | ) | [inline, virtual] |
virtual bool OMK::EventListenerCallBack< CallerClass >::processEvent | ( | Event * | event | ) | [inline, protected, virtual] |
Process an event.
Call the associated callback
Implements OMK::EventListener.
Definition at line 172 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_callBackFct, and OMK::EventListenerCallBack< CallerClass >::_callerInstance.
00173 { 00174 return (_callerInstance->*_callBackFct)( event ) ; 00175 }
virtual void OMK::EventListenerCallBack< CallerClass >::registerEvents | ( | ) | [inline, protected, virtual] |
Member function used to register the event the eventListener has to react to.
Reimplemented from OMK::EventListener.
Definition at line 177 of file OMKEventListenerCallBack.h.
References OMK::EventListenerCallBack< CallerClass >::_eventId, OMK::EventListener::_owner, and OMK::SimulatedObject::registerEventListenerForEvent().
CallerClass* OMK::EventListenerCallBack< CallerClass >::_callerInstance [protected] |
Pointer to the associated simulated object, owner of the listener and the callback method.
Definition at line 188 of file OMKEventListenerCallBack.h.
Referenced by OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack(), and OMK::EventListenerCallBack< CallerClass >::processEvent().
CallBackFct OMK::EventListenerCallBack< CallerClass >::_callBackFct [protected] |
Pointer to the callback method of the associated simulated object.
Definition at line 190 of file OMKEventListenerCallBack.h.
Referenced by OMK::EventListenerCallBack< CallerClass >::EventListenerCallBack(), and OMK::EventListenerCallBack< CallerClass >::processEvent().
EventIdentifier OMK::EventListenerCallBack< CallerClass >::_eventId [protected] |
Identifier of the listened event.
Definition at line 192 of file OMKEventListenerCallBack.h.
Referenced by OMK::EventListenerCallBack< CallerClass >::registerEvents().
Documentation generated on Mon Jun 9 11:46:01 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |