From 3fb4af82e69f53d59f868b93dbf1a3ec113bdcfc Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 4 Dec 2017 23:07:30 +0100 Subject: [PATCH] Web API: implement devicesetDeviceGet (2) --- sdrbase/dsp/devicesamplesink.h | 5 +++++ sdrbase/dsp/devicesamplesource.h | 5 +++++ sdrbase/webapi/webapiadapterinterface.h | 1 + sdrbase/webapi/webapirequestmapper.cpp | 1 + sdrgui/webapi/webapiadaptergui.cpp | 25 +++++++++---------------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/sdrbase/dsp/devicesamplesink.h b/sdrbase/dsp/devicesamplesink.h index 2d33515e4..0450b585b 100644 --- a/sdrbase/dsp/devicesamplesink.h +++ b/sdrbase/dsp/devicesamplesink.h @@ -25,6 +25,11 @@ #include "util/messagequeue.h" #include "util/export.h" +namespace SWGSDRangel +{ + class SWGObject; +} + class SDRANGEL_API DeviceSampleSink : public QObject { Q_OBJECT public: diff --git a/sdrbase/dsp/devicesamplesource.h b/sdrbase/dsp/devicesamplesource.h index f44c7272e..688f689aa 100644 --- a/sdrbase/dsp/devicesamplesource.h +++ b/sdrbase/dsp/devicesamplesource.h @@ -25,6 +25,11 @@ #include "util/messagequeue.h" #include "util/export.h" +namespace SWGSDRangel +{ + class SWGObject; +} + class SDRANGEL_API DeviceSampleSource : public QObject { Q_OBJECT public: diff --git a/sdrbase/webapi/webapiadapterinterface.h b/sdrbase/webapi/webapiadapterinterface.h index 3b16545ab..3eea06e56 100644 --- a/sdrbase/webapi/webapiadapterinterface.h +++ b/sdrbase/webapi/webapiadapterinterface.h @@ -38,6 +38,7 @@ namespace SWGSDRangel class SWGDeviceSetList; class SWGDeviceSet; class SWGDeviceListItem; + class SWGDeviceSettings; class SWGErrorResponse; } diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 2aebe28fe..ed6f79f26 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -34,6 +34,7 @@ #include "SWGPresets.h" #include "SWGPresetTransfer.h" #include "SWGPresetIdentifier.h" +#include "SWGDeviceSettings.h" #include "SWGErrorResponse.h" WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 56b7fdad7..4d9970ccd 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -50,6 +50,7 @@ #include "SWGPresetItem.h" #include "SWGPresetTransfer.h" #include "SWGPresetIdentifier.h" +#include "SWGDeviceSettings.h" #include "SWGErrorResponse.h" #include "webapiadaptergui.h" @@ -698,33 +699,25 @@ int WebAPIAdapterGUI::devicesetDeviceGet( SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { - if ((deviceSetIndex >= 0) && (m_mainWindow.m_deviceUIs < (int) m_mainWindow.m_deviceUIs.size())) + if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size())) { DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex]; - int tx = response.getTx(); - if ((tx == 0) && (deviceSet->m_deviceSinkEngine)) - { - *error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch"); - return 404; - } - - if ((tx != 0) && (deviceSet->m_deviceSourceEngine)) - { - *error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch"); - return 404; - } - - if (tx == 0) // Rx + if (deviceSet->m_deviceSourceEngine) // Rx { DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource(); return source->webapiSettingsGet(response.getData(), *error.getMessage()); } - else // Tx + else if (deviceSet->m_deviceSinkEngine) // Tx { DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink(); return sink->webapiSettingsGet(response.getData(), *error.getMessage()); } + else + { + *error.getMessage() = QString("DeviceSet error"); + return 500; + } } else {