From 00864bfb6cd06a4703db84237a41466173629e69 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 16 May 2016 19:55:01 +0200 Subject: [PATCH] Multi device support: use device API for channel load and save --- sdrbase/mainwindow.cpp | 5 +- sdrbase/plugin/pluginapi.h | 1 + sdrbase/plugin/pluginmanager.cpp | 146 +++++++++++++++---------------- sdrbase/plugin/pluginmanager.h | 6 +- 4 files changed, 81 insertions(+), 77 deletions(-) diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 366ca7998..d02e1c07e 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -315,8 +315,9 @@ void MainWindow::loadPresetSettings(const Preset* preset) if (currentSourceTabIndex >= 0) { DeviceUISet *deviceUI = m_deviceUIs[currentSourceTabIndex]; + PluginAPI pluginAPI(deviceUI->m_pluginManager, this); deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); - deviceUI->m_pluginManager->loadChannelSettings(preset, deviceUI->m_deviceAPI); + deviceUI->m_deviceAPI->loadChannelSettings(preset, &pluginAPI); deviceUI->m_deviceAPI->loadSourceSettings(preset); } @@ -344,7 +345,7 @@ void MainWindow::savePresetSettings(Preset* preset) preset->setSpectrumConfig(deviceUI->m_spectrumGUI->serialize()); preset->clearChannels(); - deviceUI->m_pluginManager->saveSettings(preset); + deviceUI->m_deviceAPI->saveChannelSettings(preset); deviceUI->m_deviceAPI->saveSourceSettings(preset); preset->setLayout(saveState()); diff --git a/sdrbase/plugin/pluginapi.h b/sdrbase/plugin/pluginapi.h index 0c26cd969..7b89f96ac 100644 --- a/sdrbase/plugin/pluginapi.h +++ b/sdrbase/plugin/pluginapi.h @@ -53,6 +53,7 @@ protected: ~PluginAPI(); friend class PluginManager; + friend class MainWindow; }; #endif // INCLUDE_PLUGINAPI_H diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 632b6b3bc..2ae49f933 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -85,67 +85,67 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin)); } -void PluginManager::loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI) -{ - fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); - - // copy currently open channels and clear list - ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; - m_channelInstanceRegistrations.clear(); - - for(int i = 0; i < preset->getChannelCount(); i++) - { - const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); - ChannelInstanceRegistration reg; - - // if we have one instance available already, use it - - for(int i = 0; i < openChannels.count(); i++) - { - qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); - - if(openChannels[i].m_channelName == channelConfig.m_channel) - { - qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); - reg = openChannels.takeAt(i); - m_channelInstanceRegistrations.append(reg); - break; - } - } - - // if we haven't one already, create one - - if(reg.m_gui == NULL) - { - for(int i = 0; i < m_channelRegistrations.count(); i++) - { - if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel) - { - qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); - reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel, deviceAPI)); - break; - } - } - } - - if(reg.m_gui != NULL) - { - qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel)); - reg.m_gui->deserialize(channelConfig.m_config); - } - } - - // everything, that is still "available" is not needed anymore - for(int i = 0; i < openChannels.count(); i++) - { - qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); - openChannels[i].m_gui->destroy(); - } - - renameChannelInstances(); - -// loadSourceSettings(preset); // FIXME -} +//void PluginManager::loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI) +//{ +// fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); +// +// // copy currently open channels and clear list +// ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; +// m_channelInstanceRegistrations.clear(); +// +// for(int i = 0; i < preset->getChannelCount(); i++) +// { +// const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); +// ChannelInstanceRegistration reg; +// +// // if we have one instance available already, use it +// +// for(int i = 0; i < openChannels.count(); i++) +// { +// qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); +// +// if(openChannels[i].m_channelName == channelConfig.m_channel) +// { +// qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); +// reg = openChannels.takeAt(i); +// m_channelInstanceRegistrations.append(reg); +// break; +// } +// } +// +// // if we haven't one already, create one +// +// if(reg.m_gui == NULL) +// { +// for(int i = 0; i < m_channelRegistrations.count(); i++) +// { +// if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel) +// { +// qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); +// reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel, deviceAPI)); +// break; +// } +// } +// } +// +// if(reg.m_gui != NULL) +// { +// qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel)); +// reg.m_gui->deserialize(channelConfig.m_config); +// } +// } +// +// // everything, that is still "available" is not needed anymore +// for(int i = 0; i < openChannels.count(); i++) +// { +// qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); +// openChannels[i].m_gui->destroy(); +// } +// +// renameChannelInstances(); +// +//// loadSourceSettings(preset); // FIXME +//} //void PluginManager::loadSourceSettings(const Preset* preset) //{ @@ -179,18 +179,18 @@ bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstance } } -void PluginManager::saveSettings(Preset* preset) -{ - qDebug("PluginManager::saveSettings"); -// saveSourceSettings(preset); // FIXME - - qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type - - for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) - { - preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize()); - } -} +//void PluginManager::saveSettings(Preset* preset) +//{ +// qDebug("PluginManager::saveSettings"); +//// saveSourceSettings(preset); // FIXME +// +// qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type +// +// for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) +// { +// preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize()); +// } +//} //void PluginManager::saveSourceSettings(Preset* preset) //{ diff --git a/sdrbase/plugin/pluginmanager.h b/sdrbase/plugin/pluginmanager.h index 2174e28b6..62a8a948b 100644 --- a/sdrbase/plugin/pluginmanager.h +++ b/sdrbase/plugin/pluginmanager.h @@ -49,9 +49,9 @@ public: PluginAPI::ChannelRegistrations *getChannelRegistrations() { return &m_channelRegistrations; } - void loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI); +// void loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI); // void loadSourceSettings(const Preset* preset); - void saveSettings(Preset* preset); +// void saveSettings(Preset* preset); // void saveSourceSettings(Preset* preset); void freeAll(); @@ -68,6 +68,8 @@ public: void populateChannelComboBox(QComboBox *channels); void createChannelInstance(int channelPluginIndex, DeviceAPI *deviceAPI); + PluginAPI *getAPI(MainWindow *mainWindow); + private: struct ChannelInstanceRegistration { QString m_channelName;