1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

MainCore: added feature and channel maps. FeatureSet and FeatureUISet: simplify feature registrations. Channel and feature names fix

This commit is contained in:
f4exb 2020-10-16 08:35:06 +02:00
parent 97b757fa98
commit 8b05670814
11 changed files with 243 additions and 75 deletions

View File

@ -513,4 +513,4 @@ void LocalSource::networkManagerFinished(QNetworkReply *reply)
uint32_t LocalSource::getNumberOfDeviceStreams() const uint32_t LocalSource::getNumberOfDeviceStreams() const
{ {
return m_deviceAPI->getNbSinkStreams(); return m_deviceAPI->getNbSinkStreams();
} }

View File

@ -25,6 +25,7 @@
#include "channel/channelapi.h" #include "channel/channelapi.h"
#include "channel/channelutils.h" #include "channel/channelutils.h"
#include "settings/preset.h" #include "settings/preset.h"
#include "maincore.h"
#include "deviceset.h" #include "deviceset.h"
@ -51,6 +52,8 @@ void DeviceSet::freeChannels()
qDebug("DeviceSet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i]->getURI())); qDebug("DeviceSet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i]->getURI()));
m_channelInstanceRegistrations[i]->destroy(); m_channelInstanceRegistrations[i]->destroy();
} }
MainCore::instance()->clearChannels(this);
} }
const ChannelAPI *DeviceSet::getChannelAt(int channelIndex) const const ChannelAPI *DeviceSet::getChannelAt(int channelIndex) const
@ -77,6 +80,7 @@ void DeviceSet::deleteChannel(int channelIndex)
{ {
m_channelInstanceRegistrations[channelIndex]->destroy(); m_channelInstanceRegistrations[channelIndex]->destroy();
m_channelInstanceRegistrations.removeAt(channelIndex); m_channelInstanceRegistrations.removeAt(channelIndex);
MainCore::instance()->removeChannelInstanceAt(this, channelIndex);
renameChannelInstances(); renameChannelInstances();
} }
} }
@ -86,8 +90,10 @@ void DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins
ChannelAPI *rxChannel; ChannelAPI *rxChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel);
ChannelAPI *reg = rxChannel; ChannelAPI *channelAPI = rxChannel;
m_channelInstanceRegistrations.append(reg); m_channelInstanceRegistrations.append(channelAPI);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances();
qDebug("DeviceSet::addRxChannel: %s", qPrintable(rxChannel->getName())); qDebug("DeviceSet::addRxChannel: %s", qPrintable(rxChannel->getName()));
} }
@ -96,8 +102,10 @@ void DeviceSet::addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // Available channel plugins
ChannelAPI *txChannel; ChannelAPI *txChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel);
ChannelAPI *reg = txChannel; ChannelAPI *channelAPI = txChannel;
m_channelInstanceRegistrations.append(reg); m_channelInstanceRegistrations.append(channelAPI);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances();
qDebug("DeviceSet::addTxChannel: %s", qPrintable(txChannel->getName())); qDebug("DeviceSet::addTxChannel: %s", qPrintable(txChannel->getName()));
} }
@ -106,8 +114,10 @@ void DeviceSet::addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // Available channel plugins
ChannelAPI *mimoChannel; ChannelAPI *mimoChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel);
ChannelAPI *reg = mimoChannel; ChannelAPI *channelAPI = mimoChannel;
m_channelInstanceRegistrations.append(reg); m_channelInstanceRegistrations.append(channelAPI);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances();
qDebug("DeviceSet::addMIMOChannel: %s", qPrintable(mimoChannel->getName())); qDebug("DeviceSet::addMIMOChannel: %s", qPrintable(mimoChannel->getName()));
} }
@ -115,6 +125,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
{ {
if (preset->isSourcePreset()) if (preset->isSourcePreset())
{ {
MainCore *mainCore = MainCore::instance();
qDebug("DeviceSet::loadChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); qDebug("DeviceSet::loadChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins // Available channel plugins
@ -123,6 +134,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
// copy currently open channels and clear list // copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear(); m_channelInstanceRegistrations.clear();
mainCore->clearChannels(this);
qDebug("DeviceSet::loadChannelSettings: %d channel(s) in preset", preset->getChannelCount()); qDebug("DeviceSet::loadChannelSettings: %d channel(s) in preset", preset->getChannelCount());
@ -144,6 +156,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
qDebug("DeviceSet::loadChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI())); qDebug("DeviceSet::loadChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI()));
channelAPI = openChannels.takeAt(i); channelAPI = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -164,6 +177,7 @@ void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
(*channelRegistrations)[i].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel); (*channelRegistrations)[i].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel);
channelAPI = rxChannel; channelAPI = rxChannel;
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -214,6 +228,7 @@ void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
{ {
if (preset->isSinkPreset()) if (preset->isSinkPreset())
{ {
MainCore *mainCore = MainCore::instance();
qDebug("DeviceSet::loadTxChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); qDebug("DeviceSet::loadTxChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins // Available channel plugins
@ -222,6 +237,7 @@ void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
// copy currently open channels and clear list // copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear(); m_channelInstanceRegistrations.clear();
mainCore->clearChannels(this);
qDebug("DeviceSet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount()); qDebug("DeviceSet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
@ -242,6 +258,7 @@ void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
qDebug("DeviceSet::loadTxChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI())); qDebug("DeviceSet::loadTxChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI()));
channelAPI = openChannels.takeAt(i); channelAPI = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -259,6 +276,7 @@ void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI
(*channelRegistrations)[i].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel); (*channelRegistrations)[i].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel);
channelAPI = txChannel; channelAPI = txChannel;
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -311,6 +329,7 @@ void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginA
{ {
if (preset->isMIMOPreset()) if (preset->isMIMOPreset())
{ {
MainCore *mainCore = MainCore::instance();
qDebug("DeviceSet::loadMIMOChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); qDebug("DeviceSet::loadMIMOChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins // Available channel plugins
@ -319,6 +338,7 @@ void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginA
// copy currently open channels and clear list // copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear(); m_channelInstanceRegistrations.clear();
mainCore->clearChannels(this);
qDebug("DeviceSet::loadMIMOChannelSettings: %d channel(s) in preset", preset->getChannelCount()); qDebug("DeviceSet::loadMIMOChannelSettings: %d channel(s) in preset", preset->getChannelCount());
@ -340,6 +360,7 @@ void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginA
qDebug("DeviceSet::loadMIMOChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI())); qDebug("DeviceSet::loadMIMOChannelSettings: channel [%s] found", qPrintable(openChannels[i]->getURI()));
channelAPI = openChannels.takeAt(i); channelAPI = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -360,6 +381,7 @@ void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginA
(*channelRegistrations)[i].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel); (*channelRegistrations)[i].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel);
channelAPI = mimoChannel; channelAPI = mimoChannel;
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
break; break;
} }
} }
@ -408,8 +430,10 @@ void DeviceSet::saveMIMOChannelSettings(Preset *preset)
void DeviceSet::renameChannelInstances() void DeviceSet::renameChannelInstances()
{ {
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++) { for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
m_channelInstanceRegistrations[i]->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i]->getURI()).arg(i)); m_channelInstanceRegistrations[i]->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i]->getURI()).arg(i));
m_channelInstanceRegistrations[i]->setIndexInDeviceSet(i);
} }
} }
@ -432,29 +456,43 @@ bool DeviceSet::compareChannels(const ChannelAPI *channelA, const ChannelAPI *ch
void DeviceSet::addChannelInstance(ChannelAPI *channelAPI) void DeviceSet::addChannelInstance(ChannelAPI *channelAPI)
{ {
MainCore *mainCore = MainCore::instance();
m_channelInstanceRegistrations.append(channelAPI); m_channelInstanceRegistrations.append(channelAPI);
mainCore->addChannelInstance(this, channelAPI);
renameChannelInstances();
} }
void DeviceSet::removeChannelInstanceAt(int index) void DeviceSet::removeChannelInstanceAt(int index)
{ {
if (index < m_channelInstanceRegistrations.size()) { if (index < m_channelInstanceRegistrations.size())
{
MainCore *mainCore = MainCore::instance();
m_channelInstanceRegistrations.removeAt(index); m_channelInstanceRegistrations.removeAt(index);
mainCore->removeChannelInstanceAt(this, index);
renameChannelInstances();
} }
} }
void DeviceSet::removeChannelInstance(ChannelAPI *channelAPI) void DeviceSet::removeChannelInstance(ChannelAPI *channelAPI)
{ {
MainCore *mainCore = MainCore::instance();
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++) for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{ {
if (m_channelInstanceRegistrations.at(i) == channelAPI) if (m_channelInstanceRegistrations.at(i) == channelAPI)
{ {
m_channelInstanceRegistrations.removeAt(i); m_channelInstanceRegistrations.removeAt(i);
mainCore->removeChannelInstance(channelAPI);
break; break;
} }
} }
renameChannelInstances();
} }
void DeviceSet::clearChannels() void DeviceSet::clearChannels()
{ {
MainCore *mainCore = MainCore::instance();
m_channelInstanceRegistrations.clear(); m_channelInstanceRegistrations.clear();
mainCore->clearChannels(this);
} }

