1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-08-04 06:52:26 -04:00

Web API: have /sdrangel/deviceset/{deviceSetIndex}/device/settings URL in its own right

This commit is contained in:
f4exb 2017-12-06 22:08:34 +01:00
parent fc4627f82e
commit f9794c7701
16 changed files with 1989 additions and 2169 deletions

View File

@ -1,5 +1,7 @@
project(filesource) project(filesource)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(filesource_SOURCES set(filesource_SOURCES
filesourcegui.cpp filesourcegui.cpp
filesourceinput.cpp filesourceinput.cpp

View File

@ -1011,9 +1011,6 @@ margin-bottom: 20px;
}, },
"devicesetlist" : { "devicesetlist" : {
"$ref" : "#/definitions/DeviceSetList" "$ref" : "#/definitions/DeviceSetList"
},
"user" : {
"$ref" : "#/definitions/User"
} }
}, },
"description" : "Summarized information about this SDRangel instance" "description" : "Summarized information about this SDRangel instance"
@ -1343,17 +1340,6 @@ margin-bottom: 20px;
} }
}, },
"description" : "Information about a logical device available from an attached hardware device that can be used as a sampling device" "description" : "Information about a logical device available from an attached hardware device that can be used as a sampling device"
};
defs.User = {
"required" : [ "index", "name" ],
"properties" : {
"index" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}; };
</script> </script>
@ -1469,7 +1455,7 @@ margin-bottom: 20px;
<p class="marked">Get device settings</p> <p class="marked">Get device settings</p>
<p></p> <p></p>
<br /> <br />
<pre class="prettyprint language-html prettyprinted" data-type="get"><code><span class="pln">/sdrangel/deviceset/{deviceSetIndex}/device</span></code></pre> <pre class="prettyprint language-html prettyprinted" data-type="get"><code><span class="pln">/sdrangel/deviceset/{deviceSetIndex}/device/settings</span></code></pre>
<p> <p>
<h3>Usage and SDK Samples</h3> <h3>Usage and SDK Samples</h3>
</p> </p>
@ -1489,7 +1475,7 @@ margin-bottom: 20px;
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="examples-DeviceSet-devicesetDeviceGet-0-curl"> <div class="tab-pane active" id="examples-DeviceSet-devicesetDeviceGet-0-curl">
<pre class="prettyprint"><code class="language-bsh">curl -X GET "http://localhost:8091/sdrangel/deviceset/{deviceSetIndex}/device"</code></pre> <pre class="prettyprint"><code class="language-bsh">curl -X GET "http://localhost:8091/sdrangel/deviceset/{deviceSetIndex}/device/settings"</code></pre>
</div> </div>
<div class="tab-pane" id="examples-DeviceSet-devicesetDeviceGet-0-java"> <div class="tab-pane" id="examples-DeviceSet-devicesetDeviceGet-0-java">
<pre class="prettyprint"><code class="language-java">import SWGSDRangel.*; <pre class="prettyprint"><code class="language-java">import SWGSDRangel.*;
@ -9072,7 +9058,7 @@ except ApiException as e:
</div> </div>
<div id="generator"> <div id="generator">
<div class="content"> <div class="content">
Generated 2017-12-06T19:21:13.596+01:00 Generated 2017-12-06T21:52:02.995+01:00
</div> </div>
</div> </div>
</div> </div>

View File

@ -30,3 +30,4 @@ QString WebAPIAdapterInterface::instanceDeviceSetsURL = "/sdrangel/devicesets";
std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]{1,2})$"); std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]{1,2})$");
std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device$"); std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device$");
std::regex WebAPIAdapterInterface::devicesetDeviceSettingsURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device/settings$");

View File

@ -217,7 +217,7 @@ public:
{ return 501; } { return 501; }
/** /**
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels * Handler of /sdrangel/deviceset/{devicesetIndex} (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented) * returns the Http status code (default 501: not implemented)
*/ */
virtual int devicesetGet( virtual int devicesetGet(
@ -237,10 +237,10 @@ public:
{ return 501; } { return 501; }
/** /**
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels * Handler of /sdrangel/deviceset/{devicesetIndex}/device/settings (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented) * returns the Http status code (default 501: not implemented)
*/ */
virtual int devicesetDeviceGet( virtual int devicesetDeviceSettingsGet(
int deviceSetIndex __attribute__((unused)), int deviceSetIndex __attribute__((unused)),
SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)), SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)),
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
@ -257,6 +257,7 @@ public:
static QString instanceDeviceSetsURL; static QString instanceDeviceSetsURL;
static std::regex devicesetURLRe; static std::regex devicesetURLRe;
static std::regex devicesetDeviceURLRe; static std::regex devicesetDeviceURLRe;
static std::regex devicesetDeviceSettingsURLRe;
}; };

