From 462eb90f66bb36fe08fcea1e1fdb69773571f0de Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 1 Nov 2017 13:03:12 +0100 Subject: [PATCH] Methods to determine if a device is buit in or physical --- sdrbase/CMakeLists.txt | 2 ++ sdrbase/sdrbase.pro | 4 +++- sdrgui/device/deviceuiset.cpp | 4 ++-- sdrgui/plugin/pluginapi.cpp | 4 ++++ sdrgui/plugin/pluginapi.h | 9 ++++++--- sdrgui/plugin/pluginmanager.cpp | 25 +++++++++++++++++++------ sdrgui/plugin/pluginmanager.h | 18 ++++++++++++------ 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index 3641e6418..4bc2edf0a 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -45,6 +45,7 @@ set(sdrbase_SOURCES device/devicesourceapi.cpp device/devicesinkapi.cpp +# device/deviceenumerator.cpp settings/preferences.cpp settings/preset.cpp @@ -124,6 +125,7 @@ set(sdrbase_HEADERS device/devicesourceapi.h device/devicesinkapi.h +# device/deviceenumerator.h plugin/plugininstancegui.h plugin/plugininterface.h diff --git a/sdrbase/sdrbase.pro b/sdrbase/sdrbase.pro index c03ca0c14..8be9677ba 100644 --- a/sdrbase/sdrbase.pro +++ b/sdrbase/sdrbase.pro @@ -50,7 +50,8 @@ SOURCES += audio/audiodeviceinfo.cpp\ audio/audiooutput.cpp\ audio/audioinput.cpp\ device/devicesourceapi.cpp\ - device/devicesinkapi.cpp\ + device/devicesinkapi.cpp\ + device/deviceenumerator.cpp\ dsp/afsquelch.cpp\ dsp/agc.cpp\ dsp/downchannelizer.cpp\ @@ -107,6 +108,7 @@ HEADERS += audio/audiodeviceinfo.h\ audio/audioinput.h\ device/devicesourceapi.h\ device/devicesinkapi.h\ + device/deviceenumerator.h\ dsp/afsquelch.h\ dsp/downchannelizer.h\ dsp/upchannelizer.h\ diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index b09659d1c..b3534dd63 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -172,7 +172,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA { for(int i = 0; i < channelRegistrations->count(); i++) { - if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel) + if((*channelRegistrations)[i].m_channelId == channelConfig.m_channel) { qDebug("DeviceUISet::loadChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); reg = ChannelInstanceRegistration( @@ -270,7 +270,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA { for(int i = 0; i < channelRegistrations->count(); i++) { - if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel) + if((*channelRegistrations)[i].m_channelId == channelConfig.m_channel) { qDebug("DeviceUISet::loadChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); reg = ChannelInstanceRegistration(channelConfig.m_channel, (*channelRegistrations)[i].m_plugin->createTxChannel(channelConfig.m_channel, this)); diff --git a/sdrgui/plugin/pluginapi.cpp b/sdrgui/plugin/pluginapi.cpp index 6f8d32c41..eb19aa64b 100644 --- a/sdrgui/plugin/pluginapi.cpp +++ b/sdrgui/plugin/pluginapi.cpp @@ -31,6 +31,10 @@ PluginAPI::ChannelRegistrations *PluginAPI::getTxChannelRegistrations() return m_pluginManager->getTxChannelRegistrations(); } +bool PluginAPI::isBuiltInDevice(QString& deviceTypeID) +{ + return m_pluginManager->isBuiltInDevice(deviceTypeID); +} PluginAPI::PluginAPI(PluginManager* pluginManager) : m_pluginManager(pluginManager) diff --git a/sdrgui/plugin/pluginapi.h b/sdrgui/plugin/pluginapi.h index 76af7e80f..6e559e8bf 100644 --- a/sdrgui/plugin/pluginapi.h +++ b/sdrgui/plugin/pluginapi.h @@ -19,10 +19,10 @@ class SDRANGEL_API PluginAPI : public QObject { public: struct ChannelRegistration { - QString m_channelName; + QString m_channelId; //!< Channel or device type ID PluginInterface* m_plugin; - ChannelRegistration(const QString& channelName, PluginInterface* plugin) : - m_channelName(channelName), + ChannelRegistration(const QString& channelId, PluginInterface* plugin) : + m_channelId(channelId), m_plugin(plugin) { } }; @@ -43,6 +43,9 @@ public: // Sample Sink stuff void registerSampleSink(const QString& sinkName, PluginInterface* plugin); + // Categories enquiry + bool isBuiltInDevice(QString& deviceTypeID); + protected: PluginManager* m_pluginManager; diff --git a/sdrgui/plugin/pluginmanager.cpp b/sdrgui/plugin/pluginmanager.cpp index cae4c42af..0f747cfc9 100644 --- a/sdrgui/plugin/pluginmanager.cpp +++ b/sdrgui/plugin/pluginmanager.cpp @@ -31,10 +31,14 @@ #include "plugin/pluginmanager.h" -const QString PluginManager::m_sdrDaemonHardwareID = "SDRdaemonSource"; -const QString PluginManager::m_sdrDaemonDeviceTypeID = "sdrangel.samplesource.sdrdaemonsource"; +const QString PluginManager::m_sdrDaemonSourceHardwareID = "SDRdaemonSource"; +const QString PluginManager::m_sdrDaemonSourceDeviceTypeID = "sdrangel.samplesource.sdrdaemonsource"; const QString PluginManager::m_fileSourceHardwareID = "FileSource"; const QString PluginManager::m_fileSourceDeviceTypeID = "sdrangel.samplesource.filesource"; + +const QString PluginManager::m_sdrDaemonSinkHardwareID = "SDRdaemonSink"; +const QString PluginManager::m_sdrDaemonSinkDeviceTypeID = "sdrangel.samplesink.sdrdaemonsink"; +const QString PluginManager::m_fileSinkHardwareID = "FileSink"; const QString PluginManager::m_fileSinkDeviceTypeID = "sdrangel.samplesink.filesink"; PluginManager::PluginManager(QObject* parent) : @@ -172,7 +176,7 @@ void PluginManager::duplicateLocalSampleSourceDevices(uint deviceUID) for(int i = 0; i < m_sampleSourceDevices.count(); ++i) { - if (m_sampleSourceDevices[i].m_deviceId == m_sdrDaemonDeviceTypeID) // SDRdaemon + if (m_sampleSourceDevices[i].m_deviceId == m_sdrDaemonSourceDeviceTypeID) // SDRdaemon { if (m_sampleSourceDevices[i].m_deviceSequence == 0) { // reference to device 0 sdrDaemonSSD0 = &m_sampleSourceDevices[i]; @@ -265,7 +269,7 @@ void PluginManager::fillSampleSourceSelector(QComboBox* comboBox, uint deviceUID for(int i = 0; i < m_sampleSourceDevices.count(); i++) { // For "local" devices show only ones that concern this device set - if ((m_sampleSourceDevices[i].m_deviceId == m_sdrDaemonDeviceTypeID) + if ((m_sampleSourceDevices[i].m_deviceId == m_sdrDaemonSourceDeviceTypeID) || (m_sampleSourceDevices[i].m_deviceId == m_fileSourceDeviceTypeID)) { if (deviceUID != m_sampleSourceDevices[i].m_deviceSequence) { @@ -627,7 +631,7 @@ void PluginManager::createRxChannelInstance(int channelPluginIndex, DeviceUISet if (channelPluginIndex < m_rxChannelRegistrations.size()) { PluginInterface *pluginInterface = m_rxChannelRegistrations[channelPluginIndex].m_plugin; - pluginInterface->createRxChannel(m_rxChannelRegistrations[channelPluginIndex].m_channelName, deviceUISet); + pluginInterface->createRxChannel(m_rxChannelRegistrations[channelPluginIndex].m_channelId, deviceUISet); } } @@ -636,6 +640,15 @@ void PluginManager::createTxChannelInstance(int channelPluginIndex, DeviceUISet if (channelPluginIndex < m_txChannelRegistrations.size()) { PluginInterface *pluginInterface = m_txChannelRegistrations[channelPluginIndex].m_plugin; - pluginInterface->createTxChannel(m_txChannelRegistrations[channelPluginIndex].m_channelName, deviceUISet); + pluginInterface->createTxChannel(m_txChannelRegistrations[channelPluginIndex].m_channelId, deviceUISet); } } + +bool PluginManager::isBuiltInDevice(QString& deviceTypeID) +{ + return ((deviceTypeID == m_fileSourceDeviceTypeID) || + (deviceTypeID == m_fileSinkDeviceTypeID) || + (deviceTypeID == m_sdrDaemonSourceDeviceTypeID) || + (deviceTypeID == m_sdrDaemonSinkDeviceTypeID)); +} + diff --git a/sdrgui/plugin/pluginmanager.h b/sdrgui/plugin/pluginmanager.h index 8516ef317..dae139fce 100644 --- a/sdrgui/plugin/pluginmanager.h +++ b/sdrgui/plugin/pluginmanager.h @@ -79,8 +79,11 @@ public: void createTxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet); void listTxChannels(QList& list); + bool isBuiltInDevice(QString& deviceTypeID); + private: - struct SamplingDeviceRegistration { + struct SamplingDeviceRegistration //!< This is the channel registration + { QString m_deviceId; PluginInterface* m_plugin; SamplingDeviceRegistration(const QString& deviceId, PluginInterface* plugin) : @@ -91,7 +94,7 @@ private: typedef QList SamplingDeviceRegistrations; - struct SamplingDevice { + struct SamplingDevice { //!< This is the device registration PluginInterface* m_plugin; QString m_displayName; QString m_hadrwareId; @@ -128,12 +131,15 @@ private: SamplingDevices m_sampleSinkDevices; //!< Instances of output sinks present in the system // "Local" sample source device IDs - static const QString m_sdrDaemonHardwareID; //!< SDRdaemon hardware ID - static const QString m_sdrDaemonDeviceTypeID; //!< SDRdaemon source plugin ID - static const QString m_fileSourceHardwareID; //!< FileSource source hardware ID - static const QString m_fileSourceDeviceTypeID; //!< FileSource source plugin ID + static const QString m_sdrDaemonSourceHardwareID; //!< SDRdaemon source hardware ID + static const QString m_sdrDaemonSourceDeviceTypeID; //!< SDRdaemon source plugin ID + static const QString m_fileSourceHardwareID; //!< FileSource source hardware ID + static const QString m_fileSourceDeviceTypeID; //!< FileSource source plugin ID // "Local" sample sink device IDs + static const QString m_sdrDaemonSinkHardwareID; //!< SDRdaemon source hardware ID + static const QString m_sdrDaemonSinkDeviceTypeID; //!< SDRdaemon source plugin ID + static const QString m_fileSinkHardwareID; //!< FileSource source hardware ID static const QString m_fileSinkDeviceTypeID; //!< FileSink sink plugin ID void loadPlugins(const QDir& dir);