View File

@ -42,6 +42,7 @@ public:
~DeviceSet(); ~DeviceSet();
int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); } int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); }
int getIndex() const { return m_deviceTabIndex; }
void freeChannels(); void freeChannels();
const ChannelAPI *getChannelAt(int channelIndex) const; const ChannelAPI *getChannelAt(int channelIndex) const;
ChannelAPI *getChannelAt(int channelIndex); ChannelAPI *getChannelAt(int channelIndex);

View File

@ -132,6 +132,8 @@ public:
errorMessage = "Not implemented"; return 501; errorMessage = "Not implemented"; return 501;
} }
int getIndexInFeatureSet() const { return m_indexInFeatureSet; }
void setIndexInFeatureSet(int indexInFeatureSet) { m_indexInFeatureSet = indexInFeatureSet; }
uint64_t getUID() const { return m_uid; } uint64_t getUID() const { return m_uid; }
FeatureState getState() const { return m_state; } FeatureState getState() const { return m_state; }
const QString& getErrorMessage() const { return m_errorMessage; } const QString& getErrorMessage() const { return m_errorMessage; }
@ -155,6 +157,7 @@ protected slots:
private: private:
QString m_name; QString m_name;
uint64_t m_uid; uint64_t m_uid;
int m_indexInFeatureSet;
}; };
#endif // SDRBASE_FETURE_FEATUREAPI_H_ #endif // SDRBASE_FETURE_FEATUREAPI_H_

