Skip to content

Commit

Permalink
API: added PUT, PATCH, POST /sdrangel/featureset/{featureSetIndex}​/p…
Browse files Browse the repository at this point in the history
…reset
  • Loading branch information
f4exb committed Sep 5, 2021
1 parent e1c3726 commit b0c35d2
Show file tree
Hide file tree
Showing 14 changed files with 4,375 additions and 250 deletions.
1,841 changes: 1,716 additions & 125 deletions sdrbase/resources/webapi/doc/html2/index.html

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions sdrbase/resources/webapi/doc/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,121 @@ paths:
"501":
$ref: "#/responses/Response_501"

/sdrangel/featureset/{featureSetIndex}/preset:
x-swagger-router-controller: featureset
patch:
description: Load a preset in a feature set
operationId: featuresetPresetPatch
tags:
- FeatureSet
consumes:
- application/json
parameters:
- in: path
name: featureSetIndex
type: integer
required: true
description: Index of feature set in the feature set list
- name: body
in: body
description: Load preset settings to the feature set
required: true
schema:
$ref: "#/definitions/FeaturePresetIdentifier"
responses:
"202":
description: On successful sending of the message the selected preset identification is returned
schema:
$ref: "#/definitions/FeaturePresetIdentifier"
"400":
description: Invalid JSON request
schema:
$ref: "#/definitions/ErrorResponse"
"404":
description: No preset or feature set found
schema:
$ref: "#/definitions/ErrorResponse"
"500":
$ref: "#/responses/Response_500"
"501":
$ref: "#/responses/Response_501"
put:
description: Update an existing preset with feature set settings.
operationId: featuresetPresetPut
tags:
- FeatureSet
consumes:
- application/json
parameters:
- in: path
name: featureSetIndex
type: integer
required: true
description: Index of feature set in the feature set list
- name: body
in: body
description: save feature set settings to the preset
required: true
schema:
$ref: "#/definitions/FeaturePresetIdentifier"
responses:
"202":
description: On successful sending of the message the selected preset identification is returned
schema:
$ref: "#/definitions/FeaturePresetIdentifier"
"400":
description: Invalid JSON request
schema:
$ref: "#/definitions/ErrorResponse"
"404":
description: No preset or feature set found
schema:
$ref: "#/definitions/ErrorResponse"
"500":
$ref: "#/responses/Response_500"
"501":
$ref: "#/responses/Response_501"
post:
description: Create a new preset from a feature set settings.
operationId: featuresetPresetPost
tags:
- FeatureSet
consumes:
- application/json
parameters:
- in: path
name: featureSetIndex
type: integer
required: true
description: Index of feature set in the feature set list
- name: body
in: body
description: save feature set settings on a new preset
required: true
schema:
$ref: "#/definitions/FeaturePresetIdentifier"
responses:
"202":
description: On successful sending of the message the created preset identification is returned
schema:
$ref: "#/definitions/PresetIdentifier"
"400":
description: Invalid JSON request
schema:
$ref: "#/definitions/ErrorResponse"
"404":
description: Feature set not found
schema:
$ref: "#/definitions/ErrorResponse"
"409":
description: Preset already exists
schema:
$ref: "#/definitions/ErrorResponse"
"500":
$ref: "#/responses/Response_500"
"501":
$ref: "#/responses/Response_501"

/sdrangel/featureset/{featureSetIndex}/feature/{featureIndex}:
x-swagger-router-controller: featureset
delete:
Expand Down
104 changes: 104 additions & 0 deletions sdrbase/webapi/webapiadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "SWGFeaturePresetGroup.h"
#include "SWGFeaturePresetItem.h"
#include "SWGFeaturePresetIdentifier.h"
#include "SWGFeaturePresetTransfer.h"
#include "SWGFeatureSetList.h"
#include "SWGFeatureSettings.h"
#include "SWGFeatureReport.h"
Expand Down Expand Up @@ -3165,6 +3166,109 @@ int WebAPIAdapter::featuresetFeatureRunDelete(
}
}

int WebAPIAdapter::featuresetPresetPatch(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
int nbFeatureSets = m_mainCore->m_featureSets.size();

if (featureSetIndex >= nbFeatureSets)
{
error.init();
*error.getMessage() = QString("There is no feature set at index %1. Number of device sets is %2").arg(featureSetIndex).arg(nbFeatureSets);
return 404;
}

const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset(
*query.getGroupName(),
*query.getDescription());

if (selectedPreset == 0)
{
error.init();
*error.getMessage() = QString("There is no preset [%1, %2]")
.arg(*query.getGroupName())
.arg(*query.getDescription());
return 404;
}

MainCore::MsgLoadFeatureSetPreset *msg = MainCore::MsgLoadFeatureSetPreset::create(selectedPreset, featureSetIndex);
m_mainCore->m_mainMessageQueue->push(msg);

return 202;
}

int WebAPIAdapter::featuresetPresetPut(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
int nbFeatureSets = m_mainCore->m_featureSets.size();

if (featureSetIndex >= nbFeatureSets)
{
error.init();
*error.getMessage() = QString("There is no feature set at index %1. Number of feature sets is %2").arg(featureSetIndex).arg(nbFeatureSets);
return 404;
}

const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset(
*query.getGroupName(),
*query.getDescription());

if (selectedPreset == 0)
{
error.init();
*error.getMessage() = QString("There is no preset [%1, %2]")
.arg(*query.getGroupName())
.arg(*query.getDescription());
return 404;
}

MainCore::MsgSaveFeatureSetPreset *msg = MainCore::MsgSaveFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset), featureSetIndex, false);
m_mainCore->m_mainMessageQueue->push(msg);

