From 48ed11331a8b58d25b12f9733420617d002344b9 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 13 Oct 2020 08:15:21 +0200 Subject: [PATCH] MainCore: methods to get channel API and feature --- sdrbase/device/deviceset.cpp | 18 ++++++++++++++ sdrbase/device/deviceset.h | 7 ++++++ sdrbase/maincore.cpp | 18 ++++++++++++++ sdrbase/maincore.h | 4 +++ sdrsrv/mainserver.cpp | 48 ++++++++++++++++++------------------ 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/sdrbase/device/deviceset.cpp b/sdrbase/device/deviceset.cpp index c816ccc55..88d5826fd 100644 --- a/sdrbase/device/deviceset.cpp +++ b/sdrbase/device/deviceset.cpp @@ -58,6 +58,24 @@ void DeviceSet::freeChannels() } } +const ChannelAPI *DeviceSet::getChannelAt(int channelIndex) const +{ + if ((channelIndex >= 0) && (channelIndex < m_channelInstanceRegistrations.size())) { + return m_channelInstanceRegistrations[channelIndex].m_channelAPI; + } else { + return nullptr; + } +} + +ChannelAPI *DeviceSet::getChannelAt(int channelIndex) +{ + if ((channelIndex >= 0) && (channelIndex < m_channelInstanceRegistrations.size())) { + return m_channelInstanceRegistrations[channelIndex].m_channelAPI; + } else { + return nullptr; + } +} + void DeviceSet::deleteChannel(int channelIndex) { if (channelIndex < m_channelInstanceRegistrations.count()) diff --git a/sdrbase/device/deviceset.h b/sdrbase/device/deviceset.h index 40dbd1a37..7a1fa849a 100644 --- a/sdrbase/device/deviceset.h +++ b/sdrbase/device/deviceset.h @@ -43,6 +43,8 @@ public: int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); } void freeChannels(); + const ChannelAPI *getChannelAt(int channelIndex) const; + ChannelAPI *getChannelAt(int channelIndex); void deleteChannel(int channelIndex); void loadRxChannelSettings(const Preset* preset, PluginAPI *pluginAPI); void saveRxChannelSettings(Preset* preset); @@ -72,6 +74,11 @@ private: ChannelInstanceRegistration(const QString& channelName, ChannelAPI* channelAPI); + ChannelInstanceRegistration(const ChannelInstanceRegistration& other) : + m_channelName(other.m_channelName), + m_channelAPI(other.m_channelAPI) + { } + bool operator<(const ChannelInstanceRegistration& other) const; }; diff --git a/sdrbase/maincore.cpp b/sdrbase/maincore.cpp index f640f9211..4ab638ea9 100644 --- a/sdrbase/maincore.cpp +++ b/sdrbase/maincore.cpp @@ -108,6 +108,24 @@ void MainCore::setLoggingOptions() } } +ChannelAPI *MainCore::getChannel(int deviceSetIndex, int channelIndex) +{ + if ((deviceSetIndex >= 0) && (deviceSetIndex < m_deviceSets.size())) { + return m_deviceSets[deviceSetIndex]->getChannelAt(channelIndex); + } else { + return nullptr; + } +} + +Feature *MainCore::getFeature(int featureSetIndex, int featureIndex) +{ + if ((featureSetIndex >= 0) && (featureSetIndex < m_featureSets.size())) { + return m_featureSets[featureSetIndex]->getFeatureAt(featureIndex); + } else { + return nullptr; + } +} + void MainCore::appendFeatureSet() { int newIndex = m_featureSets.size(); diff --git a/sdrbase/maincore.h b/sdrbase/maincore.h index 1a3531a3b..46bd6cc36 100644 --- a/sdrbase/maincore.h +++ b/sdrbase/maincore.h @@ -28,6 +28,8 @@ class DeviceSet; class FeatureSet; +class ChannelAPI; +class Feature; class PluginManager; class MessageQueue; @@ -410,6 +412,8 @@ public: std::vector& getDeviceSets() { return m_deviceSets; } std::vector& getFeatureeSets() { return m_featureSets; } void setLoggingOptions(); + ChannelAPI *getChannel(int deviceSetIndex, int channelIndex); + Feature *getFeature(int featureSetIndex, int featureIndex); // slave mode void appendFeatureSet(); void removeFeatureSet(int index); diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index f4be1dd94..5fb2dce41 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -278,24 +278,24 @@ void MainServer::addSinkDevice() // create a file sink by default int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileOutputDeviceIndex(); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex)); + deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); + deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); + deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); + deviceAPI->setHardwareId(samplingDevice->hardwareId); + deviceAPI->setSamplingDeviceId(samplingDevice->id); + deviceAPI->setSamplingDeviceSerial(samplingDevice->serial); + deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName); + deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex)); QString userArgs = m_mainCore->m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence); if (userArgs.size() > 0) { - m_mainCore->m_deviceSets.back()->m_deviceAPI->setHardwareUserArguments(userArgs); + deviceAPI->setHardwareUserArguments(userArgs); } - DeviceSampleSink *sink = m_mainCore->m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSinkPluginInstance( - m_mainCore->m_deviceSets.back()->m_deviceAPI->getSamplingDeviceId(), m_mainCore->m_deviceSets.back()->m_deviceAPI); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSampleSink(sink); + DeviceSampleSink *sink = deviceAPI->getPluginInterface()->createSampleSinkPluginInstance( + deviceAPI->getSamplingDeviceId(), deviceAPI); + deviceAPI->setSampleSink(sink); } void MainServer::addSourceDevice() @@ -323,24 +323,24 @@ void MainServer::addSourceDevice() // Create a file source instance by default int fileSourceDeviceIndex = DeviceEnumerator::instance()->getFileInputDeviceIndex(); const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(fileSourceDeviceIndex); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(fileSourceDeviceIndex)); + deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence); + deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems); + deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex); + deviceAPI->setHardwareId(samplingDevice->hardwareId); + deviceAPI->setSamplingDeviceId(samplingDevice->id); + deviceAPI->setSamplingDeviceSerial(samplingDevice->serial); + deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName); + deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(fileSourceDeviceIndex)); QString userArgs = m_mainCore->m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence); if (userArgs.size() > 0) { - m_mainCore->m_deviceSets.back()->m_deviceAPI->setHardwareUserArguments(userArgs); + deviceAPI->setHardwareUserArguments(userArgs); } - DeviceSampleSource *source = m_mainCore->m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstance( - m_mainCore->m_deviceSets.back()->m_deviceAPI->getSamplingDeviceId(), m_mainCore->m_deviceSets.back()->m_deviceAPI); - m_mainCore->m_deviceSets.back()->m_deviceAPI->setSampleSource(source); + DeviceSampleSource *source = deviceAPI->getPluginInterface()->createSampleSourcePluginInstance( + deviceAPI->getSamplingDeviceId(), deviceAPI); + deviceAPI->setSampleSource(source); } void MainServer::removeLastDevice()