View File

@ -21,6 +21,7 @@
#include "feature/feature.h" #include "feature/feature.h"
#include "feature/featureutils.h" #include "feature/featureutils.h"
#include "settings/featuresetpreset.h" #include "settings/featuresetpreset.h"
#include "maincore.h"
#include "featureset.h" #include "featureset.h"
@ -39,7 +40,8 @@ void FeatureSet::addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebA
Feature *feature = featureRegistrations->at(selectedFeatureIndex).m_plugin->createFeature(apiAdapter); Feature *feature = featureRegistrations->at(selectedFeatureIndex).m_plugin->createFeature(apiAdapter);
QString featureName; QString featureName;
feature->getIdentifier(featureName); feature->getIdentifier(featureName);
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureName, feature)); m_featureInstanceRegistrations.append(feature);
MainCore::instance()->addFeatureInstance(this, feature);
renameFeatureInstances(); renameFeatureInstances();
} }
@ -47,9 +49,11 @@ void FeatureSet::removeFeatureInstance(Feature* feature)
{ {
for (FeatureInstanceRegistrations::iterator it = m_featureInstanceRegistrations.begin(); it != m_featureInstanceRegistrations.end(); ++it) for (FeatureInstanceRegistrations::iterator it = m_featureInstanceRegistrations.begin(); it != m_featureInstanceRegistrations.end(); ++it)
{ {
if (it->m_feature == feature) if (*it == feature)
{ {
m_featureInstanceRegistrations.erase(it); m_featureInstanceRegistrations.erase(it);
feature->setIndexInFeatureSet(-1);
MainCore::instance()->removeFeatureInstance(feature);
break; break;
} }
} }
@ -59,16 +63,18 @@ void FeatureSet::removeFeatureInstance(Feature* feature)
void FeatureSet::renameFeatureInstances() void FeatureSet::renameFeatureInstances()
{ {
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++) { for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
m_featureInstanceRegistrations[i].m_feature->setName(QString("%1:%2").arg(m_featureInstanceRegistrations[i].m_featureName).arg(i)); {
m_featureInstanceRegistrations[i]->setName(QString("%1:%2").arg(m_featureInstanceRegistrations[i]->getURI()).arg(i));
m_featureInstanceRegistrations[i]->setIndexInFeatureSet(i);
} }
} }
// sort by name // sort by name
bool FeatureSet::FeatureInstanceRegistration::operator<(const FeatureInstanceRegistration& other) const bool FeatureSet::compareFeatures(Feature *featureA, Feature *featureB)
{ {
if (m_feature && other.m_feature) { if (featureA && featureB) {
return m_feature->getName() < other.m_feature->getName(); return featureA->getName() < featureB->getName();
} else { } else {
return false; return false;
} }
@ -78,9 +84,11 @@ void FeatureSet::freeFeatures()
{ {
for(int i = 0; i < m_featureInstanceRegistrations.count(); i++) for(int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{ {
qDebug("FeatureSet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureName)); qDebug("FeatureSet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i]->getURI()));
m_featureInstanceRegistrations[i].m_feature->destroy(); m_featureInstanceRegistrations[i]->destroy();
} }
MainCore::instance()->clearFeatures(this);
} }
void FeatureSet::deleteFeature(int featureIndex) void FeatureSet::deleteFeature(int featureIndex)
@ -88,10 +96,11 @@ void FeatureSet::deleteFeature(int featureIndex)
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count()))
{ {
qDebug("FeatureSet::deleteFeature: delete feature [%s] at %d", qDebug("FeatureSet::deleteFeature: delete feature [%s] at %d",
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureName), qPrintable(m_featureInstanceRegistrations[featureIndex]->getURI()),
featureIndex); featureIndex);
m_featureInstanceRegistrations[featureIndex].m_feature->destroy(); m_featureInstanceRegistrations[featureIndex]->destroy();
m_featureInstanceRegistrations.removeAt(featureIndex); m_featureInstanceRegistrations.removeAt(featureIndex);
MainCore::instance()->removeFeatureInstanceAt(this, featureIndex);
renameFeatureInstances(); renameFeatureInstances();
} }
} }
@ -99,7 +108,7 @@ void FeatureSet::deleteFeature(int featureIndex)
const Feature *FeatureSet::getFeatureAt(int featureIndex) const const Feature *FeatureSet::getFeatureAt(int featureIndex) const
{ {
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) { if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) {
return m_featureInstanceRegistrations[featureIndex].m_feature; return m_featureInstanceRegistrations[featureIndex];
} else{ } else{
return nullptr; return nullptr;
} }
@ -108,7 +117,7 @@ const Feature *FeatureSet::getFeatureAt(int featureIndex) const
Feature *FeatureSet::getFeatureAt(int featureIndex) Feature *FeatureSet::getFeatureAt(int featureIndex)
{ {
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) { if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) {
return m_featureInstanceRegistrations[featureIndex].m_feature; return m_featureInstanceRegistrations[featureIndex];
} else{ } else{
return nullptr; return nullptr;
} }
@ -116,6 +125,7 @@ Feature *FeatureSet::getFeatureAt(int featureIndex)
void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter) void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter)
{ {
MainCore *mainCore = MainCore::instance();
qDebug("FeatureSet::loadFeatureSetSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); qDebug("FeatureSet::loadFeatureSetSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available feature plugins // Available feature plugins
@ -124,11 +134,12 @@ void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAP
// copy currently open features and clear list // copy currently open features and clear list
FeatureInstanceRegistrations openFeatures = m_featureInstanceRegistrations; FeatureInstanceRegistrations openFeatures = m_featureInstanceRegistrations;
m_featureInstanceRegistrations.clear(); m_featureInstanceRegistrations.clear();
mainCore->clearFeatures(this);
for (int i = 0; i < openFeatures.count(); i++) for (int i = 0; i < openFeatures.count(); i++)
{ {
qDebug("FeatureSet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_featureName)); qDebug("FeatureSet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i]->getURI()));
openFeatures[i].m_feature->destroy(); openFeatures[i]->destroy();
} }
qDebug("FeatureSet::loadFeatureSetSettings: %d feature(s) in preset", preset->getFeatureCount()); qDebug("FeatureSet::loadFeatureSetSettings: %d feature(s) in preset", preset->getFeatureCount());
@ -136,7 +147,7 @@ void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAP
for (int i = 0; i < preset->getFeatureCount(); i++) for (int i = 0; i < preset->getFeatureCount(); i++)
{ {
const FeatureSetPreset::FeatureConfig& featureConfig = preset->getFeatureConfig(i); const FeatureSetPreset::FeatureConfig& featureConfig = preset->getFeatureConfig(i);
FeatureInstanceRegistration reg; Feature* reg = nullptr;
// create feature instance // create feature instance
@ -149,15 +160,17 @@ void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAP
qPrintable(featureConfig.m_featureIdURI)); qPrintable(featureConfig.m_featureIdURI));
Feature *feature = Feature *feature =
(*featureRegistrations)[i].m_plugin->createFeature(apiAdapter); (*featureRegistrations)[i].m_plugin->createFeature(apiAdapter);
reg = FeatureInstanceRegistration(featureConfig.m_featureIdURI, feature); reg = feature;
m_featureInstanceRegistrations.append(feature);
mainCore->addFeatureInstance(this, feature);
break; break;
} }
} }
if (reg.m_feature) if (reg)
{ {
qDebug("FeatureSet::loadFeatureSetSettings: deserializing feature [%s]", qPrintable(featureConfig.m_featureIdURI)); qDebug("FeatureSet::loadFeatureSetSettings: deserializing feature [%s]", qPrintable(featureConfig.m_featureIdURI));
reg.m_feature->deserialize(featureConfig.m_config); reg->deserialize(featureConfig.m_config);
} }
} }
@ -166,29 +179,34 @@ void FeatureSet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAP
void FeatureSet::saveFeatureSetSettings(FeatureSetPreset *preset) void FeatureSet::saveFeatureSetSettings(FeatureSetPreset *preset)
{ {
std::sort(m_featureInstanceRegistrations.begin(), m_featureInstanceRegistrations.end()); // sort by increasing delta frequency and type std::sort(m_featureInstanceRegistrations.begin(), m_featureInstanceRegistrations.end(), compareFeatures);
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++) for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{ {
qDebug("FeatureSet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureName)); qDebug("FeatureSet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i]->getURI()));
preset->addFeature(m_featureInstanceRegistrations[i].m_featureName, m_featureInstanceRegistrations[i].m_feature->serialize()); preset->addFeature(m_featureInstanceRegistrations[i]->getURI(), m_featureInstanceRegistrations[i]->serialize());
} }
} }
void FeatureSet::addFeatureInstance(const QString& featureURI, Feature *feature) void FeatureSet::addFeatureInstance(Feature *feature)
{ {
qDebug("FeatureSet::addFeatureInstance"); m_featureInstanceRegistrations.push_back(feature);
m_featureInstanceRegistrations.push_back(FeatureInstanceRegistration(featureURI, feature)); renameFeatureInstances();
MainCore::instance()->addFeatureInstance(this, feature);
} }
void FeatureSet::removeFeatureInstanceAt(int index) void FeatureSet::removeFeatureInstanceAt(int index)
{ {
if (index < m_featureInstanceRegistrations.size()) { if (index < m_featureInstanceRegistrations.size())
{
m_featureInstanceRegistrations.removeAt(index); m_featureInstanceRegistrations.removeAt(index);
renameFeatureInstances();
MainCore::instance()->removeFeatureInstanceAt(this, index);
} }
} }
void FeatureSet::clearFeatures() void FeatureSet::clearFeatures()
{ {
m_featureInstanceRegistrations.clear(); m_featureInstanceRegistrations.clear();
MainCore::instance()->clearFeatures(this);
} }

