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.
localsourcethread.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 Edouard Griffiths, F4EXB. //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include "dsp/samplesourcefifo.h"
19 
20 #include "localsourcethread.h"
21 
23 
25  QThread(parent),
26  m_running(false),
27  m_sampleFifo(0)
28 {
29  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
30 }
31 
33 {
34  qDebug("LocalSourceThread::~LocalSourceThread");
35 }
36 
38 {
39  MsgStartStop *msg = MsgStartStop::create(start);
41 }
42 
44 {
45  m_sampleFifo = sampleFifo;
46 }
47 
48 void LocalSourceThread::pullSamples(unsigned int count)
49 {
50  SampleVector::iterator beginRead;
51  m_sampleFifo->readAdvance(beginRead, count);
53 }
54 
56 {
57  qDebug("LocalSourceThread::startWork");
58  m_startWaitMutex.lock();
59  start();
60 
61  while(!m_running) {
62  m_startWaiter.wait(&m_startWaitMutex, 100);
63  }
64 
65  m_startWaitMutex.unlock();
66 }
67 
69 {
70  qDebug("LocalSourceThread::stopWork");
71  m_running = false;
72  wait();
73 }
74 
76 {
77  qDebug("LocalSinkThread::run: begin");
78  m_running = true;
79  m_startWaiter.wakeAll();
80 
81  while (m_running)
82  {
83  sleep(1); // Do nothing as everything is in the data handler (dequeuer)
84  }
85 
86  m_running = false;
87  qDebug("LocalSinkThread::run: end");
88 }
89 
91 {
92  Message* message;
93 
94  while ((message = m_inputMessageQueue.pop()) != 0)
95  {
96  if (MsgStartStop::match(*message))
97  {
98  MsgStartStop* notif = (MsgStartStop*) message;
99  qDebug("LocalSourceThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
100 
101  if (notif->getStartStop()) {
102  startWork();
103  } else {
104  stopWork();
105  }
106 
107  delete message;
108  }
109  }
110 }
Message * pop()
Pop message from queue.
void pullSamples(unsigned int count)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgStartStop * create(bool startStop)
int getIteratorOffset(const SampleVector::iterator &iterator)
MessageQueue m_inputMessageQueue
void startStop(bool start)
void setSampleFifo(SampleSourceFifo *sampleFifo)
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
Definition: message.h:52
QWaitCondition m_startWaiter
static bool match(const Message *message)
Definition: message.cpp:45
void readAdvance(SampleVector::iterator &readUntil, unsigned int nbSamples)
volatile bool m_running
SampleSourceFifo * m_sampleFifo
void samplesAvailable(int offset)