Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ark::AsyncNotifier< Notification, Observer_t, Observed_t > Class Template Reference

#include <AsyncNotifier.h>

Inheritance diagram for ark::AsyncNotifier< Notification, Observer_t, Observed_t >:

ark::AsyncConsumer< Notification > ark::Notifier< Notification, Observer_t, Observed_t > ARK_ASYNC_CONSUMER_DEFAULT_SOURCE_QUEUE_POLICY noncopyable List of all members.

Public Member Functions

void receiveNotification (Notification const &note)
void consume (Notification &note, SourceQueue &q)
void addObserver (boost::shared_ptr< Observer_t > const &obj)
void addObserver (boost::shared_ptr< Observer_t > const &obj, Observed_t const &obs)
void addObserver (boost::shared_ptr< Observer_t > const &obj, Notification const &note)
void removeObserver (boost::shared_ptr< Observer_t > &obj)
void removeObserver (boost::shared_ptr< Observer_t > &obj, Observed_t const &observed)
void removeObserver (boost::shared_ptr< Observer_t > &obj, Notification const &note)
bool isObserving (boost::shared_ptr< Observer_t > const &obj)
void setMultithreaded (bool mt)
bool isMultithreaded () const

Protected Types

typedef boost::mutex::scoped_lock scoped_lock

Private Types

typedef Notifier< Notification,
Observer_t, Observed_t > 
note_super
typedef AsyncConsumer< Notification
>::SourceQueue 
SourceQueue

Private Member Functions

void _dispatchNotification (Notification note)
 Runs in own thread.

Private Attributes

boost::mutex _allMutex
boost::thread_group _distributors
Atomic< bool > _multithreads

Detailed Description

template<typename Notification, typename Observer_t, typename Observed_t>
class ark::AsyncNotifier< Notification, Observer_t, Observed_t >

AsyncNotifier AsyncNotifier is a refinement of the AsyncConsumer class which takes notifications about an observed object and passes them to consumers of the notification, possibly in a different thread.

There are two modes to determine how asynchronously the notifications are distributed. The 'normal' mode simply distributes notifications to all registered observers in the consume() override. Remember that as an AsyncConsumer, our runloop is already in it's own dedicated thread, and thus normal mode is usually sufficient. However for fringe cases there is also the multithreaded mode, where each received notification is distributed in it's own temporary thread. Note that despite using boost::thread_group there will be a substantial cost in creating worker threads sometimes.

Because the observers are stored as weak references, there is no need to unregister an observer before it is destroyed.


Member Typedef Documentation

template<typename Notification, typename Observer_t, typename Observed_t>
typedef Notifier<Notification, Observer_t, Observed_t> ark::AsyncNotifier< Notification, Observer_t, Observed_t >::note_super [private]
 

template<typename Notification, typename Observer_t, typename Observed_t>
typedef boost::mutex::scoped_lock ark::AsyncNotifier< Notification, Observer_t, Observed_t >::scoped_lock [protected]
 

Reimplemented from ark::AsyncConsumer< Notification >.

template<typename Notification, typename Observer_t, typename Observed_t>
typedef AsyncConsumer<Notification>::SourceQueue ark::AsyncNotifier< Notification, Observer_t, Observed_t >::SourceQueue [private]
 

Reimplemented from ark::AsyncConsumer< Notification >.


Member Function Documentation

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::_dispatchNotification Notification  note  )  [inline, private]
 

Runs in own thread.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::addObserver boost::shared_ptr< Observer_t > const &  obj,
Notification const &  note
[inline, virtual]
 

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::addObserver boost::shared_ptr< Observer_t > const &  obj,
Observed_t const &  obs
[inline, virtual]
 

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::addObserver boost::shared_ptr< Observer_t > const &  obj  )  [inline, virtual]
 

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::consume Notification &  note,
SourceQueue q
[inline]
 

consume Override of AsyncConsumer, distributes the notification to observers, or schedules delivery on a worker thread.

Parameters:
The notification to distribute

template<typename Notification, typename Observer_t, typename Observed_t>
bool ark::AsyncNotifier< Notification, Observer_t, Observed_t >::isMultithreaded  )  const [inline]
 

isMultithreaded

Returns:
True if each notification is delivered in a dedicated thread
See also:
setMultithreaded()

template<typename Notification, typename Observer_t, typename Observed_t>
bool ark::AsyncNotifier< Notification, Observer_t, Observed_t >::isObserving boost::shared_ptr< Observer_t > const &  obj  )  [inline]
 

isObserving

Returns:
True if the passed object is registered with this notifier

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::receiveNotification Notification const &  note  )  [inline, virtual]
 

receiveNotification Override of Observer_t sends the notification to all registered observers.

Parameters:
note The notification to send

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::removeObserver boost::shared_ptr< Observer_t > &  obj,
Notification const &  note
[inline, virtual]
 

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::removeObserver boost::shared_ptr< Observer_t > &  obj,
Observed_t const &  observed
[inline, virtual]
 

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::removeObserver boost::shared_ptr< Observer_t > &  obj  )  [inline, virtual]
 

removeObserver Removes an observer from this notifier. All registrations will be removed.

Parameters:
A shared pointer to the observer to remove

Reimplemented from ark::Notifier< Notification, Observer_t, Observed_t >.

template<typename Notification, typename Observer_t, typename Observed_t>
void ark::AsyncNotifier< Notification, Observer_t, Observed_t >::setMultithreaded bool  mt  )  [inline]
 

setMultithreaded Sets whether the notifier should deliver each notification in it's own thread or not.

Parameters:
mt True to deliver notifications in dedicated thread.


Member Data Documentation

template<typename Notification, typename Observer_t, typename Observed_t>
boost::mutex ark::AsyncNotifier< Notification, Observer_t, Observed_t >::_allMutex [private]
 

template<typename Notification, typename Observer_t, typename Observed_t>
boost::thread_group ark::AsyncNotifier< Notification, Observer_t, Observed_t >::_distributors [private]
 

template<typename Notification, typename Observer_t, typename Observed_t>
Atomic<bool> ark::AsyncNotifier< Notification, Observer_t, Observed_t >::_multithreads [private]
 


The documentation for this class was generated from the following file:
Generated on Tue Sep 6 14:54:39 2005 for Arkonnekt Sound by  doxygen 1.4.4