From 9f4eeda7c99b4400feb9c9c2c6a5ff14d3212b1b Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 22 Apr 2017 10:45:33 +0200 Subject: [PATCH] LimeSDR output: implemented common thread interface for input and output plugins to be able to start/stop thread from each other --- .../limesdroutput/limesdroutput.cpp | 40 +++++++++---------- .../limesdroutput/limesdroutputthread.h | 7 ++-- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/plugins/samplesink/limesdroutput/limesdroutput.cpp b/plugins/samplesink/limesdroutput/limesdroutput.cpp index e046dbf45..b010b0624 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutput.cpp @@ -96,7 +96,7 @@ bool LimeSDROutput::openDevice() busyChannels[buddyShared->m_channel] = 1; if (buddyShared->m_thread) { // suspend Tx buddy's thread for proper stream allocation later - ((LimeSDROutputThread *) buddyShared->m_thread)->stopWork(); + buddyShared->m_thread->stopWork(); } } @@ -187,7 +187,7 @@ bool LimeSDROutput::openDevice() DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); if (buddyShared->m_thread) { - ((LimeSDROutputThread *) buddyShared->m_thread)->startWork(); + buddyShared->m_thread->startWork(); } } @@ -208,7 +208,7 @@ void LimeSDROutput::closeDevice() DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); if (buddyShared->m_thread) { - ((LimeSDROutputThread *) buddyShared->m_thread)->stopWork(); + buddyShared->m_thread->stopWork(); } } @@ -233,7 +233,7 @@ void LimeSDROutput::closeDevice() DeviceLimeSDRShared *buddyShared = (DeviceLimeSDRShared *) buddy->getBuddySharedPtr(); if (buddyShared->m_thread) { - ((LimeSDROutputThread *) buddyShared->m_thread)->startWork(); + buddyShared->m_thread->startWork(); } } @@ -272,7 +272,7 @@ bool LimeSDROutput::start() m_limeSDROutputThread->startWork(); - m_deviceShared.m_thread = (void *) m_limeSDROutputThread; + m_deviceShared.m_thread = m_limeSDROutputThread; m_running = true; return true; @@ -459,9 +459,9 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo for (; itSource != sourceBuddies.end(); ++itSource) { DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSource)->getBuddySharedPtr(); - if (buddySharedPtr->m_thread) - { - ((LimeSDRInputThread *) buddySharedPtr->m_thread)->stopWork(); + + if (buddySharedPtr->m_thread) { + buddySharedPtr->m_thread->stopWork(); } } @@ -471,9 +471,9 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo for (; itSink != sinkBuddies.end(); ++itSink) { DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); - if (buddySharedPtr->m_thread) - { - ((LimeSDROutputThread *) buddySharedPtr->m_thread)->stopWork(); + + if (buddySharedPtr->m_thread) { + buddySharedPtr->m_thread->stopWork(); } } @@ -489,9 +489,9 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo for (; itSink != sinkBuddies.end(); ++itSink) { DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); - if (buddySharedPtr->m_thread) - { - ((LimeSDROutputThread *) buddySharedPtr->m_thread)->stopWork(); + + if (buddySharedPtr->m_thread) { + buddySharedPtr->m_thread->stopWork(); } } @@ -714,9 +714,9 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo for (; itSink != sinkBuddies.end(); ++itSink) { DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); - if (buddySharedPtr->m_thread) - { - ((LimeSDROutputThread *) buddySharedPtr->m_thread)->startWork(); + + if (buddySharedPtr->m_thread) { + buddySharedPtr->m_thread->startWork(); } } @@ -732,9 +732,9 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo for (; itSink != sinkBuddies.end(); ++itSink) { DeviceLimeSDRShared *buddySharedPtr = (DeviceLimeSDRShared *) (*itSink)->getBuddySharedPtr(); - if (buddySharedPtr->m_thread) - { - ((LimeSDROutputThread *) buddySharedPtr->m_thread)->startWork(); + + if (buddySharedPtr->m_thread) { + buddySharedPtr->m_thread->startWork(); } } diff --git a/plugins/samplesink/limesdroutput/limesdroutputthread.h b/plugins/samplesink/limesdroutput/limesdroutputthread.h index b1ac37373..b611ac883 100644 --- a/plugins/samplesink/limesdroutput/limesdroutputthread.h +++ b/plugins/samplesink/limesdroutput/limesdroutputthread.h @@ -25,10 +25,11 @@ #include "dsp/samplesourcefifo.h" #include "dsp/interpolators.h" +#include "limesdr/devicelimesdrshared.h" #define LIMESDROUTPUT_BLOCKSIZE (1<<14) //complex samples per buffer ~10k (16k) -class LimeSDROutputThread : public QThread +class LimeSDROutputThread : public QThread, public DeviceLimeSDRShared::ThreadInterface { Q_OBJECT @@ -36,8 +37,8 @@ public: LimeSDROutputThread(lms_stream_t* stream, SampleSourceFifo* sampleFifo, QObject* parent = 0); ~LimeSDROutputThread(); - void startWork(); - void stopWork(); + virtual void startWork(); + virtual void stopWork(); void setLog2Interpolation(unsigned int log2_ioterp); void setFcPos(int fcPos);