View File

@ -35,6 +35,7 @@ public:
~FeatureSet(); ~FeatureSet();
int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); } int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); }
int getIndex() const { return m_featureTabIndex; }
void addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter); void addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter);
void removeFeatureInstance(Feature* feature); void removeFeatureInstance(Feature* feature);
void freeFeatures(); void freeFeatures();
@ -44,35 +45,18 @@ public:
void loadFeatureSetSettings(const FeatureSetPreset* preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter); void loadFeatureSetSettings(const FeatureSetPreset* preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter);
void saveFeatureSetSettings(FeatureSetPreset* preset); void saveFeatureSetSettings(FeatureSetPreset* preset);
// slave mode // slave mode
void addFeatureInstance(const QString& featureURI, Feature *feature); void addFeatureInstance(Feature *feature);
void removeFeatureInstanceAt(int index); void removeFeatureInstanceAt(int index);
void clearFeatures(); void clearFeatures();
private: private:
struct FeatureInstanceRegistration typedef QList<Feature*> FeatureInstanceRegistrations;
{
QString m_featureName;
Feature* m_feature;
FeatureInstanceRegistration() :
m_featureName(),
m_feature(nullptr)
{ }
FeatureInstanceRegistration(const QString& featureName, Feature *feature) :
m_featureName(featureName),
m_feature(feature)
{ }
bool operator<(const FeatureInstanceRegistration& other) const;
};
typedef QList<FeatureInstanceRegistration> FeatureInstanceRegistrations;
FeatureInstanceRegistrations m_featureInstanceRegistrations; FeatureInstanceRegistrations m_featureInstanceRegistrations;
int m_featureTabIndex; int m_featureTabIndex;
void renameFeatureInstances(); void renameFeatureInstances();
static bool compareFeatures(Feature *featureA, Feature *featureB);
}; };
#endif // SDRBASE_FEATURE_FEATURESET_H_ #endif // SDRBASE_FEATURE_FEATURESET_H_

