1 #ifndef __SDR_QUEUE_HH__
2 #define __SDR_QUEUE_HH__
127 void addIdle(T *instance,
void (T::*
function)(
void)) {
134 std::list<DelegateInterface *>::iterator item =
_idle.begin();
135 while (item !=
_idle.end()) {
136 if ( (*item)->instance() == ((
void *)instance)) {
137 item =
_idle.erase(item);
146 void addStart(T *instance,
void (T::*
function)(
void)) {
153 std::list<DelegateInterface *>::iterator item =
_onStart.begin();
155 if ( (*item)->instance() == ((
void *)instance)) {
165 void addStop(T *instance,
void (T::*
function)(
void)) {
172 std::list<DelegateInterface *>::iterator item =
_onStop.begin();
173 while (item !=
_onStop.end()) {
174 if ( (*item)->instance() == ((
void *)instance)) {
205 std::list<DelegateInterface *>
_idle;
213 static Queue *_instance;
215 static void *__thread_start(
void *ptr);
220 #endif // __SDR_QUEUE_HH__
std::list< DelegateInterface * > _onStop
Stop event callbacks.
Definition: queue.hh:209
SinkBase * _sink
The destination.
Definition: queue.hh:85
std::list< Message > _queue
The message queue.
Definition: queue.hh:203
Base class of all buffers, represents an untyped array of bytes.
Definition: buffer.hh:32
void send(const RawBuffer &buffer, SinkBase *sink, bool allow_overwrite=false)
Adds a buffer and its receiver to the queue.
Definition: queue.cc:36
The internal used message type.
Definition: queue.hh:57
void wait()
Wait for the queue to exit the queue loop.
Definition: queue.cc:70
virtual void * instance()=0
Returns the instance of the delegate.
pthread_mutex_t _queue_lock
The queue mutex.
Definition: queue.hh:198
Specific delegate to a method of an object .
Definition: queue.hh:27
bool isStopped() const
Returns true if the queue loop is stopped.
Definition: queue.cc:46
bool isRunning() const
Returns true if the queue loop is running.
Definition: queue.cc:51
Delegate(T *instance, void(T::*func)(void))
Constructs a delegate to the method func of the instance instance.
Definition: queue.hh:31
void _signalStop()
Emits the stop signal.
Definition: queue.cc:144
std::list< DelegateInterface * > _idle
Idle event callbacks.
Definition: queue.hh:205
Definition: autocast.hh:8
Central message queue (singleton).
Definition: queue.hh:53
T * _instance
The instance.
Definition: queue.hh:41
void stop()
Signals the queue to stop processing.
Definition: queue.cc:64
virtual void * instance()
Returns the instance of the delegate.
Definition: queue.hh:37
Message(const Message &other)
Copy constructor.
Definition: queue.hh:63
void addIdle(T *instance, void(T::*function)(void))
Adds a callback to the idle event.
Definition: queue.hh:127
const RawBuffer & buffer() const
Returns the buffer of the message.
Definition: queue.hh:73
bool allowOverwrite() const
If true, the sender allows to overwrite the content of the buffer.
Definition: queue.hh:79
pthread_t _thread
If _parallel is true, the thread of the queue loop.
Definition: queue.hh:196
void addStop(T *instance, void(T::*function)(void))
Adds a callback to the stop event.
Definition: queue.hh:165
const Message & operator=(const Message &other)
Assignment operator.
Definition: queue.hh:66
void(T::* _function)(void)
The method.
Definition: queue.hh:43
virtual ~Queue()
Destructor.
Definition: queue.cc:30
Interface of a delegate.
Definition: queue.hh:17
SinkBase * sink() const
Returns the destination of the message.
Definition: queue.hh:77
void start()
Enters the queue loop, if parallel=true was passed to get, exec will execute the queue loop in a sepa...
Definition: queue.cc:57
void remStop(T *instance)
Removes all callbacks of the given instance from the stop signal.
Definition: queue.hh:171
virtual ~Delegate()
Destructor.
Definition: queue.hh:33
RawBuffer & buffer()
Returns the buffer of the message.
Definition: queue.hh:75
Basic interface of all Sinks.
Definition: node.hh:174
void remIdle(T *instance)
Removes all callbacks of the given instance from the idle signal.
Definition: queue.hh:133
std::list< DelegateInterface * > _onStart
Start event callbacks.
Definition: queue.hh:207
virtual void operator()()=0
Call back interface.
void _main()
The actual queue loop.
Definition: queue.cc:84
Message(const RawBuffer &buffer, SinkBase *sink, bool allow_overwrite)
Constructor.
Definition: queue.hh:60
bool _running
While this is true, the queue loop is executed.
Definition: queue.hh:194
bool _allow_overwrite
If true, the sender allows to overwrite the buffer.
Definition: queue.hh:87
virtual void operator()()
Callback, simply calls the method of the instance given to the constructor.
Definition: queue.hh:35
void _signalIdle()
Emits the idle signal.
Definition: queue.cc:128
pthread_cond_t _queue_cond
The queue condition.
Definition: queue.hh:200
void _signalStart()
Emits the start signal.
Definition: queue.cc:136
void remStart(T *instance)
Removes all callbacks of the given instance from the start signal.
Definition: queue.hh:152
Queue()
Hidden constructor, use get to get the singleton instance.
Definition: queue.cc:22
void addStart(T *instance, void(T::*function)(void))
Adds a callback to the start event.
Definition: queue.hh:146
RawBuffer _buffer
The buffer being send.
Definition: queue.hh:83