Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ThreadedMessageQueue< T > Class Template Reference

Provides a mechanism for exchanging messages between threads. More...

#include <ThreadedMessageQueue.h>

Inheritance diagram for ThreadedMessageQueue< T >:

Detailed Description

template<class T>
class ThreadedMessageQueue< T >

Provides a mechanism for exchanging messages between threads.

Receivers are responsible for message cleanup/deletion.

Definition at line 13 of file ThreadedMessageQueue.h.

List of all members.

Classes

class  ReceiverThread
 Pulls messages out of the queue and gives them to the specified callback. More...
class  ReceiverThreadBase
 Holds controller flags for the receiver thread to indicate exit conditions. More...

Public Member Functions

 ThreadedMessageQueue ()
 Constructor.
 ~ThreadedMessageQueue ()
 Destructor, calls finishCallback().
void send (const T &msg)
 Adds a message to the queue.
template<class F >
void for_each (const F &f)
 Applies the specified predicate to each of the messages (you can modify the queue value itself via pass-by-reference).
template<class F >
void remove (const F &f)
 Applies the specified predicate to each of the message, removing those for which the predicate returns true.
void remove (const T e)
 Removes an element from the queue.
size_t size () const
 Returns number of messages in msgs.
void clear ()
 Clears any backlog.
const T & front () const
 Returns the next message (does not remove from the queue), blocking until available.
void pop ()
 Removes the front message, if any.
template<typename F , typename C >
void spawnCallback (F fn, C &cl)
 Spawns a thread to trigger a class member callback with each message - only a single receiver is supported, so this replaces any previous receiver.
void stopCallback ()
 Sends a thread cancellation to the receiver thread to halt processing.
void finishCallback ()
 Sets a flag to exit the receiver thread at the completion of the current callback.
void finishQueue ()
 Sets a flag that when the receiver gets to the end of the queue, it will exit.

Public Attributes

Thread::Lock lock
 provides mutual exclusion on msgs operations and signal reception
Thread::Condition signal
 connects notification of send() in receiver
std::list< T > msgs
 unprocessed messages
ReceiverThreadBasereceiver
 currently only a single receiver is supported

Private Member Functions

 ThreadedMessageQueue (const ThreadedMessageQueue &o)
 Do not call.
ThreadedMessageQueueoperator= (const ThreadedMessageQueue &o)
 Do not call.

Constructor & Destructor Documentation

template<class T>
ThreadedMessageQueue< T >::ThreadedMessageQueue (  ) 

Constructor.

Definition at line 16 of file ThreadedMessageQueue.h.

template<class T>
ThreadedMessageQueue< T >::~ThreadedMessageQueue (  ) 

Destructor, calls finishCallback().

Definition at line 19 of file ThreadedMessageQueue.h.

template<class T>
ThreadedMessageQueue< T >::ThreadedMessageQueue ( const ThreadedMessageQueue< T > &  o  )  [private]

Do not call.


Member Function Documentation

template<class T>
void ThreadedMessageQueue< T >::clear (  ) 

Clears any backlog.

Definition at line 37 of file ThreadedMessageQueue.h.

template<class T>
void ThreadedMessageQueue< T >::finishCallback (  ) 

Sets a flag to exit the receiver thread at the completion of the current callback.

If no callback is active, cancels the receiver immediately -- doesn't wait for another message first

Definition at line 79 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< EventBase * >::~ThreadedMessageQueue().

template<class T>
void ThreadedMessageQueue< T >::finishQueue (  ) 

Sets a flag that when the receiver gets to the end of the queue, it will exit.

If the receiver is already blocking at the end of the queue, stops the thread now

Definition at line 95 of file ThreadedMessageQueue.h.

template<class T>
template<class F >
void ThreadedMessageQueue< T >::for_each ( const F &  f  ) 

Applies the specified predicate to each of the messages (you can modify the queue value itself via pass-by-reference).

Definition at line 25 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< EventBase * >::for_each().

template<class T>
const T& ThreadedMessageQueue< T >::front (  )  const

Returns the next message (does not remove from the queue), blocking until available.

Definition at line 40 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< T >::ReceiverThread< F, C >::run().

template<class T>
ThreadedMessageQueue& ThreadedMessageQueue< T >::operator= ( const ThreadedMessageQueue< T > &  o  )  [private]

Do not call.

template<class T>
void ThreadedMessageQueue< T >::pop (  ) 

Removes the front message, if any.

Definition at line 48 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< T >::ReceiverThread< F, C >::run().

template<class T>
void ThreadedMessageQueue< T >::remove ( const T  e  ) 

Removes an element from the queue.

Definition at line 31 of file ThreadedMessageQueue.h.

template<class T>
template<class F >
void ThreadedMessageQueue< T >::remove ( const F &  f  ) 

Applies the specified predicate to each of the message, removing those for which the predicate returns true.

Definition at line 28 of file ThreadedMessageQueue.h.

Referenced by EventRouter::requeueEvent().

template<class T>
void ThreadedMessageQueue< T >::send ( const T &  msg  ) 

Adds a message to the queue.

Definition at line 22 of file ThreadedMessageQueue.h.

Referenced by EventRouter::queueEvent().

template<class T>
size_t ThreadedMessageQueue< T >::size (  )  const

Returns number of messages in msgs.

Definition at line 34 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< T >::ReceiverThread< F, C >::run().

template<class T>
template<typename F , typename C >
void ThreadedMessageQueue< T >::spawnCallback ( fn,
C &  cl 
)

Spawns a thread to trigger a class member callback with each message - only a single receiver is supported, so this replaces any previous receiver.

Definition at line 52 of file ThreadedMessageQueue.h.

template<class T>
void ThreadedMessageQueue< T >::stopCallback (  ) 

Sends a thread cancellation to the receiver thread to halt processing.

Definition at line 59 of file ThreadedMessageQueue.h.

Referenced by ThreadedMessageQueue< EventBase * >::spawnCallback().


Member Data Documentation


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:17 2016 by Doxygen 1.6.3