mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 18:15:45 -05:00
Web API: /sdrangel/preset (PUT) implementation
This commit is contained in:
parent
57bda99c2b
commit
33e39f161a
@ -154,6 +154,16 @@ public:
|
|||||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||||
{ return 501; }
|
{ return 501; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler of /sdrangel/preset (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||||
|
* returns the Http status code (default 501: not implemented)
|
||||||
|
*/
|
||||||
|
virtual int instancePresetPut(
|
||||||
|
Swagger::SWGPresetTransfer& query __attribute__((unused)),
|
||||||
|
Swagger::SWGPresetIdentifier& response __attribute__((unused)),
|
||||||
|
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||||
|
{ return 501; }
|
||||||
|
|
||||||
static QString instanceSummaryURL;
|
static QString instanceSummaryURL;
|
||||||
static QString instanceDevicesURL;
|
static QString instanceDevicesURL;
|
||||||
static QString instanceChannelsURL;
|
static QString instanceChannelsURL;
|
||||||
|
@ -362,6 +362,25 @@ void WebAPIRequestMapper::instancePresetService(qtwebapp::HttpRequest& request,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (request.getMethod() == "PUT")
|
||||||
|
{
|
||||||
|
Swagger::SWGPresetTransfer query;
|
||||||
|
Swagger::SWGPresetIdentifier normalResponse;
|
||||||
|
QString jsonStr = request.getBody();
|
||||||
|
|
||||||
|
if (parseJsonBody(jsonStr, response))
|
||||||
|
{
|
||||||
|
query.fromJson(jsonStr);
|
||||||
|
int status = m_adapter->instancePresetPut(query, normalResponse, errorResponse);
|
||||||
|
response.setStatus(status);
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
response.write(normalResponse.asJson().toUtf8());
|
||||||
|
} else {
|
||||||
|
response.write(errorResponse.asJson().toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.setStatus(405,"Invalid HTTP method");
|
response.setStatus(405,"Invalid HTTP method");
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgLoadPreset, Message)
|
MESSAGE_CLASS_DEFINITION(MainWindow::MsgLoadPreset, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(MainWindow::MsgSavePreset, Message)
|
||||||
|
|
||||||
MainWindow *MainWindow::m_instance = 0;
|
MainWindow *MainWindow::m_instance = 0;
|
||||||
|
|
||||||
@ -664,6 +665,15 @@ bool MainWindow::handleMessage(const Message& cmd)
|
|||||||
loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
|
loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (MsgSavePreset::match(cmd))
|
||||||
|
{
|
||||||
|
MsgSavePreset& notif = (MsgSavePreset&) cmd;
|
||||||
|
savePresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
|
||||||
|
if (notif.isNewPreset()) { ui->presetTree->setCurrentItem(addPresetToTree(notif.getPreset())); }
|
||||||
|
m_settings.sortPresets();
|
||||||
|
m_settings.save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,32 @@ private:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MsgSavePreset : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
Preset *getPreset() const { return m_preset; }
|
||||||
|
int getDeviceSetIndex() const { return m_deviceSetIndex; }
|
||||||
|
bool isNewPreset() const { return m_newPreset; }
|
||||||
|
|
||||||
|
static MsgSavePreset* create(Preset *preset, int deviceSetIndex, bool newPreset)
|
||||||
|
{
|
||||||
|
return new MsgSavePreset(preset, deviceSetIndex, newPreset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Preset *m_preset;
|
||||||
|
int m_deviceSetIndex;
|
||||||
|
bool m_newPreset;
|
||||||
|
|
||||||
|
MsgSavePreset(Preset *preset, int deviceSetIndex, bool newPreset) :
|
||||||
|
Message(),
|
||||||
|
m_preset(preset),
|
||||||
|
m_deviceSetIndex(deviceSetIndex),
|
||||||
|
m_newPreset(newPreset)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PGroup,
|
PGroup,
|
||||||
PItem
|
PItem
|
||||||
|
@ -486,6 +486,61 @@ int WebAPIAdapterGUI::instancePresetPatch(
|
|||||||
return 200;
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterGUI::instancePresetPut(
|
||||||
|
Swagger::SWGPresetTransfer& query,
|
||||||
|
Swagger::SWGPresetIdentifier& response,
|
||||||
|
Swagger::SWGErrorResponse& error)
|
||||||
|
{
|
||||||
|
int deviceSetIndex = query.getDeviceSetIndex();
|
||||||
|
Swagger::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
||||||
|
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
||||||
|
bool newPreset;
|
||||||
|
|
||||||
|
if (deviceSetIndex > nbDeviceSets)
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
|
||||||
|
presetIdentifier->getCenterFrequency(),
|
||||||
|
*presetIdentifier->getName());
|
||||||
|
|
||||||
|
if (selectedPreset == 0) // save on a new preset
|
||||||
|
{
|
||||||
|
selectedPreset = m_mainWindow.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
|
||||||
|
newPreset = true;
|
||||||
|
}
|
||||||
|
else // update existing preset
|
||||||
|
{
|
||||||
|
DeviceUISet *deviceUI = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||||
|
newPreset = false;
|
||||||
|
|
||||||
|
if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::MsgSavePreset *msg = MainWindow::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, newPreset);
|
||||||
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
||||||
|
|
||||||
|
response.init();
|
||||||
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
||||||
|
*response.getGroupName() = selectedPreset->getGroup();
|
||||||
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
||||||
|
*response.getName() = selectedPreset->getDescription();
|
||||||
|
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
|
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
|
||||||
{
|
{
|
||||||
if (msgTypeString == "debug") {
|
if (msgTypeString == "debug") {
|
||||||
|
@ -83,6 +83,11 @@ public:
|
|||||||
Swagger::SWGPresetIdentifier& response,
|
Swagger::SWGPresetIdentifier& response,
|
||||||
Swagger::SWGErrorResponse& error);
|
Swagger::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int instancePresetPut(
|
||||||
|
Swagger::SWGPresetTransfer& query,
|
||||||
|
Swagger::SWGPresetIdentifier& response,
|
||||||
|
Swagger::SWGErrorResponse& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow& m_mainWindow;
|
MainWindow& m_mainWindow;
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ paths:
|
|||||||
"501":
|
"501":
|
||||||
description: Function not implemented
|
description: Function not implemented
|
||||||
put:
|
put:
|
||||||
description: Save device set settings on a preset
|
description: Save device set settings on a preset. Preset is updated if it already exists else it is created with the given name and group. If created given frequency and type is ignored and is determined with the device set values.
|
||||||
operationId: instancePresetPut
|
operationId: instancePresetPut
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
|
Loading…
Reference in New Issue
Block a user