| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 Edouard Griffiths, F4EXB.                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | // Remtoe sink channel (Rx) data blocks queue                                    //
 | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | // SDRangel can serve as a remote SDR front end that handles the interface       //
 | 
					
						
							|  |  |  | // with a physical device and sends or receives the I/Q samples stream via UDP   //
 | 
					
						
							|  |  |  | // to or from another SDRangel instance or any program implementing the same     //
 | 
					
						
							|  |  |  | // protocol. The remote SDRangel is controlled via its Web REST API.             //
 | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | #include <channel/remotedatablock.h>
 | 
					
						
							|  |  |  | #include <channel/remotedataqueue.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QMutexLocker>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | RemoteDataQueue::RemoteDataQueue(QObject* parent) : | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | 	QObject(parent), | 
					
						
							|  |  |  | 	m_lock(QMutex::Recursive), | 
					
						
							|  |  |  | 	m_queue() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | RemoteDataQueue::~RemoteDataQueue() | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | 	RemoteDataBlock* data; | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while ((data = pop()) != 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-03 01:52:11 +01:00
										 |  |  | 		qDebug() << "RemoteDataQueue::~RemoteDataQueue: data block was still in queue"; | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | 		delete data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | void RemoteDataQueue::push(RemoteDataBlock* data, bool emitSignal) | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (data) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_lock.lock(); | 
					
						
							|  |  |  | 		m_queue.append(data); | 
					
						
							|  |  |  | 		m_lock.unlock(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (emitSignal) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		emit dataBlockEnqueued(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | RemoteDataBlock* RemoteDataQueue::pop() | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker locker(&m_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (m_queue.isEmpty()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_queue.takeFirst(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | int RemoteDataQueue::size() | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker locker(&m_lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return m_queue.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-02 22:58:42 +01:00
										 |  |  | void RemoteDataQueue::clear() | 
					
						
							| 
									
										
										
										
											2018-08-20 14:05:27 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker locker(&m_lock); | 
					
						
							|  |  |  | 	m_queue.clear(); | 
					
						
							|  |  |  | } |