mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-17 23:28:50 -05:00
Multi device support: channel registrations support in device API
This commit is contained in:
parent
6840a20ab9
commit
e1e3df466f
@ -16,6 +16,8 @@
|
||||
|
||||
#include "device/deviceapi.h"
|
||||
#include "plugin/plugingui.h"
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "plugin/plugininterface.h"
|
||||
#include "gui/glspectrum.h"
|
||||
#include "gui/channelwindow.h"
|
||||
#include "mainwindow.h"
|
||||
@ -156,10 +158,44 @@ void DeviceAPI::setSampleSourcePluginGUI(PluginGUI *gui)
|
||||
m_sampleSourcePluginGUI = gui;
|
||||
}
|
||||
|
||||
void DeviceAPI::registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI)
|
||||
{
|
||||
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
|
||||
renameChannelInstances();
|
||||
}
|
||||
|
||||
void DeviceAPI::removeChannelInstance(PluginGUI* pluginGUI)
|
||||
{
|
||||
for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
|
||||
{
|
||||
if(it->m_gui == pluginGUI)
|
||||
{
|
||||
m_channelInstanceRegistrations.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renameChannelInstances();
|
||||
}
|
||||
|
||||
void DeviceAPI::renameChannelInstances()
|
||||
{
|
||||
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
||||
{
|
||||
m_channelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i));
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceAPI::freeAll()
|
||||
{
|
||||
m_deviceEngine->stopAcquistion();
|
||||
|
||||
while(!m_channelInstanceRegistrations.isEmpty())
|
||||
{
|
||||
ChannelInstanceRegistration reg(m_channelInstanceRegistrations.takeLast());
|
||||
reg.m_gui->destroy();
|
||||
}
|
||||
|
||||
if(m_sampleSourcePluginGUI != 0)
|
||||
{
|
||||
m_deviceEngine->setSource(0);
|
||||
@ -199,6 +235,69 @@ void DeviceAPI::saveSourceSettings(Preset* preset)
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceAPI::loadChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
|
||||
{
|
||||
qDebug("DeviceAPI::loadChannelSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
||||
|
||||
// Available channel plugins
|
||||
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getChannelRegistrations();
|
||||
|
||||
// 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 < channelRegistrations->count(); i++)
|
||||
{
|
||||
if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel)
|
||||
{
|
||||
qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel));
|
||||
reg = ChannelInstanceRegistration(channelConfig.m_channel, (*channelRegistrations)[i].m_plugin->createChannel(channelConfig.m_channel, this));
|
||||
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();
|
||||
}
|
||||
|
||||
void DeviceAPI::saveChannelSettings(Preset *preset)
|
||||
{
|
||||
qDebug("DeviceAPI::saveChannelSettings");
|
||||
|
@ -35,6 +35,7 @@ class MessageQueue;
|
||||
class ChannelMarker;
|
||||
class QWidget;
|
||||
class PluginGUI;
|
||||
class PluginAPI;
|
||||
class Preset;
|
||||
|
||||
class SDRANGEL_API DeviceAPI : public QObject {
|
||||
@ -69,10 +70,14 @@ public:
|
||||
void setSampleSourceSequence(int sequence);
|
||||
void setSampleSourcePluginGUI(PluginGUI *gui);
|
||||
|
||||
void registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI);
|
||||
void removeChannelInstance(PluginGUI* pluginGUI);
|
||||
|
||||
void freeAll();
|
||||
|
||||
void loadSourceSettings(const Preset* preset);
|
||||
void saveSourceSettings(Preset* preset);
|
||||
void loadChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
|
||||
void saveChannelSettings(Preset* preset);
|
||||
|
||||
protected:
|
||||
@ -103,6 +108,8 @@ protected:
|
||||
ChannelWindow *channelWindow);
|
||||
~DeviceAPI();
|
||||
|
||||
void renameChannelInstances();
|
||||
|
||||
MainWindow *m_mainWindow;
|
||||
int m_deviceTabIndex;
|
||||
DSPDeviceEngine *m_deviceEngine;
|
||||
|
@ -28,6 +28,12 @@ void PluginAPI::registerSampleSource(const QString& sourceName, PluginInterface*
|
||||
m_pluginManager->registerSampleSource(sourceName, plugin);
|
||||
}
|
||||
|
||||
PluginAPI::ChannelRegistrations *PluginAPI::getChannelRegistrations()
|
||||
{
|
||||
return m_pluginManager->getChannelRegistrations();
|
||||
}
|
||||
|
||||
|
||||
PluginAPI::PluginAPI(PluginManager* pluginManager, MainWindow* mainWindow) :
|
||||
QObject(mainWindow),
|
||||
m_pluginManager(pluginManager),
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
void registerChannel(const QString& channelName, PluginInterface* plugin);
|
||||
void registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI);
|
||||
void removeChannelInstance(PluginGUI* pluginGUI);
|
||||
ChannelRegistrations *getChannelRegistrations();
|
||||
|
||||
// Sample Source stuff
|
||||
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
void removeChannelInstance(PluginGUI* pluginGUI);
|
||||
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
|
||||
|
||||
PluginAPI::ChannelRegistrations *getChannelRegistrations() { return &m_channelRegistrations; }
|
||||
|
||||
void loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI);
|
||||
// void loadSourceSettings(const Preset* preset);
|
||||
void saveSettings(Preset* preset);
|
||||
|
Loading…
Reference in New Issue
Block a user