SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
sdrbase
util
messagequeue.cpp
Go to the documentation of this file.
1
// Copyright (C) 2015 F4EXB //
3
// written by Edouard Griffiths //
4
// //
5
// This program is free software; you can redistribute it and/or modify //
6
// it under the terms of the GNU General Public License as published by //
7
// the Free Software Foundation as version 3 of the License, or //
8
// (at your option) any later version. //
9
// //
10
// This program is distributed in the hope that it will be useful, //
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13
// GNU General Public License V3 for more details. //
14
// //
15
// You should have received a copy of the GNU General Public License //
16
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
18
19
#include <QDebug>
20
#include <QMutexLocker>
21
#include "
util/messagequeue.h
"
22
#include "
util/message.h
"
23
24
MessageQueue::MessageQueue
(QObject* parent) :
25
QObject(parent),
26
m_lock(QMutex::Recursive),
27
m_queue()
28
{
29
}
30
31
MessageQueue::~MessageQueue
()
32
{
33
Message
* message;
34
35
while
((message =
pop
()) != 0)
36
{
37
qDebug() <<
"MessageQueue::~MessageQueue: message: "
<< message->
getIdentifier
() <<
" was still in queue"
;
38
delete
message;
39
}
40
}
41
42
void
MessageQueue::push
(
Message
* message,
bool
emitSignal)
43
{
44
if
(message)
45
{
46
m_lock
.lock();
47
m_queue
.append(message);
48
m_lock
.unlock();
49
}
50
51
if
(emitSignal)
52
{
53
emit
messageEnqueued
();
54
}
55
}
56
57
Message
*
MessageQueue::pop
()
58
{
59
QMutexLocker locker(&
m_lock
);
60
61
if
(
m_queue
.isEmpty())
62
{
63
return
0;
64
}
65
else
66
{
67
return
m_queue
.takeFirst();
68
}
69
}
70
71
int
MessageQueue::size
()
72
{
73
QMutexLocker locker(&
m_lock
);
74
75
return
m_queue
.size();
76
}
77
78
void
MessageQueue::clear
()
79
{
80
QMutexLocker locker(&
m_lock
);
81
82
while
(!
m_queue
.isEmpty()) {
83
delete
m_queue
.takeFirst();
84
}
85
}
MessageQueue::pop
Message * pop()
Pop message from queue.
Definition:
messagequeue.cpp:57
MessageQueue::push
void push(Message *message, bool emitSignal=true)
Push message onto queue.
Definition:
messagequeue.cpp:42
MessageQueue::size
int size()
Returns queue size.
Definition:
messagequeue.cpp:71
Message
Definition:
message.h:25
messagequeue.h
MessageQueue::clear
void clear()
Empty queue.
Definition:
messagequeue.cpp:78
message.h
MessageQueue::m_queue
QQueue< Message * > m_queue
Definition:
messagequeue.h:47
MessageQueue::~MessageQueue
~MessageQueue()
Definition:
messagequeue.cpp:31
MessageQueue::MessageQueue
MessageQueue(QObject *parent=NULL)
Definition:
messagequeue.cpp:24
MessageQueue::messageEnqueued
void messageEnqueued()
Message::getIdentifier
virtual const char * getIdentifier() const
Definition:
message.cpp:35
MessageQueue::m_lock
QMutex m_lock
Definition:
messagequeue.h:46
Generated on Fri Aug 2 2019 17:56:33 for SDRAngel by
1.8.13