View File

@ -90,6 +90,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
devicesetService(std::string(desc_match[1]), request, response); devicesetService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) { } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
devicesetDeviceService(std::string(desc_match[1]), request, response); devicesetDeviceService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
devicesetDeviceSettingsService(std::string(desc_match[1]), request, response);
} }
else else
{ {
@ -601,15 +603,40 @@ void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qt
} }
} }
} }
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
catch (const boost::bad_lexical_cast &e)
{
errorResponse.init();
*errorResponse.getMessage() = "Wrong integer conversion on device set index";
response.setStatus(400,"Invalid data");
response.write(errorResponse.asJson().toUtf8());
}
}
void WebAPIRequestMapper::devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
SWGSDRangel::SWGErrorResponse errorResponse;
try
{
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
if (request.getMethod() == "PUT")
{
}
else if (request.getMethod() == "PATCH")
{
}
else if (request.getMethod() == "GET") else if (request.getMethod() == "GET")
{ {
SWGSDRangel::SWGDeviceSettings normalResponse; SWGSDRangel::SWGDeviceSettings normalResponse;
normalResponse.cleanup(); resetDeviceSettings(normalResponse);
normalResponse.setFileSourceSettings(0); int status = m_adapter->devicesetDeviceSettingsGet(deviceSetIndex, normalResponse, errorResponse);
normalResponse.setRtlSdrSettings(0);
normalResponse.setLimeSdrInputSettings(0);
normalResponse.setLimeSdrOutputSettings(0);
int status = m_adapter->devicesetDeviceGet(deviceSetIndex, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
if (status == 200) { if (status == 200) {
@ -682,4 +709,12 @@ bool WebAPIRequestMapper::validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifi
return (presetIdentifier.getGroupName() && presetIdentifier.getName() && presetIdentifier.getType()); return (presetIdentifier.getGroupName() && presetIdentifier.getName() && presetIdentifier.getType());
} }
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
{
deviceSettings.cleanup();
deviceSettings.setFileSourceSettings(0);
deviceSettings.setRtlSdrSettings(0);
deviceSettings.setLimeSdrInputSettings(0);
deviceSettings.setLimeSdrOutputSettings(0);
}

View File

@ -57,11 +57,14 @@ private:
void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer); bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier); bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response); bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response);
void resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings);
}; };
#endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */ #endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */

View File

