Skip to content

Commit

Permalink
Merge pull request #2274 from srcejon/freq_scanner
Browse files Browse the repository at this point in the history
MainWindow: Add FSMs to avoid blocking on GUI Thread
  • Loading branch information
f4exb authored Oct 12, 2024
2 parents f24600b + e3ec875 commit 4dcf050
Show file tree
Hide file tree
Showing 14 changed files with 1,317 additions and 605 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ if (BUILD_GUI)
QuickWidgets
Svg
SvgWidgets
StateMachine
OPTIONAL_COMPONENTS
WebEngineQuick
WebEngineCore
Expand Down
4 changes: 4 additions & 0 deletions sdrbase/dsp/dspdevicemimoengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message)
else if (DSPAcquisitionStop::match(message))
{
setStateRx(gotoIdle(0));
emit acquisitionStopped();
return true;
}
else if (DSPGenerationInit::match(message))
Expand All @@ -1053,11 +1054,13 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message)
else if (DSPGenerationStop::match(message))
{
setStateTx(gotoIdle(1));
emit generationStopped();
return true;
}
else if (SetSampleMIMO::match(message)) {
const auto& cmd = (const SetSampleMIMO&) message;
handleSetMIMO(cmd.getSampleMIMO());
emit sampleSet();
return true;
}
else if (AddBasebandSampleSink::match(message))
Expand Down Expand Up @@ -1194,6 +1197,7 @@ bool DSPDeviceMIMOEngine::handleMessage(const Message& message)
BasebandSampleSink* spectrumSink = msg.getSampleSink();
spectrumSink->stop();
m_spectrumSink = nullptr;
emit spectrumSinkRemoved();
return true;
}
else if (SetSpectrumSinkInput::match(message))
Expand Down
5 changes: 5 additions & 0 deletions sdrbase/dsp/dspdevicemimoengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ private slots:

signals:
void stateChanged();

void acquisitionStopped();
void sampleSet();
void generationStopped();
void spectrumSinkRemoved();
};

#endif // SDRBASE_DSP_DSPDEVICEMIMOENGINE_H_
3 changes: 3 additions & 0 deletions sdrbase/dsp/dspdevicesinkengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,14 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message)
else if (DSPGenerationStop::match(message))
{
setState(gotoIdle());
emit generationStopped();
return true;
}
else if (DSPSetSink::match(message))
{
const auto& cmd = (const DSPSetSink&) message;
handleSetSink(cmd.getSampleSink());
emit sampleSet();
return true;
}
else if (DSPRemoveSpectrumSink::match(message))
Expand All @@ -476,6 +478,7 @@ bool DSPDeviceSinkEngine::handleMessage(const Message& message)
}

m_spectrumSink = nullptr;
emit spectrumSinkRemoved();
return true;
}
else if (DSPAddBasebandSampleSource::match(message))
Expand Down
4 changes: 4 additions & 0 deletions sdrbase/dsp/dspdevicesinkengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ private slots:

signals:
void stateChanged();

void generationStopped();
void sampleSet();
void spectrumSinkRemoved();
};


Expand Down
8 changes: 7 additions & 1 deletion sdrbase/dsp/dspdevicesourceengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DSPDeviceSourceEngine::DSPDeviceSourceEngine(uint uid, QObject* parent) :

DSPDeviceSourceEngine::~DSPDeviceSourceEngine()
{
qDebug("DSPDeviceSourceEngine::~DSPDeviceSourceEngine");
qDebug("DSPDeviceSourceEngine::~DSPDeviceSourceEngine");
}

void DSPDeviceSourceEngine::setState(State state)
Expand Down Expand Up @@ -601,12 +601,15 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message)
else if (DSPAcquisitionStop::match(message))
{
setState(gotoIdle());
emit acquistionStopped();
return true;
}
else if (DSPSetSource::match(message))
{
auto cmd = (const DSPSetSource&) message;
handleSetSource(cmd.getSampleSource());
emit sampleSet();
return true;
}
else if (DSPAddBasebandSampleSink::match(message))
{
Expand All @@ -620,6 +623,7 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message)
if(m_state == State::StRunning) {
sink->start();
}
return true;
}
else if (DSPRemoveBasebandSampleSink::match(message))
{
Expand All @@ -631,6 +635,8 @@ bool DSPDeviceSourceEngine::handleMessage(const Message& message)
}

m_basebandSampleSinks.remove(sink);
emit sinkRemoved();
return true;
}

return false;
Expand Down
4 changes: 4 additions & 0 deletions sdrbase/dsp/dspdevicesourceengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ private slots:

signals:
void stateChanged();

void acquistionStopped();
void sampleSet();
void sinkRemoved();
};

#endif // INCLUDE_DSPDEVICEENGINE_H
35 changes: 9 additions & 26 deletions sdrbase/dsp/dspengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ DSPDeviceSourceEngine *DSPEngine::addDeviceSourceEngine()
m_deviceEngineReferences.push_back(DeviceEngineReference{0, m_deviceSourceEngines.back(), nullptr, nullptr, deviceThread});
deviceSourceEngine->moveToThread(deviceThread);

