libsdr  0.1.0
A simple SDR library
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
sdr::Queue Class Reference

Central message queue (singleton). More...

#include <queue.hh>

Classes

class  Message
 The internal used message type. More...
 

Public Member Functions

virtual ~Queue ()
 Destructor. More...
 
void send (const RawBuffer &buffer, SinkBase *sink, bool allow_overwrite=false)
 Adds a buffer and its receiver to the queue. More...
 
void start ()
 Enters the queue loop, if parallel=true was passed to get, exec will execute the queue loop in a separate thread and returns immediately. More...
 
void stop ()
 Signals the queue to stop processing. More...
 
void wait ()
 Wait for the queue to exit the queue loop. More...
 
bool isStopped () const
 Returns true if the queue loop is stopped. More...
 
bool isRunning () const
 Returns true if the queue loop is running. More...
 
template<class T >
void addIdle (T *instance, void(T::*function)(void))
 Adds a callback to the idle event. More...
 
template<class T >
void remIdle (T *instance)
 Removes all callbacks of the given instance from the idle signal. More...
 
template<class T >
void addStart (T *instance, void(T::*function)(void))
 Adds a callback to the start event. More...
 
template<class T >
void remStart (T *instance)
 Removes all callbacks of the given instance from the start signal. More...
 
template<class T >
void addStop (T *instance, void(T::*function)(void))
 Adds a callback to the stop event. More...
 
template<class T >
void remStop (T *instance)
 Removes all callbacks of the given instance from the stop signal. More...
 

Static Public Member Functions

static Queueget ()
 Get a reference to the global instance of the queue. More...
 

Protected Member Functions

 Queue ()
 Hidden constructor, use get to get the singleton instance. More...
 
void _main ()
 The actual queue loop. More...
 
void _signalIdle ()
 Emits the idle signal. More...
 
void _signalStart ()
 Emits the start signal. More...
 
void _signalStop ()
 Emits the stop signal. More...
 

Protected Attributes

bool _running
 While this is true, the queue loop is executed. More...
 
pthread_t _thread
 If _parallel is true, the thread of the queue loop. More...
 
pthread_mutex_t _queue_lock
 The queue mutex. More...
 
pthread_cond_t _queue_cond
 The queue condition. More...
 
std::list< Message_queue
 The message queue. More...
 
std::list< DelegateInterface * > _idle
 Idle event callbacks. More...
 
std::list< DelegateInterface * > _onStart
 Start event callbacks. More...
 
std::list< DelegateInterface * > _onStop
 Stop event callbacks. More...
 

Detailed Description

Central message queue (singleton).

Must be created before any other SDR object is constructed. The queue collects all buffers for processing and routes them to their destination. The queue loop can either be run in a separate thread by passing parallel=true to the factory method get. In this case, the exec method will return immediately. Otherwise, the queue loop will be executed in the thread calling exec which blocks until the queue is stopped by a call to stop.

Constructor & Destructor Documentation

Queue::Queue ( )
protected

Hidden constructor, use get to get the singleton instance.

Queue::~Queue ( )
virtual

Destructor.

Member Function Documentation

void Queue::_main ( )
protected

The actual queue loop.

void Queue::_signalIdle ( )
protected

Emits the idle signal.

void Queue::_signalStart ( )
protected

Emits the start signal.

void Queue::_signalStop ( )
protected

Emits the stop signal.

template<class T >
void sdr::Queue::addIdle ( T *  instance,
void(T::*)(void)  function 
)
inline

Adds a callback to the idle event.

The method gets called repeatedly while the queue looop is idle, means that there are no messages to be processed. This can be used to trigger an input source to read more data.

template<class T >
void sdr::Queue::addStart ( T *  instance,
void(T::*)(void)  function 
)
inline

Adds a callback to the start event.

The method gets called once the queue loop is started.

template<class T >
void sdr::Queue::addStop ( T *  instance,
void(T::*)(void)  function 
)
inline

Adds a callback to the stop event.

The method gets called once the queue loop is stopped.

Queue & Queue::get ( )
static

Get a reference to the global instance of the queue.

If parallel is true, the queue will be constructed in parallel mode, means the queue loop will be executed in a separate thread. Please note that this option is only used in the first call, when the singleton instance of the queue is created.

bool Queue::isRunning ( ) const

Returns true if the queue loop is running.

bool Queue::isStopped ( ) const

Returns true if the queue loop is stopped.

template<class T >
void sdr::Queue::remIdle ( T *  instance)
inline

Removes all callbacks of the given instance from the idle signal.

template<class T >
void sdr::Queue::remStart ( T *  instance)
inline

Removes all callbacks of the given instance from the start signal.

template<class T >
void sdr::Queue::remStop ( T *  instance)
inline

Removes all callbacks of the given instance from the stop signal.

void Queue::send ( const RawBuffer buffer,
SinkBase sink,
bool  allow_overwrite = false 
)

Adds a buffer and its receiver to the queue.

If allow_overwrite is true, the the receiver is allowed to overwrite the content of the buffer.

void Queue::start ( )

Enters the queue loop, if parallel=true was passed to get, exec will execute the queue loop in a separate thread and returns immediately.

Otherwise, exec will block until the queue is stopped.

void Queue::stop ( )

Signals the queue to stop processing.

void Queue::wait ( )

Wait for the queue to exit the queue loop.

Member Data Documentation

std::list<DelegateInterface *> sdr::Queue::_idle
protected

Idle event callbacks.

std::list<DelegateInterface *> sdr::Queue::_onStart
protected

Start event callbacks.

std::list<DelegateInterface *> sdr::Queue::_onStop
protected

Stop event callbacks.

std::list<Message> sdr::Queue::_queue
protected

The message queue.

pthread_cond_t sdr::Queue::_queue_cond
protected

The queue condition.

pthread_mutex_t sdr::Queue::_queue_lock
protected

The queue mutex.

bool sdr::Queue::_running
protected

While this is true, the queue loop is executed.

pthread_t sdr::Queue::_thread
protected

If _parallel is true, the thread of the queue loop.


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