@ -694,7 +694,7 @@ int WebAPIAdapterGUI::devicesetDevicePut(
} }
} }
int WebAPIAdapterGUI::devicesetDeviceGet( int WebAPIAdapterGUI::devicesetDeviceSettingsGet(
int deviceSetIndex, int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)

View File

@ -120,7 +120,7 @@ public:
SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGDeviceListItem& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceGet( virtual int devicesetDeviceSettingsGet(
int deviceSetIndex, int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);

View File

@ -530,9 +530,11 @@ paths:
$ref: "#/definitions/ErrorResponse" $ref: "#/definitions/ErrorResponse"
"501": "501":
description: Function not implemented description: Function not implemented
/sdrangel/deviceset/{deviceSetIndex}/device/settings:
x-swagger-router-controller: deviceset
get: get:
description: Get device settings description: Get device settings
operationId: devicesetDeviceGet operationId: devicesetDeviceSettingsGet
tags: tags:
- DeviceSet - DeviceSet
parameters: parameters:
@ -569,8 +571,6 @@ definitions:
$ref: "#/definitions/LoggingInfo" $ref: "#/definitions/LoggingInfo"
devicesetlist: devicesetlist:
$ref: "#/definitions/DeviceSetList" $ref: "#/definitions/DeviceSetList"
user:
$ref: "http://localhost:8081/User.yaml#/User"
InstanceDevicesResponse: InstanceDevicesResponse:
description: "Summarized information about logical devices from hardware devices attached to this SDRangel instance" description: "Summarized information about logical devices from hardware devices attached to this SDRangel instance"
required: required:

View File

@ -1011,9 +1011,6 @@ margin-bottom: 20px;
}, },
"devicesetlist" : { "devicesetlist" : {
"$ref" : "#/definitions/DeviceSetList" "$ref" : "#/definitions/DeviceSetList"
},
"user" : {
"$ref" : "#/definitions/User"
} }
}, },
"description" : "Summarized information about this SDRangel instance" "description" : "Summarized information about this SDRangel instance"
@ -1343,17 +1340,6 @@ margin-bottom: 20px;
} }
}, },
"description" : "Information about a logical device available from an attached hardware device that can be used as a sampling device" "description" : "Information about a logical device available from an attached hardware device that can be used as a sampling device"
};
defs.User = {
"required" : [ "index", "name" ],
"properties" : {
"index" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
}; };
</script> </script>
@ -1469,7 +1455,7 @@ margin-bottom: 20px;
<p class="marked">Get device settings</p> <p class="marked">Get device settings</p>
<p></p> <p></p>
<br /> <br />
<pre class="prettyprint language-html prettyprinted" data-type="get"><code><span class="pln">/sdrangel/deviceset/{deviceSetIndex}/device</span></code></pre> <pre class="prettyprint language-html prettyprinted" data-type="get"><code><span class="pln">/sdrangel/deviceset/{deviceSetIndex}/device/settings</span></code></pre>
<p> <p>
<h3>Usage and SDK Samples</h3> <h3>Usage and SDK Samples</h3>
</p> </p>
@ -1489,7 +1475,7 @@ margin-bottom: 20px;
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="examples-DeviceSet-devicesetDeviceGet-0-curl"> <div class="tab-pane active" id="examples-DeviceSet-devicesetDeviceGet-0-curl">
<pre class="prettyprint"><code class="language-bsh">curl -X GET "http://localhost:8091/sdrangel/deviceset/{deviceSetIndex}/device"</code></pre> <pre class="prettyprint"><code class="language-bsh">curl -X GET "http://localhost:8091/sdrangel/deviceset/{deviceSetIndex}/device/settings"</code></pre>
</div> </div>
<div class="tab-pane" id="examples-DeviceSet-devicesetDeviceGet-0-java"> <div class="tab-pane" id="examples-DeviceSet-devicesetDeviceGet-0-java">
<pre class="prettyprint"><code class="language-java">import SWGSDRangel.*; <pre class="prettyprint"><code class="language-java">import SWGSDRangel.*;
@ -9072,7 +9058,7 @@ except ApiException as e:
</div> </div>
<div id="generator"> <div id="generator">
<div class="content"> <div class="content">
Generated 2017-12-06T19:21:13.596+01:00 Generated 2017-12-06T21:52:02.995+01:00
</div> </div>
</div> </div>
</div> </div>

View File

@ -31,7 +31,7 @@ SWGDeviceSetApi::SWGDeviceSetApi(QString host, QString basePath) {
void void
SWGDeviceSetApi::devicesetDeviceGet(qint32 device_set_index) { SWGDeviceSetApi::devicesetDeviceGet(qint32 device_set_index) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/sdrangel/deviceset/{deviceSetIndex}/device"); fullPath.append(this->host).append(this->basePath).append("/sdrangel/deviceset/{deviceSetIndex}/device/settings");
QString device_set_indexPathParam("{"); device_set_indexPathParam.append("deviceSetIndex").append("}"); QString device_set_indexPathParam("{"); device_set_indexPathParam.append("deviceSetIndex").append("}");
fullPath.replace(device_set_indexPathParam, stringValue(device_set_index)); fullPath.replace(device_set_indexPathParam, stringValue(device_set_index));

View File

@ -40,7 +40,6 @@ SWGInstanceSummaryResponse::init() {
version = new QString(""); version = new QString("");
logging = new SWGLoggingInfo(); logging = new SWGLoggingInfo();
devicesetlist = new SWGDeviceSetList(); devicesetlist = new SWGDeviceSetList();
user = new SWGUser();
} }
void void
@ -57,10 +56,6 @@ SWGInstanceSummaryResponse::cleanup() {
if(devicesetlist != nullptr) { if(devicesetlist != nullptr) {
delete devicesetlist; delete devicesetlist;
} }
if(user != nullptr) {
delete user;
}
} }
SWGInstanceSummaryResponse* SWGInstanceSummaryResponse*
@ -77,7 +72,6 @@ SWGInstanceSummaryResponse::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&version, pJson["version"], "QString", "QString"); ::SWGSDRangel::setValue(&version, pJson["version"], "QString", "QString");
::SWGSDRangel::setValue(&logging, pJson["logging"], "SWGLoggingInfo", "SWGLoggingInfo"); ::SWGSDRangel::setValue(&logging, pJson["logging"], "SWGLoggingInfo", "SWGLoggingInfo");
::SWGSDRangel::setValue(&devicesetlist, pJson["devicesetlist"], "SWGDeviceSetList", "SWGDeviceSetList"); ::SWGSDRangel::setValue(&devicesetlist, pJson["devicesetlist"], "SWGDeviceSetList", "SWGDeviceSetList");
::SWGSDRangel::setValue(&user, pJson["user"], "SWGUser", "SWGUser");
} }
QString QString
@ -100,8 +94,6 @@ SWGInstanceSummaryResponse::asJsonObject() {
toJsonValue(QString("devicesetlist"), devicesetlist, obj, QString("SWGDeviceSetList")); toJsonValue(QString("devicesetlist"), devicesetlist, obj, QString("SWGDeviceSetList"));
toJsonValue(QString("user"), user, obj, QString("SWGUser"));
return obj; return obj;
} }
@ -132,15 +124,6 @@ SWGInstanceSummaryResponse::setDevicesetlist(SWGDeviceSetList* devicesetlist) {
this->devicesetlist = devicesetlist; this->devicesetlist = devicesetlist;
} }
SWGUser*
SWGInstanceSummaryResponse::getUser() {
return user;
}
void
SWGInstanceSummaryResponse::setUser(SWGUser* user) {
this->user = user;
}
} }