View File

@ -22,7 +22,9 @@
#include "loggerwithfile.h" #include "loggerwithfile.h"
#include "dsp/dsptypes.h" #include "dsp/dsptypes.h"
#include "feature/featureset.h" #include "feature/featureset.h"
#include "feature/feature.h"
#include "device/deviceset.h" #include "device/deviceset.h"
#include "channel/channelapi.h"
#include "maincore.h" #include "maincore.h"
@ -129,19 +131,27 @@ Feature *MainCore::getFeature(int featureSetIndex, int featureIndex)
void MainCore::appendFeatureSet() void MainCore::appendFeatureSet()
{ {
int newIndex = m_featureSets.size(); int newIndex = m_featureSets.size();
m_featureSets.push_back(new FeatureSet(newIndex)); FeatureSet *featureSet = new FeatureSet(newIndex);
m_featureSets.push_back(featureSet);
m_featureSetsMap.insert(featureSet, newIndex);
} }
void MainCore::removeFeatureSet(int index) void MainCore::removeFeatureSet(int index)
{ {
if (index < m_featureSets.size()) { if (index < m_featureSets.size())
{
FeatureSet *featureSet = m_featureSets[index];
m_featureSetsMap.remove(featureSet);
m_featureSets.erase(m_featureSets.begin() + index); m_featureSets.erase(m_featureSets.begin() + index);
} }
} }
void MainCore::removeLastFeatureSet() void MainCore::removeLastFeatureSet()
{ {
if (m_featureSets.size() != 0) { if (m_featureSets.size() != 0)
{
FeatureSet *featureSet = m_featureSets.back();
m_featureSetsMap.remove(featureSet);
m_featureSets.pop_back(); m_featureSets.pop_back();
} }
} }
@ -149,12 +159,110 @@ void MainCore::removeLastFeatureSet()
void MainCore::appendDeviceSet(int deviceType) void MainCore::appendDeviceSet(int deviceType)
{ {
int newIndex = m_deviceSets.size(); int newIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(newIndex, deviceType)); DeviceSet *deviceSet = new DeviceSet(newIndex, deviceType);
m_deviceSets.push_back(deviceSet);
m_deviceSetsMap.insert(deviceSet, newIndex);
} }
void MainCore::removeLastDeviceSet() void MainCore::removeLastDeviceSet()
{ {
if (m_deviceSets.size() != 0) { if (m_deviceSets.size() != 0)
{
DeviceSet *deviceSet = m_deviceSets.back();
m_deviceSetsMap.remove(deviceSet);
m_deviceSets.pop_back(); m_deviceSets.pop_back();
} }
} }
void MainCore::addChannelInstance(DeviceSet *deviceSet, ChannelAPI *channelAPI)
{
m_channelsMap.insert(channelAPI, deviceSet);
// debugMaps();
}
void MainCore::removeChannelInstanceAt(DeviceSet *deviceSet, int channelIndex)
{
int deviceSetIndex = m_deviceSetsMap[deviceSet];
ChannelAPI *channelAPI = m_deviceSets[deviceSetIndex]->getChannelAt(channelIndex);
if (channelAPI) {
m_channelsMap.remove(channelAPI);
}
}
void MainCore::removeChannelInstance(ChannelAPI *channelAPI)
{
if (channelAPI) {
m_channelsMap.remove(channelAPI);
}
}
void MainCore::clearChannels(DeviceSet *deviceSet)
{
for (int i = 0; i < deviceSet->getNumberOfChannels(); i++)
{
ChannelAPI *channelAPI = deviceSet->getChannelAt(i);
m_channelsMap.remove(channelAPI);
}
}
void MainCore::addFeatureInstance(FeatureSet *featureSet, Feature *feature)
{
m_featuresMap.insert(feature, featureSet);
// debugMaps();
}
void MainCore::removeFeatureInstanceAt(FeatureSet *featureSet, int featureIndex)
{
int featureSetIndex = m_featureSetsMap[featureSet];
Feature *feature = m_featureSets[featureSetIndex]->getFeatureAt(featureIndex);
if (feature) {
m_featuresMap.remove(feature);
}
}
void MainCore::removeFeatureInstance(Feature *feature)
{
if (feature) {
m_featuresMap.remove(feature);
}
}
void MainCore::clearFeatures(FeatureSet *featureSet)
{
for (int i = 0; i < featureSet->getNumberOfFeatures(); i++)
{
Feature *feature = featureSet->getFeatureAt(i);
m_featuresMap.remove(feature);
}
}
void MainCore::debugMaps()
{
QMap<DeviceSet*, int>::const_iterator dsIt = m_deviceSetsMap.begin();
for (; dsIt != m_deviceSetsMap.end(); ++dsIt) {
qDebug("MainCore::debugMaps: device set %d #%d", dsIt.key()->getIndex(), dsIt.value());
}
QMap<FeatureSet*, int>::const_iterator fsIt = m_featureSetsMap.begin();
for (; fsIt != m_featureSetsMap.end(); ++fsIt) {
qDebug("MainCore::debugMaps: feature set %d #%d", fsIt.key()->getIndex(), fsIt.value());
}
QMap<ChannelAPI*, DeviceSet*>::const_iterator chIt = m_channelsMap.begin();
for (; chIt != m_channelsMap.end(); ++chIt) {
qDebug("MainCore::debugMaps: channel ds: %d - %d: %s %s",
chIt.value()->getIndex(), chIt.key()->getIndexInDeviceSet(), qPrintable(chIt.key()->getURI()), qPrintable(chIt.key()->getName()));
}
QMap<Feature*, FeatureSet*>::const_iterator feIt = m_featuresMap.begin();
for (; feIt != m_featuresMap.end(); ++feIt) {
qDebug("MainCore::debugMaps: feature fs: %d - %d: %s %s",
feIt.value()->getIndex(), feIt.key()->getIndexInFeatureSet(), qPrintable(feIt.key()->getURI()), qPrintable(feIt.key()->getName()));
}
}

