1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 05:41:56 -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
{
return m_deviceAPI->getNbSinkStreams();
}
}

View File

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

View File

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

View File

@ -132,6 +132,8 @@ public:
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; }
FeatureState getState() const { return m_state; }
const QString& getErrorMessage() const { return m_errorMessage; }
@ -155,6 +157,7 @@ protected slots:
private:
QString m_name;
uint64_t m_uid;
int m_indexInFeatureSet;
};
#endif // SDRBASE_FETURE_FEATUREAPI_H_

View File

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

View File

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

View File

@ -22,7 +22,9 @@
#include "loggerwithfile.h"
#include "dsp/dsptypes.h"
#include "feature/featureset.h"
#include "feature/feature.h"
#include "device/deviceset.h"
#include "channel/channelapi.h"
#include "maincore.h"
@ -129,19 +131,27 @@ Feature *MainCore::getFeature(int featureSetIndex, int featureIndex)
void MainCore::appendFeatureSet()
{
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)
{
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);
}
}
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();
}
}
@ -149,12 +159,110 @@ void MainCore::removeLastFeatureSet()
void MainCore::appendDeviceSet(int deviceType)
{
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()
{
if (m_deviceSets.size() != 0) {
if (m_deviceSets.size() != 0)
{
DeviceSet *deviceSet = m_deviceSets.back();
m_deviceSetsMap.remove(deviceSet);
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 <QMap>
#include <QTimer>
#include "export.h"
@ -414,12 +415,24 @@ public:
void setLoggingOptions();
ChannelAPI *getChannel(int deviceSetIndex, int channelIndex);
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
void appendFeatureSet();
void removeFeatureSet(int index);
void removeLastFeatureSet();
void appendDeviceSet(int deviceType);
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 MainWindow;
@ -433,7 +446,13 @@ private:
QTimer m_masterTimer;
std::vector<DeviceSet*> m_deviceSets;
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;
void debugMaps();
};
#endif // SDRBASE_MAINCORE_H_

View File

@ -43,10 +43,10 @@ void FeatureUISet::addRollupWidget(QWidget *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_featureSet->addFeatureInstance(featureURI, feature);
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureGUI, feature));
m_featureSet->addFeatureInstance(feature);
QObject::connect(
featureGUI,
&FeatureGUI::closing,
@ -70,7 +70,7 @@ void FeatureUISet::freeFeatures()
{
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_feature->destroy();
}
@ -83,7 +83,7 @@ void FeatureUISet::deleteFeature(int featureIndex)
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count()))
{
qDebug("FeatureUISet::deleteFeature: delete feature [%s] at %d",
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureURI),
qPrintable(m_featureInstanceRegistrations[featureIndex].m_feature->getURI()),
featureIndex);
m_featureInstanceRegistrations[featureIndex].m_gui->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++)
{
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_feature->destroy();
}
@ -148,7 +148,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
(*featureRegistrations)[i].m_plugin->createFeature(apiAdapter);
featureGUI =
(*featureRegistrations)[i].m_plugin->createFeatureGUI(this, feature);
registerFeatureInstance(feature->getURI(), featureGUI, feature);
registerFeatureInstance(featureGUI, feature);
break;
}
}
@ -167,8 +167,8 @@ void FeatureUISet::saveFeatureSetSettings(FeatureSetPreset *preset)
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{
qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI));
preset->addFeature(m_featureInstanceRegistrations[i].m_featureURI, m_featureInstanceRegistrations[i].m_gui->serialize());
qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_feature->getURI()));
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
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);
const Feature *getFeatureAt(int featureIndex) const;
Feature *getFeatureAt(int featureIndex);
@ -54,18 +54,15 @@ public:
private:
struct FeatureInstanceRegistration
{
QString m_featureURI;
FeatureGUI* m_gui;
Feature* m_feature;
FeatureInstanceRegistration() :
m_featureURI(),
m_gui(nullptr),
m_feature(nullptr)
{ }
FeatureInstanceRegistration(const QString& featureURI, FeatureGUI* pluginGUI, Feature *feature) :
m_featureURI(featureURI),
FeatureInstanceRegistration(FeatureGUI* pluginGUI, Feature *feature) :
m_gui(pluginGUI),
m_feature(feature)
{ }

View File

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