libsdr
0.1.0
A simple SDR library
|
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 Queue & | get () |
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... | |
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
.
|
protected |
Hidden constructor, use get
to get the singleton instance.
|
virtual |
Destructor.
|
protected |
The actual queue loop.
|
protected |
Emits the idle signal.
|
protected |
Emits the start signal.
|
protected |
Emits the stop signal.
|
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.
|
inline |
Adds a callback to the start event.
The method gets called once the queue loop is started.
|
inline |
Adds a callback to the stop event.
The method gets called once the queue loop is stopped.
|
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.
|
inline |
Removes all callbacks of the given instance from the idle signal.
|
inline |
Removes all callbacks of the given instance from the start signal.
|
inline |
Removes all callbacks of the given instance from the stop signal.
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.
|
protected |
Idle event callbacks.
|
protected |
Start event callbacks.
|
protected |
Stop event callbacks.
|
protected |
The message queue.
|
protected |
The queue condition.
|
protected |
The queue mutex.
|
protected |
While this is true, the queue loop is executed.
|
protected |
If _parallel
is true, the thread of the queue loop.