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.
remotedataqueue.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB. //
3 // //
4 // Remtoe sink channel (Rx) data blocks queue //
5 // //
6 // SDRangel can serve as a remote SDR front end that handles the interface //
7 // with a physical device and sends or receives the I/Q samples stream via UDP //
8 // to or from another SDRangel instance or any program implementing the same //
9 // protocol. The remote SDRangel is controlled via its Web REST API. //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation as version 3 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License V3 for more details. //
20 // //
21 // You should have received a copy of the GNU General Public License //
22 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
24 
27 #include <QDebug>
28 #include <QMutexLocker>
29 
31  QObject(parent),
32  m_lock(QMutex::Recursive),
33  m_queue()
34 {
35 }
36 
38 {
39  RemoteDataBlock* data;
40 
41  while ((data = pop()) != 0)
42  {
43  qDebug() << "RemoteDataQueue::~RemoteDataQueue: data block was still in queue";
44  delete data;
45  }
46 }
47 
48 void RemoteDataQueue::push(RemoteDataBlock* data, bool emitSignal)
49 {
50  if (data)
51  {
52  m_lock.lock();
53  m_queue.append(data);
54  m_lock.unlock();
55  }
56 
57  if (emitSignal)
58  {
59  emit dataBlockEnqueued();
60  }
61 }
62 
64 {
65  QMutexLocker locker(&m_lock);
66 
67  if (m_queue.isEmpty())
68  {
69  return 0;
70  }
71  else
72  {
73  return m_queue.takeFirst();
74  }
75 }
76 
78 {
79  QMutexLocker locker(&m_lock);
80 
81  return m_queue.size();
82 }
83 
85 {
86  QMutexLocker locker(&m_lock);
87  m_queue.clear();
88 }
RemoteDataBlock * pop()
Pop message from queue.
QQueue< RemoteDataBlock * > m_queue
void dataBlockEnqueued()
void push(RemoteDataBlock *dataBlock, bool emitSignal=true)
Push daa block onto queue.
void clear()
Empty queue.
int size()
Returns queue size.
RemoteDataQueue(QObject *parent=NULL)