From aa3d5eddb0c08bd45565c2971313ee478b66b671 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 3 Oct 2020 03:09:36 +0200 Subject: [PATCH] Add GUI to device set outside plugin --- sdrbase/device/deviceapi.h | 4 +--- sdrbase/plugin/pluginmanager.cpp | 1 - sdrgui/device/deviceuiset.cpp | 28 ++++++++++++++++------------ sdrgui/device/deviceuiset.h | 12 ++++++++---- sdrgui/mainwindow.cpp | 30 ++++++++++++++++++++---------- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/sdrbase/device/deviceapi.h b/sdrbase/device/deviceapi.h index f2e26c842..6edb93667 100644 --- a/sdrbase/device/deviceapi.h +++ b/sdrbase/device/deviceapi.h @@ -128,8 +128,6 @@ public: PluginInterface *getPluginInterface() { return m_pluginInterface; } PluginInstanceGUI *getSamplingDevicePluginInstanceGUI() { return m_samplingDevicePluginInstanceUI; } - // PluginInstanceGUI *getSampleSourcePluginInstanceGUI() { return m_sampleSourcePluginInstanceUI; } - // PluginInstanceGUI *getSampleSinkPluginInstanceGUI() { return m_sampleSinkPluginInstanceUI; } void getDeviceEngineStateStr(QString& state, int subsystemIndex = 0); @@ -214,4 +212,4 @@ protected: private: void renumerateChannels(); }; -#endif // SDRBASE_DEVICE_DEVICEAPI_H_ \ No newline at end of file +#endif // SDRBASE_DEVICE_DEVICEAPI_H_ diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 353cb2d0e..512dfcf14 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -22,7 +22,6 @@ #include #include -#include #include "device/deviceenumerator.h" #include "settings/preset.h" #include "util/message.h" diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index ed7371cc2..d30842db6 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -91,21 +91,21 @@ void DeviceUISet::addRollupWidget(QWidget *widget) m_channelWindow->addRollupWidget(widget); } -void DeviceUISet::registerRxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI) +void DeviceUISet::registerRxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI) { - m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI, 0)); + m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, pluginGUI, 0)); renameChannelInstances(); } -void DeviceUISet::registerTxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI) +void DeviceUISet::registerTxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI) { - m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI, 1)); + m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, pluginGUI, 1)); renameChannelInstances(); } -void DeviceUISet::registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI) +void DeviceUISet::registerChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI) { - m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI, 2)); + m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, pluginGUI, 2)); renameChannelInstances(); } @@ -208,11 +208,12 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA qDebug("DeviceUISet::loadRxChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); + ChannelAPI *channelAPI; BasebandSampleSink *rxChannel; - (*channelRegistrations)[i].m_plugin->createRxChannel(m_deviceAPI, &rxChannel, nullptr); + (*channelRegistrations)[i].m_plugin->createRxChannel(m_deviceAPI, &rxChannel, &channelAPI); PluginInstanceGUI *rxChannelGUI = (*channelRegistrations)[i].m_plugin->createRxChannelGUI(this, rxChannel); - reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, rxChannelGUI, 0); + reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, channelAPI, rxChannelGUI, 0); break; } } @@ -285,11 +286,12 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA qDebug("DeviceUISet::loadTxChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); + ChannelAPI *channelAPI; BasebandSampleSource *txChannel; - (*channelRegistrations)[i].m_plugin->createTxChannel(m_deviceAPI, &txChannel, nullptr); + (*channelRegistrations)[i].m_plugin->createTxChannel(m_deviceAPI, &txChannel, &channelAPI); PluginInstanceGUI *txChannelGUI = (*channelRegistrations)[i].m_plugin->createTxChannelGUI(this, txChannel); - reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, txChannelGUI, 1); + reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, channelAPI, txChannelGUI, 1); break; } } @@ -364,11 +366,13 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi qDebug("DeviceUISet::loadMIMOChannelSettings: creating new channel [%s] from config [%s]", qPrintable((*channelRegistrations)[i].m_channelIdURI), qPrintable(channelConfig.m_channelIdURI)); + ChannelAPI *channelAPI; MIMOChannel *mimoChannel; - (*channelRegistrations)[i].m_plugin->createMIMOChannel(m_deviceAPI, &mimoChannel, nullptr); + (*channelRegistrations)[i].m_plugin->createMIMOChannel(m_deviceAPI, &mimoChannel, &channelAPI); PluginInstanceGUI *mimoChannelGUI = (*channelRegistrations)[i].m_plugin->createMIMOChannelGUI(this, mimoChannel); - reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, mimoChannelGUI, 2); + (*channelRegistrations)[i].m_plugin->createMIMOChannel(m_deviceAPI, &mimoChannel, &channelAPI); + reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, channelAPI, mimoChannelGUI, 2); break; } } diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index 200e1c396..f68e5bb42 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -34,6 +34,7 @@ class DSPDeviceMIMOEngine; class ChannelMarker; class PluginAPI; class PluginInstanceGUI; +class ChannelAPI; class Preset; namespace SWGSDRangel { @@ -72,9 +73,9 @@ public: void saveTxChannelSettings(Preset* preset); void loadMIMOChannelSettings(const Preset* preset, PluginAPI *pluginAPI); void saveMIMOChannelSettings(Preset* preset); - void registerRxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI); - void registerTxChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI); - void registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI); + void registerRxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI); + void registerTxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI); + void registerChannelInstance(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI); void removeRxChannelInstance(PluginInstanceGUI* pluginGUI); void removeTxChannelInstance(PluginInstanceGUI* pluginGUI); void removeChannelInstance(PluginInstanceGUI* pluginGUI); @@ -102,17 +103,20 @@ private: struct ChannelInstanceRegistration { QString m_channelName; + ChannelAPI *m_channelAPI; PluginInstanceGUI* m_gui; int m_channelType; ChannelInstanceRegistration() : m_channelName(), + m_channelAPI(nullptr), m_gui(nullptr), m_channelType(0) { } - ChannelInstanceRegistration(const QString& channelName, PluginInstanceGUI* pluginGUI, int channelType) : + ChannelInstanceRegistration(const QString& channelName, ChannelAPI *channelAPI, PluginInstanceGUI* pluginGUI, int channelType) : m_channelName(channelName), + m_channelAPI(channelAPI), m_gui(pluginGUI), m_channelType(channelType) { } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 8840c0852..cc1d65112 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -2071,17 +2071,21 @@ void MainWindow::channelAddClicked(int channelIndex) { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); // Available channel plugins PluginInterface *pluginInterface = (*channelRegistrations)[channelIndex].m_plugin; + ChannelAPI *channelAPI; BasebandSampleSink *rxChannel; - pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, nullptr); - pluginInterface->createRxChannelGUI(deviceUI, rxChannel); + pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, &channelAPI); + PluginInstanceGUI *gui = pluginInterface->createRxChannelGUI(deviceUI, rxChannel); + deviceUI->registerRxChannelInstance(gui->getName(), channelAPI, gui); } else if (deviceUI->m_deviceSinkEngine) // sink device => Tx channels { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins PluginInterface *pluginInterface = (*channelRegistrations)[channelIndex].m_plugin; + ChannelAPI *channelAPI; BasebandSampleSource *txChannel; - pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, nullptr); - pluginInterface->createTxChannelGUI(deviceUI, txChannel); + pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, &channelAPI); + PluginInstanceGUI *gui = pluginInterface->createTxChannelGUI(deviceUI, txChannel); + deviceUI->registerTxChannelInstance(gui->getName(), channelAPI, gui); } else if (deviceUI->m_deviceMIMOEngine) // MIMO device => all possible channels. Depends on index range { @@ -2095,25 +2099,31 @@ void MainWindow::channelAddClicked(int channelIndex) { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getMIMOChannelRegistrations(); // Available channel plugins PluginInterface *pluginInterface = (*channelRegistrations)[channelIndex].m_plugin; + ChannelAPI *channelAPI; MIMOChannel *mimoChannel; - pluginInterface->createMIMOChannel(deviceUI->m_deviceAPI, &mimoChannel, nullptr); - pluginInterface->createMIMOChannelGUI(deviceUI, mimoChannel); + pluginInterface->createMIMOChannel(deviceUI->m_deviceAPI, &mimoChannel, &channelAPI); + PluginInstanceGUI *gui = pluginInterface->createMIMOChannelGUI(deviceUI, mimoChannel); + deviceUI->registerChannelInstance(gui->getName(), channelAPI, gui); } else if (channelIndex < nbMIMOChannels + nbRxChannels) // Rx { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getRxChannelRegistrations(); // Available channel plugins PluginInterface *pluginInterface = (*channelRegistrations)[channelIndex - nbMIMOChannels].m_plugin; + ChannelAPI *channelAPI; BasebandSampleSink *rxChannel; - pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, nullptr); - pluginInterface->createRxChannelGUI(deviceUI, rxChannel); + pluginInterface->createRxChannel(deviceUI->m_deviceAPI, &rxChannel, &channelAPI); + PluginInstanceGUI *gui = pluginInterface->createRxChannelGUI(deviceUI, rxChannel); + deviceUI->registerRxChannelInstance(gui->getName(), channelAPI, gui); } else if (channelIndex < nbMIMOChannels + nbRxChannels + nbTxChannels) { PluginAPI::ChannelRegistrations *channelRegistrations = m_pluginManager->getTxChannelRegistrations(); // Available channel plugins PluginInterface *pluginInterface = (*channelRegistrations)[channelIndex - nbMIMOChannels - nbRxChannels].m_plugin; + ChannelAPI *channelAPI; BasebandSampleSource *txChannel; - pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, nullptr); - pluginInterface->createTxChannelGUI(deviceUI, txChannel); + pluginInterface->createTxChannel(deviceUI->m_deviceAPI, &txChannel, &channelAPI); + PluginInstanceGUI *gui = pluginInterface->createTxChannelGUI(deviceUI, txChannel); + deviceUI->registerTxChannelInstance(gui->getName(), channelAPI, gui); } } }