diff --git a/devices/soapysdr/CMakeLists.txt b/devices/soapysdr/CMakeLists.txt
index 57f627bd9..5ee756732 100644
--- a/devices/soapysdr/CMakeLists.txt
+++ b/devices/soapysdr/CMakeLists.txt
@@ -3,10 +3,12 @@ project(soapysdrdevice)
set (CMAKE_CXX_STANDARD 11)
set(soapysdrdevice_SOURCES
+ devicesoapysdr.cpp
devicesoapysdrscan.cpp
)
set(soapysdrdevice_HEADERS
+ devicesoapysdr.h
devicesoapysdrscan.h
)
diff --git a/devices/soapysdr/devicesoapysdr.cpp b/devices/soapysdr/devicesoapysdr.cpp
new file mode 100644
index 000000000..6cb06b258
--- /dev/null
+++ b/devices/soapysdr/devicesoapysdr.cpp
@@ -0,0 +1,68 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2018 Edouard Griffiths, F4EXB //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation as version 3 of the License, or //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License V3 for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#include "devicesoapysdr.h"
+
+DeviceSoapySDR::DeviceSoapySDR()
+{
+ m_scanner.scan();
+}
+
+DeviceSoapySDR::~DeviceSoapySDR()
+{}
+
+DeviceSoapySDR& DeviceSoapySDR::instance()
+{
+ static DeviceSoapySDR inst;
+ return inst;
+}
+
+SoapySDR::Device *DeviceSoapySDR::openSoapySDR(uint32_t sequence)
+{
+ instance();
+ return openopenSoapySDRFromSequence(sequence);
+}
+
+SoapySDR::Device *DeviceSoapySDR::openopenSoapySDRFromSequence(uint32_t sequence)
+{
+ if (sequence > m_scanner.getNbDevices())
+ {
+ return 0;
+ }
+ else
+ {
+ const DeviceSoapySDRScan::SoapySDRDeviceEnum& deviceEnum = m_scanner.getDevicesEnumeration()[sequence];
+
+ try
+ {
+ SoapySDR::Kwargs kwargs;
+ kwargs["driver"] = deviceEnum.m_driverName.toStdString();
+
+ if (deviceEnum.m_idKey.size() > 0) {
+ kwargs[deviceEnum.m_idKey.toStdString()] = deviceEnum.m_idValue.toStdString();
+ }
+
+ SoapySDR::Device *device = SoapySDR::Device::make(kwargs);
+ return device;
+ }
+ catch (const std::exception &ex)
+ {
+ qWarning("DeviceSoapySDR::openopenSoapySDRFromSequence: %s cannot be opened: %s",
+ deviceEnum.m_label.toStdString().c_str(), ex.what());
+ return 0;
+ }
+ }
+}
diff --git a/devices/soapysdr/devicesoapysdr.h b/devices/soapysdr/devicesoapysdr.h
new file mode 100644
index 000000000..95e0b0d64
--- /dev/null
+++ b/devices/soapysdr/devicesoapysdr.h
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2018 Edouard Griffiths, F4EXB //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation as version 3 of the License, or //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License V3 for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_
+#define DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_
+
+#include
+#include
+
+#include "export.h"
+#include "devicesoapysdrscan.h"
+
+class DEVICES_API DeviceSoapySDR
+{
+public:
+ static DeviceSoapySDR& instance();
+ SoapySDR::Device *openSoapySDR(uint32_t sequence);
+
+ uint32_t getNbDevices() const { return m_scanner.getNbDevices(); }
+ const std::vector& getDevicesEnumeration() const { return m_scanner.getDevicesEnumeration(); }
+
+protected:
+ DeviceSoapySDR();
+ DeviceSoapySDR(const DeviceSoapySDR&) {}
+ DeviceSoapySDR& operator=(const DeviceSoapySDR& other __attribute__((unused))) { return *this; }
+ ~DeviceSoapySDR();
+
+private:
+ SoapySDR::Device *openopenSoapySDRFromSequence(uint32_t sequence);
+ DeviceSoapySDRScan m_scanner;
+};
+
+#endif /* DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_ */
diff --git a/plugins/samplesource/soapysdrinput/soapysdrinputplugin.cpp b/plugins/samplesource/soapysdrinput/soapysdrinputplugin.cpp
index 690457e02..0c1afccf4 100644
--- a/plugins/samplesource/soapysdrinput/soapysdrinputplugin.cpp
+++ b/plugins/samplesource/soapysdrinput/soapysdrinputplugin.cpp
@@ -18,7 +18,7 @@
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "device/devicesourceapi.h"
-#include "soapysdr/devicesoapysdrscan.h"
+#include "soapysdr/devicesoapysdr.h"
#include "soapysdrinputplugin.h"
@@ -58,9 +58,8 @@ void SoapySDRInputPlugin::initPlugin(PluginAPI* pluginAPI)
PluginInterface::SamplingDevices SoapySDRInputPlugin::enumSampleSources()
{
SamplingDevices result;
- DeviceSoapySDRScan scanner;
- scanner.scan();
- const std::vector& devicesEnumeration = scanner.getDevicesEnumeration();
+ DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
+ const std::vector& devicesEnumeration = deviceSoapySDR.getDevicesEnumeration();
qDebug("SoapySDRInputPlugin::enumSampleSources: found %lu devices", devicesEnumeration.size());
std::vector::const_iterator it = devicesEnumeration.begin();