View File

@ -20,6 +20,7 @@
#include <vector> #include <vector>
#include <QMap>
#include <QTimer> #include <QTimer>
#include "export.h" #include "export.h"
@ -414,12 +415,24 @@ public:
void setLoggingOptions(); void setLoggingOptions();
ChannelAPI *getChannel(int deviceSetIndex, int channelIndex); ChannelAPI *getChannel(int deviceSetIndex, int channelIndex);
Feature *getFeature(int featureSetIndex, int featureIndex); Feature *getFeature(int featureSetIndex, int featureIndex);
bool existsChannel(ChannelAPI *channel) const { return m_channelsMap.contains(channel); }
bool existsFeature(Feature *feature) const { return m_featuresMap.contains(feature); }
// slave mode // slave mode
void appendFeatureSet(); void appendFeatureSet();
void removeFeatureSet(int index); void removeFeatureSet(int index);
void removeLastFeatureSet(); void removeLastFeatureSet();
void appendDeviceSet(int deviceType); void appendDeviceSet(int deviceType);
void removeLastDeviceSet(); void removeLastDeviceSet();
// slave mode - channels
void addChannelInstance(DeviceSet *deviceSet, ChannelAPI *channelAPI);
void removeChannelInstanceAt(DeviceSet *deviceSet, int channelIndex);
void removeChannelInstance(ChannelAPI *channelAPI);
void clearChannels(DeviceSet *deviceSet);
// slave mode - features
void addFeatureInstance(FeatureSet *featureSet, Feature *feature);
void removeFeatureInstanceAt(FeatureSet *featureSet, int featureIndex);
void removeFeatureInstance(Feature *feature);
void clearFeatures(FeatureSet *featureSet);
friend class MainServer; friend class MainServer;
friend class MainWindow; friend class MainWindow;
@ -433,7 +446,13 @@ private:
QTimer m_masterTimer; QTimer m_masterTimer;
std::vector<DeviceSet*> m_deviceSets; std::vector<DeviceSet*> m_deviceSets;
std::vector<FeatureSet*> m_featureSets; std::vector<FeatureSet*> m_featureSets;
QMap<DeviceSet*, int> m_deviceSetsMap; //!< Device set instance to device set index map
QMap<FeatureSet*, int> m_featureSetsMap; //!< Feature set instance to feature set index map
QMap<ChannelAPI*, DeviceSet*> m_channelsMap; //!< Channel to device set map
QMap<Feature*, FeatureSet*> m_featuresMap; //!< Feature to feature set map
PluginManager* m_pluginManager; PluginManager* m_pluginManager;
void debugMaps();
}; };
#endif // SDRBASE_MAINCORE_H_ #endif // SDRBASE_MAINCORE_H_