QObject::connect(
deviceThread,
&QThread::finished,
deviceSourceEngine,
&QObject::deleteLater
);
QObject::connect(
deviceThread,
&QThread::finished,
Expand Down Expand Up @@ -118,12 +112,6 @@ DSPDeviceSinkEngine *DSPEngine::addDeviceSinkEngine()
m_deviceEngineReferences.push_back(DeviceEngineReference{1, nullptr, m_deviceSinkEngines.back(), nullptr, deviceThread});
deviceSinkEngine->moveToThread(deviceThread);

QObject::connect(
deviceThread,
&QThread::finished,
deviceSinkEngine,
&QObject::deleteLater
);
QObject::connect(
deviceThread,
&QThread::finished,
Expand Down Expand Up @@ -166,12 +154,6 @@ DSPDeviceMIMOEngine *DSPEngine::addDeviceMIMOEngine()
m_deviceEngineReferences.push_back(DeviceEngineReference{2, nullptr, nullptr, m_deviceMIMOEngines.back(), deviceThread});
deviceMIMOEngine->moveToThread(deviceThread);

QObject::connect(
deviceThread,
&QThread::finished,
deviceMIMOEngine,
&QObject::deleteLater
);
QObject::connect(
deviceThread,
&QThread::finished,
Expand Down Expand Up @@ -205,38 +187,39 @@ void DSPEngine::removeLastDeviceMIMOEngine()
}
}

void DSPEngine::removeDeviceEngineAt(int deviceIndex)
QThread * DSPEngine::removeDeviceEngineAt(int deviceIndex)
{
if (deviceIndex >= m_deviceEngineReferences.size()) {
return;
return nullptr;
}

QThread *deviceThread = nullptr;

if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 0) // source
{
DSPDeviceSourceEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSourceEngine;
QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread->exit();
deviceThread->wait();
m_deviceSourceEngines.removeAll(deviceEngine);
}
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink
{
DSPDeviceSinkEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSinkEngine;
QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread->exit();
deviceThread->wait();
m_deviceSinkEngines.removeAll(deviceEngine);
}
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO
{
DSPDeviceMIMOEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceMIMOEngine;
QThread *deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
deviceThread->exit();
deviceThread->wait();
m_deviceMIMOEngines.removeAll(deviceEngine);
}

m_deviceEngineReferences.removeAt(deviceIndex);

return deviceThread;
}

void DSPEngine::createFFTFactory(const QString& fftWisdomFileName)
Expand Down
2 changes: 1 addition & 1 deletion sdrbase/dsp/dspengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SDRBASE_API DSPEngine : public QObject {
DSPDeviceMIMOEngine *addDeviceMIMOEngine();
void removeLastDeviceMIMOEngine();

void removeDeviceEngineAt(int deviceIndex);
QThread *removeDeviceEngineAt(int deviceIndex);

AudioDeviceManager *getAudioDeviceManager() { return &m_audioDeviceManager; }

Expand Down
3 changes: 3 additions & 0 deletions sdrgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ target_link_libraries(sdrgui
logging
)
if (Qt6_FOUND)
target_link_libraries(sdrgui
Qt6::StateMachine
)
target_link_libraries(sdrbase
Qt::OpenGLWidgets
)
Expand Down
8 changes: 5 additions & 3 deletions sdrgui/device/devicegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ DeviceGUI::DeviceGUI(QWidget *parent) :
m_contextMenuType(ContextMenuNone),
m_resizer(this),
m_drag(false),
m_currentDeviceIndex(-1)
m_currentDeviceIndex(-1),
m_channelAddDialog(this)
{
qDebug("DeviceGUI::DeviceGUI: %p", parent);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
Expand Down Expand Up @@ -283,7 +284,7 @@ void DeviceGUI::closeEvent(QCloseEvent *event)
{
qDebug("DeviceGUI::closeEvent");
emit closing();
event->accept();
event->ignore(); // Don't automatically delete the GUI - MainWindow::RemoveDeviceSetFSM::removeUI will do it
}

void DeviceGUI::mousePressEvent(QMouseEvent* event)
Expand Down Expand Up @@ -380,7 +381,8 @@ void DeviceGUI::openMoveToWorkspaceDialog()

void DeviceGUI::openAddChannelsDialog()
{
m_channelAddDialog.exec();
//m_channelAddDialog.exec();
m_channelAddDialog.open();
}

void DeviceGUI::showSpectrumHandler()
Expand Down
3 changes: 2 additions & 1 deletion sdrgui/gui/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ private slots:
void stackSubWindows();
void autoStackSubWindows(const QPoint&);
void tabSubWindows();
void layoutSubWindows();
void startStopClicked(bool checked = false);
void addFeatureEmitted(int featureIndex);
void toggleFloating();
void deviceStateChanged(int, DeviceAPI *deviceAPI);
void subWindowActivated(QMdiSubWindow *window);
public slots:
void layoutSubWindows();

signals:
void addRxDevice(Workspace *inWorkspace, int deviceIndex);
Expand Down
Loading

0 comments on commit 4dcf050

Please sign in to comment.