mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-02 06:04:39 -04:00
Web API: /sdrangel/deviceset/{index}/device (PUT) implementation
This commit is contained in:
@@ -37,6 +37,7 @@ namespace Swagger
|
||||
class SWGPresetIdentifier;
|
||||
class SWGDeviceSetList;
|
||||
class SWGDeviceSet;
|
||||
class SWGDeviceListItem;
|
||||
class SWGErrorResponse;
|
||||
}
|
||||
|
||||
@@ -224,6 +225,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 devicesetDevicePut(
|
||||
int deviceSetIndex __attribute__((unused)),
|
||||
Swagger::SWGDeviceListItem& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
|
||||
@@ -87,6 +87,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||
|
||||
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
||||
deviceset(std::string(desc_match[1]), request, response);
|
||||
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
|
||||
devicesetDevice(std::string(desc_match[1]), request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -571,6 +573,48 @@ void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpR
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::devicesetDevice(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
try
|
||||
{
|
||||
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
||||
|
||||
if (request.getMethod() == "PUT")
|
||||
{
|
||||
Swagger::SWGDeviceListItem normalResponse;
|
||||
QString jsonStr = request.getBody();
|
||||
|
||||
if (parseJsonBody(jsonStr, response))
|
||||
{
|
||||
normalResponse.fromJson(jsonStr);
|
||||
|
||||
int status = m_adapter->devicesetDevicePut(deviceSetIndex, normalResponse, errorResponse);
|
||||
response.setStatus(status);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
@@ -56,6 +56,7 @@ private:
|
||||
void instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
void deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void devicesetDevice(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
bool validatePresetTransfer(Swagger::SWGPresetTransfer& presetTransfer);
|
||||
bool validatePresetIdentifer(Swagger::SWGPresetIdentifier& presetIdentifier);
|
||||
|
||||
Reference in New Issue
Block a user