return 202;
}

int WebAPIAdapter::featuresetPresetPost(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
int nbFeatureSets = m_mainCore->m_featureSets.size();

if (featureSetIndex >= nbFeatureSets)
{
error.init();
*error.getMessage() = QString("There is no feature set at index %1. Number of feature sets is %2").arg(featureSetIndex).arg(nbFeatureSets);
return 404;
}

const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset(
*query.getGroupName(),
*query.getDescription());

if (selectedPreset == 0) // save on a new preset
{
selectedPreset = m_mainCore->m_settings.newFeatureSetPreset(*query.getGroupName(), *query.getDescription());
}
else
{
error.init();
*error.getMessage() = QString("Preset already exists [%1, %2]")
.arg(*query.getGroupName())
.arg(*query.getDescription());
return 409;
}

MainCore::MsgSaveFeatureSetPreset *msg = MainCore::MsgSaveFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset), featureSetIndex, true);
m_mainCore->m_mainMessageQueue->push(msg);

return 202;
}

int WebAPIAdapter::featuresetFeatureSettingsGet(
int featureSetIndex,
int featureIndex,
Expand Down
15 changes: 15 additions & 0 deletions sdrbase/webapi/webapiadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ class SDRBASE_API WebAPIAdapter: public WebAPIAdapterInterface
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);

virtual int featuresetPresetPatch(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error);

virtual int featuresetPresetPut(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error);

virtual int featuresetPresetPost(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error);

virtual int featuresetFeatureSettingsGet(
int featureSetIndex,
int featureIndex,
Expand Down
1 change: 1 addition & 0 deletions sdrbase/webapi/webapiadapterinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ std::regex WebAPIAdapterInterface::devicesetChannelActionsURLRe("^/sdrangel/devi

std::regex WebAPIAdapterInterface::featuresetURLRe("^/sdrangel/featureset/([0-9]{1,2})$");
std::regex WebAPIAdapterInterface::featuresetFeatureURLRe("^/sdrangel/featureset/([0-9]{1,2})/feature$");
std::regex WebAPIAdapterInterface::featuresetPresetURLRe("^/sdrangel/featureset/([0-9]{1,2})/preset");
std::regex WebAPIAdapterInterface::featuresetFeatureIndexURLRe("^/sdrangel/featureset/([0-9]{1,2})/feature/([0-9]{1,2})$");
std::regex WebAPIAdapterInterface::featuresetFeatureRunURLRe("^/sdrangel/featureset/([0-9]{1,2})/feature/([0-9]{1,2})/run$");
std::regex WebAPIAdapterInterface::featuresetFeatureSettingsURLRe("^/sdrangel/featureset/([0-9]{1,2})/feature/([0-9]{1,2})/settings$");
Expand Down
50 changes: 50 additions & 0 deletions sdrbase/webapi/webapiadapterinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace SWGSDRangel
class SWGSuccessResponse;
class SWGFeaturePresets;
class SWGFeaturePresetIdentifier;
class SWGFeaturePresetTransfer;
class SWGFeatureSetList;
class SWGFeatureSet;
class SWGFeatureSettings;
Expand Down Expand Up @@ -1318,6 +1319,54 @@ class SDRBASE_API WebAPIAdapterInterface
return 501;
}

/**
* Handler of /sdrangel/featureset/{featuresetIndex}/preset (PATCH) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int featuresetPresetPatch(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
(void) featureSetIndex;
(void) query;
error.init();
*error.getMessage() = QString("Function not implemented");
return 501;
}

/**
* Handler of /sdrangel/featureset/{featuresetIndex}/preset (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int featuresetPresetPut(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
(void) featureSetIndex;
(void) query;
error.init();
*error.getMessage() = QString("Function not implemented");
return 501;
}

/**
* Handler of /sdrangel/featureset/{featuresetIndex}/preset (POST) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int featuresetPresetPost(
int featureSetIndex,
SWGSDRangel::SWGFeaturePresetIdentifier& query,
SWGSDRangel::SWGErrorResponse& error)
{
(void) featureSetIndex;
(void) query;
error.init();
*error.getMessage() = QString("Function not implemented");
return 501;
}

/**
* Handler of /sdrangel/featureset/{featuresetIndex}/feature/{featureIndex}/settings (GET)
* returns the Http status code (default 501: not implemented)
Expand Down Expand Up @@ -1443,6 +1492,7 @@ class SDRBASE_API WebAPIAdapterInterface
static std::regex devicesetChannelsReportURLRe;
static std::regex featuresetURLRe;
static std::regex featuresetFeatureURLRe;
static std::regex featuresetPresetURLRe;
static std::regex featuresetFeatureIndexURLRe;
static std::regex featuresetFeatureRunURLRe;
static std::regex featuresetFeatureSettingsURLRe;
Expand Down
Loading

0 comments on commit b0c35d2

Please sign in to comment.