1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

Server: Web API: implemented /sdrangel/preset DELETE

This commit is contained in:
f4exb 2017-12-21 00:31:38 +01:00
parent 15453b7528
commit e4678ec70c
4 changed files with 61 additions and 0 deletions

View File

@ -37,6 +37,7 @@
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgLoadPreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgSavePreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeletePreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
@ -112,6 +113,14 @@ bool MainCore::handleMessage(const Message& cmd)
m_settings.save();
return true;
}
else if (MsgDeletePreset::match(cmd))
{
MsgDeletePreset& notif = (MsgDeletePreset&) cmd;
const Preset *presetToDelete = notif.getPreset();
// remove preset from settings
m_settings.deletePreset(presetToDelete);
return true;
}
else if (MsgAddDeviceSet::match(cmd))
{
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;

View File

@ -119,6 +119,26 @@ private:
{ }
};
class MsgDeletePreset : public Message {
MESSAGE_CLASS_DECLARATION
public:
const Preset *getPreset() const { return m_preset; }
static MsgDeletePreset* create(const Preset *preset)
{
return new MsgDeletePreset(preset);
}
private:
const Preset *m_preset;
MsgDeletePreset(const Preset *preset) :
Message(),
m_preset(preset)
{ }
};
class MsgDeleteInstance : public Message {
MESSAGE_CLASS_DECLARATION

View File

@ -651,6 +651,34 @@ int WebAPIAdapterSrv::instancePresetPost(
return 200;
}
int WebAPIAdapterSrv::instancePresetDelete(
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error)
{
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*response.getGroupName(),
response.getCenterFrequency(),
*response.getName());
if (selectedPreset == 0)
{
*error.getMessage() = QString("There is no preset [%1, %2, %3]")
.arg(*response.getGroupName())
.arg(response.getCenterFrequency())
.arg(*response.getName());
return 404;
}
response.setCenterFrequency(selectedPreset->getCenterFrequency());
*response.getGroupName() = selectedPreset->getGroup();
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
*response.getName() = selectedPreset->getDescription();
MainCore::MsgDeletePreset *msg = MainCore::MsgDeletePreset::create(const_cast<Preset*>(selectedPreset));
m_mainCore.m_inputMessageQueue.push(msg);
return 200;
}
int WebAPIAdapterSrv::instanceDeviceSetsPost(
bool tx,
SWGSDRangel::SWGSuccessResponse& response,

View File

@ -113,6 +113,10 @@ public:
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetDelete(
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetsDelete(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);