RobWorkProject  23.9.11-
Public Types | Public Member Functions | Public Attributes | List of all members
Event< CallBackMethod, T1, T2, T3, T4 > Class Template Reference

Event is used for managing subscribtions and firing of events. More...

#include <Event.hpp>

Public Types

typedef rw::core::EventListener< CallBackMethod > Listener
 
typedef std::list< Listener >::const_iterator ConstListenerIterator
 iterator of event listeners
 

Public Member Functions

 Event ()
 constructor
 
void add (CallBackMethod callback, const void *obj=nullptr, int id=0)
 Descructor. More...
 
void remove (void *obj)
 Removes all callback method from a given obj. More...
 
void remove (void *obj, int id)
 Removes all callback methods associated with the obj and id. More...
 
std::pair< ConstListenerIterator, ConstListenerIteratorgetListeners ()
 Returns list of listeners to the event. More...
 
std::list< Listener > & getListenerList ()
 Get the list of listeners for this event. More...
 

Public Attributes

FireFunctor< CallBackMethod, T1, T2, T3, T4, _n1fire
 Fires the event. More...
 

Detailed Description

template<class CallBackMethod, class T1 = _n1, class T2 = _n1, class T3 = _n1, class T4 = _n1>
class rw::core::Event< CallBackMethod, T1, T2, T3, T4 >

Event is used for managing subscribtions and firing of events.

Event is used for managing subscribtions and firing of events. The signature of the callback method and the fire method is termined through the template arguments.

CallBackMethod, defines the signature of the callback method needed for subscribing to the event.

FireEventMethod, defines the interface for firing events.

Example of usage in RobWorkStudio:

In: RobWorkStudio.hpp
typedef boost::function<void(const rw::kinematics::State&)> StateChangedListener;
typedef Event<StateChangedListener, StateChangedListener> StateChangedEvent;
StateChangedEvent& stateChangedEvent() {
return _stateChangedEvent;
}
void fireStateChangedEvent(const rw::kinematics::State& state) {
for(const StateChangedEvent::Listener& listener : stateChangedEvent().getListeners()) {
listener.callback(state);
}
}
In: RobWorkStudio.cpp
RobWorkStudio::RobWorkStudio(...):
_stateChangedEvent(boost::bind(&RobWorkStudio::fireStateChangedEvent, this,
boost::arg<1>())),
...
{
...
}
std::pair< ConstListenerIterator, ConstListenerIterator > getListeners()
Returns list of listeners to the event.
Definition: core/Event.hpp:179
The state of a work cell (or kinematics tree).
Definition: State.hpp:64

Member Function Documentation

◆ add()

void add ( CallBackMethod  callback,
const void *  obj = nullptr,
int  id = 0 
)
inline

Descructor.

Adds a listener to the event

Adds callback as a listener to the event. The optional obj and id are stored with callback to enable removing listeners. It is recommended to set obj as the object on which the callback is defined.

Direct comparison of boost::function pointers does not work on all platform. It is thus necessary to provide the user with the optional id to enable removing a specific callback.

Typical usage

void MyPlugin::frameSelectedListener(rw::core::Ptr<rw::kinematics::Frame> frame) {
...
}
void MyPlugin::initialize() {
getRobWorkStudio()->frameSelectedEvent().add(
boost::bind(&MyPlugin::frameSelectedListener, this, boost::arg<1>()), this);
}
Parameters
callback[in] The callback function
obj[in] Pointer to object associated with the listener (only used when removing listeners)
id[in] Id associated with the callback (only used for removing a specific listener)

◆ getListenerList()

std::list<Listener>& getListenerList ( )
inline

Get the list of listeners for this event.

Returns
list of listeners.

◆ getListeners()

std::pair<ConstListenerIterator, ConstListenerIterator> getListeners ( )
inline

Returns list of listeners to the event.

Returns
List of listeners

◆ remove() [1/2]

void remove ( void *  obj)
inline

Removes all callback method from a given obj.

All callbacks associated with obj are removed. Typical use will be to remove all callbacks to an object before it is destroyed.

Parameters
obj[in] Object for which to remove listeners

◆ remove() [2/2]

void remove ( void *  obj,
int  id 
)
inline

Removes all callback methods associated with the obj and id.

Parameters
obj[in] Object associated with the callback
id[in] Id of the callback

Member Data Documentation

◆ fire

FireFunctor<CallBackMethod, T1, T2, T3, T4, _n1> fire

Fires the event.

The signature of the fire method depends on the FireEventMethod template argument.


The documentation for this class was generated from the following file: