mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-10 13:40:37 -04:00
Web API: /sdrangel/deviceset/{index} (GET) implementation
This commit is contained in:
parent
3e7efb4c6f
commit
c5a19e261c
@ -792,7 +792,7 @@ margin-bottom: 20px;
|
||||
"description" : "Channel summarized information"
|
||||
};
|
||||
defs.ChannelListItem = {
|
||||
"required" : [ "id", "name" ],
|
||||
"required" : [ "id" ],
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string",
|
||||
@ -848,7 +848,7 @@ margin-bottom: 20px;
|
||||
"description" : "DV serial device details"
|
||||
};
|
||||
defs.DeviceListItem = {
|
||||
"required" : [ "hwType" ],
|
||||
"required" : [ "hwType", "tx" ],
|
||||
"properties" : {
|
||||
"displayedName" : {
|
||||
"type" : "string",
|
||||
@ -8445,7 +8445,7 @@ except ApiException as e:
|
||||
</div>
|
||||
<div id="generator">
|
||||
<div class="content">
|
||||
Generated 2017-11-26T00:25:44.253+01:00
|
||||
Generated 2017-11-26T10:35:17.573+01:00
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -28,5 +28,5 @@ QString WebAPIAdapterInterface::instanceDVSerialURL = "/sdrangel/dvserial";
|
||||
QString WebAPIAdapterInterface::instancePresetURL = "/sdrangel/preset";
|
||||
QString WebAPIAdapterInterface::instanceDeviceSetsURL = "/sdrangel/devicesets";
|
||||
|
||||
std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]+)$");
|
||||
std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]+)/device$");
|
||||
std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]{1,2})$");
|
||||
std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device$");
|
||||
|
@ -205,7 +205,6 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
@ -215,6 +214,16 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int devicesetGet(
|
||||
int deviceSetIndex __attribute__((unused)),
|
||||
Swagger::SWGDeviceSet& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "httpdocrootsettings.h"
|
||||
#include "webapirequestmapper.h"
|
||||
#include "SWGInstanceSummaryResponse.h"
|
||||
@ -80,13 +82,23 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||
}
|
||||
else
|
||||
{
|
||||
std::smatch desc_match;
|
||||
std::string pathStr(path.constData(), path.length());
|
||||
|
||||
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
||||
deviceset(std::string(desc_match[1]), request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray path = "/index.html";
|
||||
m_staticFileController->service(path, response);
|
||||
}
|
||||
|
||||
// QDirIterator it(":", QDirIterator::Subdirectories);
|
||||
// while (it.hasNext()) {
|
||||
// qDebug() << "WebAPIRequestMapper::service: " << it.next();
|
||||
// }
|
||||
|
||||
QByteArray path = "/index.html";
|
||||
m_staticFileController->service(path, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -525,6 +537,40 @@ void WebAPIRequestMapper::instanceDeviceSetsService(qtwebapp::HttpRequest& reque
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
if (request.getMethod() == "GET")
|
||||
{
|
||||
try
|
||||
{
|
||||
Swagger::SWGDeviceSet normalResponse;
|
||||
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
||||
int status = m_adapter->devicesetGet(deviceSetIndex, normalResponse, errorResponse);
|
||||
response.setStatus(status);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
response.write("Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
|
||||
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
void instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
void deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
bool validatePresetTransfer(Swagger::SWGPresetTransfer& presetTransfer);
|
||||
bool validatePresetIdentifer(Swagger::SWGPresetIdentifier& presetIdentifier);
|
||||
|
||||
|
@ -593,6 +593,27 @@ int WebAPIAdapterGUI::instanceDeviceSetsDelete(
|
||||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::devicesetGet(
|
||||
int deviceSetIndex,
|
||||
Swagger::SWGDeviceSet& response,
|
||||
Swagger::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||
{
|
||||
const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||
getDeviceSet(&response, deviceSet, deviceSetIndex);
|
||||
|
||||
return 200;
|
||||
}
|
||||
else
|
||||
{
|
||||
error.init();
|
||||
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIAdapterGUI::getDeviceSetList(Swagger::SWGDeviceSetList* deviceSetList)
|
||||
{
|
||||
deviceSetList->init();
|
||||
|
@ -110,6 +110,11 @@ public:
|
||||
Swagger::SWGDeviceSetList& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetGet(
|
||||
int deviceSetIndex,
|
||||
Swagger::SWGDeviceSet& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
|
@ -550,6 +550,7 @@ definitions:
|
||||
description: "Summarized information about attached hardware device"
|
||||
required:
|
||||
- hwType
|
||||
- tx
|
||||
properties:
|
||||
displayedName:
|
||||
description: "Displayable name that uniquely identifies this device instance"
|
||||
@ -581,7 +582,6 @@ definitions:
|
||||
ChannelListItem:
|
||||
description: "Summarized information about channel plugin"
|
||||
required:
|
||||
- name
|
||||
- id
|
||||
properties:
|
||||
name:
|
||||
|
@ -792,7 +792,7 @@ margin-bottom: 20px;
|
||||
"description" : "Channel summarized information"
|
||||
};
|
||||
defs.ChannelListItem = {
|
||||
"required" : [ "id", "name" ],
|
||||
"required" : [ "id" ],
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string",
|
||||
@ -848,7 +848,7 @@ margin-bottom: 20px;
|
||||
"description" : "DV serial device details"
|
||||
};
|
||||
defs.DeviceListItem = {
|
||||
"required" : [ "hwType" ],
|
||||
"required" : [ "hwType", "tx" ],
|
||||
"properties" : {
|
||||
"displayedName" : {
|
||||
"type" : "string",
|
||||
@ -8445,7 +8445,7 @@ except ApiException as e:
|
||||
</div>
|
||||
<div id="generator">
|
||||
<div class="content">
|
||||
Generated 2017-11-26T00:25:44.253+01:00
|
||||
Generated 2017-11-26T10:35:17.573+01:00
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user