View File

@ -43,10 +43,10 @@ void FeatureUISet::addRollupWidget(QWidget *widget)
m_featureWindow->addRollupWidget(widget); m_featureWindow->addRollupWidget(widget);
} }
void FeatureUISet::registerFeatureInstance(const QString& featureURI, FeatureGUI* featureGUI, Feature *feature) void FeatureUISet::registerFeatureInstance(FeatureGUI* featureGUI, Feature *feature)
{ {
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureURI, featureGUI, feature)); m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureGUI, feature));
m_featureSet->addFeatureInstance(featureURI, feature); m_featureSet->addFeatureInstance(feature);
QObject::connect( QObject::connect(
featureGUI, featureGUI,
&FeatureGUI::closing, &FeatureGUI::closing,
@ -70,7 +70,7 @@ void FeatureUISet::freeFeatures()
{ {
for(int i = 0; i < m_featureInstanceRegistrations.count(); i++) for(int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{ {
qDebug("FeatureUISet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI)); qDebug("FeatureUISet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_feature->getURI()));
m_featureInstanceRegistrations[i].m_gui->destroy(); m_featureInstanceRegistrations[i].m_gui->destroy();
m_featureInstanceRegistrations[i].m_feature->destroy(); m_featureInstanceRegistrations[i].m_feature->destroy();
} }
@ -83,7 +83,7 @@ void FeatureUISet::deleteFeature(int featureIndex)
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count()))
{ {
qDebug("FeatureUISet::deleteFeature: delete feature [%s] at %d", qDebug("FeatureUISet::deleteFeature: delete feature [%s] at %d",
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureURI), qPrintable(m_featureInstanceRegistrations[featureIndex].m_feature->getURI()),
featureIndex); featureIndex);
m_featureInstanceRegistrations[featureIndex].m_gui->destroy(); m_featureInstanceRegistrations[featureIndex].m_gui->destroy();
m_featureInstanceRegistrations[featureIndex].m_feature->destroy(); m_featureInstanceRegistrations[featureIndex].m_feature->destroy();
@ -123,7 +123,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
for (int i = 0; i < openFeatures.count(); i++) for (int i = 0; i < openFeatures.count(); i++)
{ {
qDebug("FeatureUISet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_featureURI)); qDebug("FeatureUISet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_feature->getURI()));
openFeatures[i].m_gui->destroy(); openFeatures[i].m_gui->destroy();
openFeatures[i].m_feature->destroy(); openFeatures[i].m_feature->destroy();
} }
@ -148,7 +148,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
(*featureRegistrations)[i].m_plugin->createFeature(apiAdapter); (*featureRegistrations)[i].m_plugin->createFeature(apiAdapter);
featureGUI = featureGUI =
(*featureRegistrations)[i].m_plugin->createFeatureGUI(this, feature); (*featureRegistrations)[i].m_plugin->createFeatureGUI(this, feature);
registerFeatureInstance(feature->getURI(), featureGUI, feature); registerFeatureInstance(featureGUI, feature);
break; break;
} }
} }
@ -167,8 +167,8 @@ void FeatureUISet::saveFeatureSetSettings(FeatureSetPreset *preset)
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++) for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{ {
qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI)); qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_feature->getURI()));
preset->addFeature(m_featureInstanceRegistrations[i].m_featureURI, m_featureInstanceRegistrations[i].m_gui->serialize()); preset->addFeature(m_featureInstanceRegistrations[i].m_feature->getURI(), m_featureInstanceRegistrations[i].m_gui->serialize());
} }
} }