View File

@ -24,7 +24,6 @@
#include "SWGDeviceSetList.h" #include "SWGDeviceSetList.h"
#include "SWGLoggingInfo.h" #include "SWGLoggingInfo.h"
#include "SWGUser.h"
#include <QString> #include <QString>
#include "SWGObject.h" #include "SWGObject.h"
@ -54,15 +53,11 @@ public:
SWGDeviceSetList* getDevicesetlist(); SWGDeviceSetList* getDevicesetlist();
void setDevicesetlist(SWGDeviceSetList* devicesetlist); void setDevicesetlist(SWGDeviceSetList* devicesetlist);
SWGUser* getUser();
void setUser(SWGUser* user);
private: private:
QString* version; QString* version;
SWGLoggingInfo* logging; SWGLoggingInfo* logging;
SWGDeviceSetList* devicesetlist; SWGDeviceSetList* devicesetlist;
SWGUser* user;
}; };
} }

View File

@ -41,7 +41,6 @@
#include "SWGPresets.h" #include "SWGPresets.h"
#include "SWGRtlSdrSettings.h" #include "SWGRtlSdrSettings.h"
#include "SWGSamplingDevice.h" #include "SWGSamplingDevice.h"
#include "SWGUser.h"
namespace SWGSDRangel { namespace SWGSDRangel {
@ -127,9 +126,6 @@ namespace SWGSDRangel {
if(QString("SWGSamplingDevice").compare(type) == 0) { if(QString("SWGSamplingDevice").compare(type) == 0) {
return new SWGSamplingDevice(); return new SWGSamplingDevice();
} }
if(QString("SWGUser").compare(type) == 0) {
return new SWGUser();
}
return nullptr; return nullptr;
} }

View File

@ -1,109 +0,0 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
#include "SWGUser.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace SWGSDRangel {
SWGUser::SWGUser(QString* json) {
init();
this->fromJson(*json);
}
SWGUser::SWGUser() {
init();
}
SWGUser::~SWGUser() {
this->cleanup();
}
void
SWGUser::init() {
index = 0;
name = new QString("");
}
void
SWGUser::cleanup() {
if(name != nullptr) {
delete name;
}
}
SWGUser*
SWGUser::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGUser::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&index, pJson["index"], "qint32", "");
::SWGSDRangel::setValue(&name, pJson["name"], "QString", "QString");
}
QString
SWGUser::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGUser::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("index", QJsonValue(index));
toJsonValue(QString("name"), name, obj, QString("QString"));
return obj;
}
qint32
SWGUser::getIndex() {
return index;
}
void
SWGUser::setIndex(qint32 index) {
this->index = index;
}
QString*
SWGUser::getName() {
return name;
}
void
SWGUser::setName(QString* name) {
this->name = name;
}
}

View File

@ -1,59 +0,0 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/*
* SWGUser.h
*
*
*/
#ifndef SWGUser_H_
#define SWGUser_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace SWGSDRangel {
class SWGUser: public SWGObject {
public:
SWGUser();
SWGUser(QString* json);
virtual ~SWGUser();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGUser* fromJson(QString &jsonString);
qint32 getIndex();
void setIndex(qint32 index);
QString* getName();
void setName(QString* name);
private:
qint32 index;
QString* name;
};
}
#endif /* SWGUser_H_ */