S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_event_dispatcher Class Template Reference

Templated base class that contains a list of event handlers. More...

#include <s3_event.h>

Inheritance diagram for s3_event_dispatcher:

Inheritance graph
[legend]
Collaboration diagram for s3_event_dispatcher:

Collaboration graph
[legend]
List of all members.

Public Types

typedef T_Event event_t
 Type of the event that this handler handles. More...

typedef s3_event_handler<
event_t
event_handler_t
 Type of the event handler that can subscribe. More...


Public Methods

void subscribe_handler (event_handler_t &handler)
 Subscribe the specified handler to this dispatcher. More...

void unsubscribe_handler (event_handler_t &handler)
 Unsubscribe the specified handler to this dispatcher. More...

bool is_subscribed (const event_handler_t &handler) const
 Test and return whether the specified handler is subscribed. More...

void dispatch_event (const event_t &event)
 Dispatch the specified event to all subscribed handlers. More...


Private Types

typedef std::list< event_handler_t * > hlist_t

Private Methods

bool is_subscribed (const event_handler_t &handler, int critical) const

Private Attributes

hlist_t hlist
s3_mutex s3_event_dispatcher_lock

Detailed Description

template<typename T_Event>
class s3_event_dispatcher< T_Event >

Templated base class that contains a list of event handlers.

It is templated on the type of event that it dispatches. Event handlers, that handle the same types of events that this one dispatches, can be subscribed and unsubscribed. A handler may only be subscribed once, and attempting to re-subscribe a subscribed handler is a programming error. Only subscribed handlers may be unsubscribed and attempting to unsubscribe a subscribed handler is a programming error.

An event is dispatched to all subscribed handlers by invoking a single function call.

See also:
Event notification and handling

Definition at line 113 of file s3_event.h.


Member Typedef Documentation

template<typename T_Event>
typedef s3_event_handler<event_t> s3_event_dispatcher::event_handler_t
 

Type of the event handler that can subscribe.

Definition at line 123 of file s3_event.h.

template<typename T_Event>
typedef T_Event s3_event_dispatcher::event_t
 

Type of the event that this handler handles.

Definition at line 119 of file s3_event.h.

template<typename T_Event>
typedef std::list<event_handler_t*> s3_event_dispatcher::hlist_t [private]
 

Definition at line 126 of file s3_event.h.


Member Function Documentation

template<typename T_Event>
void s3_event_dispatcher< T_Event >::dispatch_event const event_t   event
 

Dispatch the specified event to all subscribed handlers.

Note:
Operations performed by the handlers during the execution of the handler functions, s3_event_handler::operator()(const event_t& n_event), occurs on the time of the caller.
Parameters:
event  Event to dispatch.

Definition at line 87 of file s3_event.tcc.

References hlist, s3_mutex::lock, s3_event_dispatcher_lock, and s3_mutex::unlock.

Referenced by s3_txport_tcp::connect, s3_txport_tcp::listen, s3_txport_tcp::main_loop, s3_txport_tcp::reap, and s3_txport_tcp::spawn_handler.

template<typename T_Event>
bool s3_event_dispatcher< T_Event >::is_subscribed const event_handler_t   handler,
int    critical
const [private]
 

Definition at line 103 of file s3_event.tcc.

References hlist.

template<typename T_Event>
bool s3_event_dispatcher< T_Event >::is_subscribed const event_handler_t   handler const
 

Test and return whether the specified handler is subscribed.

Parameters:
handler  Handler to test.
Return values:
c  true handler is subscribed.
c  false handler is not subscribed.

Definition at line 75 of file s3_event.tcc.

References s3_mutex::lock, s3_event_dispatcher_lock, and s3_mutex::unlock.

Referenced by subscribe_handler, and unsubscribe_handler.

template<typename T_Event>
void s3_event_dispatcher< T_Event >::subscribe_handler event_handler_t   handler
 

Subscribe the specified handler to this dispatcher.

It is the responsibility of the caller to ensure that n_handler is valid during the time that it is subscribed (i.e. the actual supplied handler is subscribed and not a copy - for obvious reasons). Throw an s3_generic_exception if n_handler is already subscribed.

Parameters:
handler  Handler to subscribe.
Precondition:
is_subscribed(n_handler) == false

Definition at line 39 of file s3_event.tcc.

References hlist, is_subscribed, s3_mutex::lock, s3_event_dispatcher_lock, and s3_mutex::unlock.

template<typename T_Event>
void s3_event_dispatcher< T_Event >::unsubscribe_handler event_handler_t   handler
 

Unsubscribe the specified handler to this dispatcher.

All resources allocated to and by n_handler can safely be freed after this call. Throw an s3_generic_exception if n_handler is not subscribed.

Parameters:
handler  Handler to unsubscribe.
Precondition:
is_subscribed(n_handler) == true

Definition at line 56 of file s3_event.tcc.

References hlist, is_subscribed, s3_mutex::lock, s3_event_dispatcher_lock, and s3_mutex::unlock.


Member Data Documentation

template<typename T_Event>
hlist_t s3_event_dispatcher::hlist [private]
 

Definition at line 128 of file s3_event.h.

Referenced by dispatch_event, is_subscribed, subscribe_handler, and unsubscribe_handler.

template<typename T_Event>
s3_mutex s3_event_dispatcher::s3_event_dispatcher_lock [private]
 

Definition at line 130 of file s3_event.h.

Referenced by dispatch_event, is_subscribed, subscribe_handler, and unsubscribe_handler.


The documentation for this class was generated from the following files:
Send comments to: s3fc@stonethree.com SourceForge Logo