DeviceSourceAPI code cleanup

pull/127/head
f4exb 2017-10-31 08:35:27 +01:00
rodzic a61bb04dac
commit e30050f018
3 zmienionych plików z 3 dodań i 187 usunięć

Wyświetl plik

@ -179,49 +179,6 @@ void DeviceSourceAPI::setSampleSourcePluginInstanceGUI(PluginInstanceGUI *gui)
m_sampleSourcePluginInstanceUI = gui;
}
void DeviceSourceAPI::registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
renameChannelInstances();
}
void DeviceSourceAPI::removeChannelInstance(PluginInstanceGUI* 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 DeviceSourceAPI::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 DeviceSourceAPI::freeChannels()
{
// while(!m_channelInstanceRegistrations.isEmpty())
// {
// ChannelInstanceRegistration reg(m_channelInstanceRegistrations.takeLast());
// reg.m_gui->destroy();
// }
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSourceAPI::freeAll: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
m_channelInstanceRegistrations[i].m_gui->destroy();
}
}
void DeviceSourceAPI::loadSourceSettings(const Preset* preset)
{
if (preset->isSourcePreset())
@ -274,116 +231,6 @@ void DeviceSourceAPI::saveSourceSettings(Preset* preset)
}
}
void DeviceSourceAPI::loadChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
{
if (preset->isSourcePreset())
{
qDebug("DeviceSourceAPI::loadChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations();
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear();
qDebug("DeviceSourceAPI::loadChannelSettings: %d channel(s) in preset", preset->getChannelCount());
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("DeviceSourceAPI::loadChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel));
if(openChannels[i].m_channelName == channelConfig.m_channel)
{
qDebug("DeviceSourceAPI::loadChannelSettings: 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("DeviceSourceAPI::loadChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel));
reg = ChannelInstanceRegistration(channelConfig.m_channel, (*channelRegistrations)[i].m_plugin->createRxChannel(channelConfig.m_channel, this));
break;
}
}
}
if(reg.m_gui != NULL)
{
qDebug("DeviceSourceAPI::loadChannelSettings: 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("DeviceSourceAPI::loadChannelSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
openChannels[i].m_gui->destroy();
}
renameChannelInstances();
}
else
{
qDebug("DeviceSourceAPI::loadChannelSettings: Loading preset [%s | %s] not a source preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
}
}
void DeviceSourceAPI::saveChannelSettings(Preset *preset)
{
if (preset->isSourcePreset())
{
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSourceAPI::saveChannelSettings: channel [%s] saved", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize());
}
}
else
{
qDebug("DeviceSourceAPI::saveChannelSettings: not a source preset");
}
}
// sort by increasing delta frequency and type (i.e. name)
bool DeviceSourceAPI::ChannelInstanceRegistration::operator<(const ChannelInstanceRegistration& other) const
{
if (m_gui && other.m_gui)
{
if (m_gui->getCenterFrequency() == other.m_gui->getCenterFrequency())
{
return m_gui->getName() < other.m_gui->getName();
}
else
{
return m_gui->getCenterFrequency() < other.m_gui->getCenterFrequency();
}
}
else
{
return false;
}
}
void DeviceSourceAPI::addSourceBuddy(DeviceSourceAPI* buddy)
{
m_sourceBuddies.push_back(buddy);

Wyświetl plik

@ -88,12 +88,6 @@ public:
uint32_t getSampleSourceSequence() const { return m_sampleSourceSequence; }
PluginInstanceGUI *getSampleSourcePluginInstanceGUI() { return m_sampleSourcePluginInstanceUI; }
void registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI);
void removeChannelInstance(PluginInstanceGUI* pluginGUI);
void freeChannels();
void loadChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveChannelSettings(Preset* preset);
void loadSourceSettings(const Preset* preset);
void saveSourceSettings(Preset* preset);
@ -114,29 +108,6 @@ public:
const QTimer& getMasterTimer() const { return m_masterTimer; } //!< This is the DSPEngine master timer
protected:
struct ChannelInstanceRegistration
{
QString m_channelName;
PluginInstanceGUI* m_gui;
ChannelInstanceRegistration() :
m_channelName(),
m_gui(NULL)
{ }
ChannelInstanceRegistration(const QString& channelName, PluginInstanceGUI* pluginGUI) :
m_channelName(channelName),
m_gui(pluginGUI)
{ }
bool operator<(const ChannelInstanceRegistration& other) const;
};
typedef QList<ChannelInstanceRegistration> ChannelInstanceRegistrations;
void renameChannelInstances();
int m_deviceTabIndex;
DSPDeviceSourceEngine *m_deviceSourceEngine;
GLSpectrum *m_spectrum;
@ -150,8 +121,6 @@ protected:
PluginInterface* m_pluginInterface;
PluginInstanceGUI* m_sampleSourcePluginInstanceUI;
ChannelInstanceRegistrations m_channelInstanceRegistrations;
std::vector<DeviceSourceAPI*> m_sourceBuddies; //!< Device source APIs referencing the same physical device
std::vector<DeviceSinkAPI*> m_sinkBuddies; //!< Device sink APIs referencing the same physical device
void *m_buddySharedPtr;

Wyświetl plik

@ -330,7 +330,7 @@ void MainWindow::removeLastDevice()
ui->tabSpectra->removeTab(ui->tabSpectra->count() - 1);
// deletes old UI and input object
m_deviceUIs.back()->m_deviceSourceAPI->freeChannels(); // destroys the channel instances
m_deviceUIs.back()->freeChannels(); // destroys the channel instances
m_deviceUIs.back()->m_deviceSourceAPI->getSampleSource()->setMessageQueueToGUI(0); // have source stop sending messages to the GUI
m_deviceUIs.back()->m_deviceSourceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceGUI(
m_deviceUIs.back()->m_deviceSourceAPI->getSampleSourcePluginInstanceGUI());
@ -479,7 +479,7 @@ void MainWindow::loadPresetSettings(const Preset* preset, int tabIndex)
{
deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig());
deviceUI->m_deviceSourceAPI->loadSourceSettings(preset);
deviceUI->m_deviceSourceAPI->loadChannelSettings(preset, m_pluginManager->getPluginAPI());
deviceUI->loadChannelSettings(preset, m_pluginManager->getPluginAPI());
}
else if (deviceUI->m_deviceSinkEngine) // sink device
{
@ -507,7 +507,7 @@ void MainWindow::savePresetSettings(Preset* preset, int tabIndex)
{
preset->setSpectrumConfig(deviceUI->m_spectrumGUI->serialize());
preset->clearChannels();
deviceUI->m_deviceSourceAPI->saveChannelSettings(preset);
deviceUI->saveChannelSettings(preset);
deviceUI->m_deviceSourceAPI->saveSourceSettings(preset);
}
else if (deviceUI->m_deviceSinkEngine) // sink device