View File

@ -42,7 +42,7 @@ public:
void addRollupWidget(QWidget *widget); //!< Add feature rollup widget to feature window void addRollupWidget(QWidget *widget); //!< Add feature rollup widget to feature window
int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); } int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); }
void registerFeatureInstance(const QString& featureURI, FeatureGUI* featureGUI, Feature *feature); void registerFeatureInstance(FeatureGUI* featureGUI, Feature *feature);
void deleteFeature(int featureIndex); void deleteFeature(int featureIndex);
const Feature *getFeatureAt(int featureIndex) const; const Feature *getFeatureAt(int featureIndex) const;
Feature *getFeatureAt(int featureIndex); Feature *getFeatureAt(int featureIndex);
@ -54,18 +54,15 @@ public:
private: private:
struct FeatureInstanceRegistration struct FeatureInstanceRegistration
{ {
QString m_featureURI;
FeatureGUI* m_gui; FeatureGUI* m_gui;
Feature* m_feature; Feature* m_feature;
FeatureInstanceRegistration() : FeatureInstanceRegistration() :
m_featureURI(),
m_gui(nullptr), m_gui(nullptr),
m_feature(nullptr) m_feature(nullptr)
{ } { }
FeatureInstanceRegistration(const QString& featureURI, FeatureGUI* pluginGUI, Feature *feature) : FeatureInstanceRegistration(FeatureGUI* pluginGUI, Feature *feature) :
m_featureURI(featureURI),
m_gui(pluginGUI), m_gui(pluginGUI),
m_feature(feature) m_feature(feature)
{ } { }

View File

@ -1982,7 +1982,7 @@ void MainWindow::featureAddClicked(int featureIndex)
PluginInterface *pluginInterface = (*featureRegistrations)[featureIndex].m_plugin; PluginInterface *pluginInterface = (*featureRegistrations)[featureIndex].m_plugin;
Feature *feature = pluginInterface->createFeature(m_apiAdapter); Feature *feature = pluginInterface->createFeature(m_apiAdapter);
FeatureGUI *gui = pluginInterface->createFeatureGUI(featureUISet, feature); FeatureGUI *gui = pluginInterface->createFeatureGUI(featureUISet, feature);
featureUISet->registerFeatureInstance(feature->getURI(), gui, feature); featureUISet->registerFeatureInstance(gui, feature);
} }
} }