|
| event_router_t () |
| Construct a new event_router_t object. More...
|
|
void | call (const T &event) const |
| Call all attached listeners. Listenrs may cancel, by calling the event.cancel method. More...
|
|
bool | empty () const |
| Returns true if the container of listeners is empty, i.e. there is nothing listening for this event right now. More...
|
|
| operator bool () const |
| Returns true if any listeners are attached. More...
|
|
event_handle | operator() (std::function< void(const T &)> func) |
| Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t. More...
|
|
event_handle | attach (std::function< void(const T &)> func) |
| Attach a lambda to the event, adding a listener. The lambda should follow the signature specified when declaring the event object and should take exactly one parameter derived from event_dispatch_t. More...
|
|
bool | detach (const event_handle &handle) |
| Detach a listener from the event using a previously obtained ID. More...
|
|
template<class T>
class dpp::event_router_t< T >
Handles routing of an event to multiple listeners.
Multiple listeners may attach to the event_router_t by means of operator(). Passing a lambda into operator() attaches to the event.
Dispatchers of the event may call the event_router_t::call() method to cause all listeners to receive the event.
The event_router_t::empty() method will return true if there are no listeners attached to the event_router_t (this can be used to save time by not constructing objects that nobody will ever see).
The event_router_t::detach() method removes an existing listener from the event, using the event_handle ID returned by operator().
This class is used by the library to route all websocket events to listening code.
Example:
event_router_t<log_t> my_event;
std::cout << cc.message << "\n";
});
log_t lt;
lt.message = "foo";
my_event.call(lt);
my_event.detach(id);
size_t event_handle
A returned event handle for an event which was attached.
Definition: dispatcher.h:36
- Template Parameters
-