mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 01:55:48 -05:00
Server: Web API: /sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex} DELETE
This commit is contained in:
parent
d79ef49112
commit
b011185e42
@ -435,7 +435,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler of /sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
* Handler of /sdrangel/deviceset/{deviceSetIndex}/channel (POST) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||||
* returns the Http status code (default 501: not implemented)
|
* returns the Http status code (default 501: not implemented)
|
||||||
*/
|
*/
|
||||||
virtual int devicesetChannelPost(
|
virtual int devicesetChannelPost(
|
||||||
@ -450,18 +450,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler of /sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
* Handler of /sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex} (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||||
* returns the Http status code (default 501: not implemented)
|
* returns the Http status code (default 501: not implemented)
|
||||||
*/
|
*/
|
||||||
virtual int devicesetChannelIndexDelete(
|
virtual int devicesetChannelDelete(
|
||||||
int deviceSetIndex __attribute__((unused)),
|
int deviceSetIndex __attribute__((unused)),
|
||||||
int channelIndex __attribute__((unused)),
|
int channelIndex __attribute__((unused)),
|
||||||
SWGSDRangel::SWGChannelSettings& response __attribute__((unused)),
|
SWGSDRangel::SWGSuccessResponse& response __attribute__((unused)),
|
||||||
SWGSDRangel::SWGErrorResponse& error)
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
||||||
{
|
{
|
||||||
error.init();
|
error.init();
|
||||||
*error.getMessage() = QString("Function not implemented");
|
*error.getMessage() = QString("Function not implemented");
|
||||||
return 501;
|
return 501;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1111,9 +1111,8 @@ void WebAPIRequestMapper::devicesetChannelIndexService(
|
|||||||
|
|
||||||
if (request.getMethod() == "DELETE")
|
if (request.getMethod() == "DELETE")
|
||||||
{
|
{
|
||||||
SWGSDRangel::SWGChannelSettings normalResponse;
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
||||||
resetChannelSettings(normalResponse);
|
int status = m_adapter->devicesetChannelDelete(deviceSetIndex, channelIndex, normalResponse, errorResponse);
|
||||||
int status = m_adapter->devicesetChannelIndexDelete(deviceSetIndex, channelIndex, normalResponse, errorResponse);
|
|
||||||
|
|
||||||
response.setStatus(status);
|
response.setStatus(status);
|
||||||
|
|
||||||
|
@ -99,6 +99,26 @@ void DeviceSet::freeTxChannels()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceSet::deleteRxChannel(int channelIndex)
|
||||||
|
{
|
||||||
|
if (channelIndex < m_rxChannelInstanceRegistrations.count())
|
||||||
|
{
|
||||||
|
m_rxChannelInstanceRegistrations[channelIndex].m_channelSinkAPI->destroy();
|
||||||
|
m_rxChannelInstanceRegistrations.removeAt(channelIndex);
|
||||||
|
renameRxChannelInstances();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceSet::deleteTxChannel(int channelIndex)
|
||||||
|
{
|
||||||
|
if (channelIndex < m_txChannelInstanceRegistrations.count())
|
||||||
|
{
|
||||||
|
m_txChannelInstanceRegistrations[channelIndex].m_channelSourceAPI->destroy();
|
||||||
|
m_txChannelInstanceRegistrations.removeAt(channelIndex);
|
||||||
|
renameTxChannelInstances();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
|
void DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
|
||||||
{
|
{
|
||||||
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins
|
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins
|
||||||
|
@ -38,8 +38,12 @@ struct DeviceSet
|
|||||||
DeviceSet(int tabIndex);
|
DeviceSet(int tabIndex);
|
||||||
~DeviceSet();
|
~DeviceSet();
|
||||||
|
|
||||||
|
int getNumberOfRxChannels() const { return m_rxChannelInstanceRegistrations.size(); }
|
||||||
|
int getNumberOfTxChannels() const { return m_txChannelInstanceRegistrations.size(); }
|
||||||
void addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
|
void addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
|
||||||
void addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
|
void addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
|
||||||
|
void deleteRxChannel(int channelIndex);
|
||||||
|
void deleteTxChannel(int channelIndex);
|
||||||
void registerRxChannelInstance(const QString& channelName, ChannelSinkAPI* channelAPI);
|
void registerRxChannelInstance(const QString& channelName, ChannelSinkAPI* channelAPI);
|
||||||
void registerTxChannelInstance(const QString& channelName, ChannelSourceAPI* channelAPI);
|
void registerTxChannelInstance(const QString& channelName, ChannelSourceAPI* channelAPI);
|
||||||
void removeRxChannelInstance(ChannelSinkAPI* channelAPI);
|
void removeRxChannelInstance(ChannelSinkAPI* channelAPI);
|
||||||
|
@ -42,6 +42,7 @@ MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message)
|
|||||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
|
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgSetDevice, Message)
|
MESSAGE_CLASS_DEFINITION(MainCore::MsgSetDevice, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddChannel, Message)
|
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddChannel, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteChannel, Message)
|
||||||
|
|
||||||
MainCore *MainCore::m_instance = 0;
|
MainCore *MainCore::m_instance = 0;
|
||||||
|
|
||||||
@ -161,7 +162,12 @@ bool MainCore::handleMessage(const Message& cmd)
|
|||||||
addChannel(notif.getDeviceSetIndex(), notif.getChannelRegistrationIndex());
|
addChannel(notif.getDeviceSetIndex(), notif.getChannelRegistrationIndex());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (MsgDeleteChannel::match(cmd))
|
||||||
|
{
|
||||||
|
MsgDeleteChannel& notif = (MsgDeleteChannel&) cmd;
|
||||||
|
deleteChannel(notif.getDeviceSetIndex(), notif.getChannelIndex());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -485,6 +491,23 @@ void MainCore::addChannel(int deviceSetIndex, int selectedChannelIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainCore::deleteChannel(int deviceSetIndex, int channelIndex)
|
||||||
|
{
|
||||||
|
if (deviceSetIndex >= 0)
|
||||||
|
{
|
||||||
|
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
|
||||||
|
|
||||||
|
if (deviceSet->m_deviceSourceEngine) // source device => Rx channels
|
||||||
|
{
|
||||||
|
deviceSet->deleteRxChannel(channelIndex);
|
||||||
|
}
|
||||||
|
else if (deviceSet->m_deviceSinkEngine) // sink device => Tx channels
|
||||||
|
{
|
||||||
|
deviceSet->deleteTxChannel(channelIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainCore::loadPresetSettings(const Preset* preset, int tabIndex)
|
void MainCore::loadPresetSettings(const Preset* preset, int tabIndex)
|
||||||
{
|
{
|
||||||
qDebug("MainCore::loadPresetSettings: preset [%s | %s]",
|
qDebug("MainCore::loadPresetSettings: preset [%s | %s]",
|
||||||
|
@ -66,6 +66,7 @@ public:
|
|||||||
void changeSampleSource(int deviceSetIndex, int selectedDeviceIndex);
|
void changeSampleSource(int deviceSetIndex, int selectedDeviceIndex);
|
||||||
void changeSampleSink(int deviceSetIndex, int selectedDeviceIndex);
|
void changeSampleSink(int deviceSetIndex, int selectedDeviceIndex);
|
||||||
void addChannel(int deviceSetIndex, int selectedChannelIndex);
|
void addChannel(int deviceSetIndex, int selectedChannelIndex);
|
||||||
|
void deleteChannel(int deviceSetIndex, int channelIndex);
|
||||||
|
|
||||||
friend class WebAPIAdapterSrv;
|
friend class WebAPIAdapterSrv;
|
||||||
|
|
||||||
@ -244,6 +245,32 @@ private:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MsgDeleteChannel : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
int getDeviceSetIndex() const { return m_deviceSetIndex; }
|
||||||
|
int getChannelIndex() const { return m_channelIndex; }
|
||||||
|
bool isTx() const { return m_tx; }
|
||||||
|
|
||||||
|
static MsgDeleteChannel* create(int deviceSetIndex, int channelIndex, bool tx)
|
||||||
|
{
|
||||||
|
return new MsgDeleteChannel(deviceSetIndex, channelIndex, tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_deviceSetIndex;
|
||||||
|
int m_channelIndex;
|
||||||
|
bool m_tx;
|
||||||
|
|
||||||
|
MsgDeleteChannel(int deviceSetIndex, int channelIndex, bool tx) :
|
||||||
|
Message(),
|
||||||
|
m_deviceSetIndex(deviceSetIndex),
|
||||||
|
m_channelIndex(channelIndex),
|
||||||
|
m_tx(tx)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
static MainCore *m_instance;
|
static MainCore *m_instance;
|
||||||
MainSettings m_settings;
|
MainSettings m_settings;
|
||||||
int m_masterTabIndex;
|
int m_masterTabIndex;
|
||||||
|
@ -621,7 +621,7 @@ int WebAPIAdapterSrv::instancePresetPost(
|
|||||||
} else if (deviceSet->m_deviceSinkEngine) { // Tx
|
} else if (deviceSet->m_deviceSinkEngine) { // Tx
|
||||||
deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency();
|
deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency();
|
||||||
} else {
|
} else {
|
||||||
*error.getMessage() = QString("Unknown device in device set (not Rx nor Tx)");
|
*error.getMessage() = QString("Device set error");
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,6 +850,7 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsGet(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
error.init();
|
||||||
*error.getMessage() = QString("DeviceSet error");
|
*error.getMessage() = QString("DeviceSet error");
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
@ -858,7 +859,6 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsGet(
|
|||||||
{
|
{
|
||||||
error.init();
|
error.init();
|
||||||
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
|
||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -911,6 +911,7 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
error.init();
|
||||||
*error.getMessage() = QString("DeviceSet error");
|
*error.getMessage() = QString("DeviceSet error");
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
@ -919,7 +920,6 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch(
|
|||||||
{
|
{
|
||||||
error.init();
|
error.init();
|
||||||
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
|
||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1015,6 +1015,71 @@ int WebAPIAdapterSrv::devicesetChannelPost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterSrv::devicesetChannelDelete(
|
||||||
|
int deviceSetIndex,
|
||||||
|
int channelIndex,
|
||||||
|
SWGSDRangel::SWGSuccessResponse& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error)
|
||||||
|
{
|
||||||
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
|
||||||
|
{
|
||||||
|
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
|
||||||
|
|
||||||
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
||||||
|
{
|
||||||
|
if (channelIndex < deviceSet->getNumberOfRxChannels()) {
|
||||||
|
MainCore::MsgDeleteChannel *msg = MainCore::MsgDeleteChannel::create(deviceSetIndex, channelIndex, false);
|
||||||
|
m_mainCore.m_inputMessageQueue.push(msg);
|
||||||
|
|
||||||
|
response.init();
|
||||||
|
*response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
|
||||||
|
|
||||||
|
return 202;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no channel at index %1. There are %2 Rx channels")
|
||||||
|
.arg(channelIndex)
|
||||||
|
.arg(channelIndex < deviceSet->getNumberOfRxChannels());
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
||||||
|
{
|
||||||
|
if (channelIndex < deviceSet->getNumberOfTxChannels()) {
|
||||||
|
MainCore::MsgDeleteChannel *msg = MainCore::MsgDeleteChannel::create(deviceSetIndex, channelIndex, true);
|
||||||
|
m_mainCore.m_inputMessageQueue.push(msg);
|
||||||
|
|
||||||
|
response.init();
|
||||||
|
*response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
|
||||||
|
|
||||||
|
return 202;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no channel at index %1. There are %2 Tx channels")
|
||||||
|
.arg(channelIndex)
|
||||||
|
.arg(channelIndex < deviceSet->getNumberOfRxChannels());
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("DeviceSet error");
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
||||||
{
|
{
|
||||||
deviceSetList->init();
|
deviceSetList->init();
|
||||||
|
@ -152,6 +152,12 @@ public:
|
|||||||
SWGSDRangel::SWGSuccessResponse& response,
|
SWGSDRangel::SWGSuccessResponse& response,
|
||||||
SWGSDRangel::SWGErrorResponse& error);
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int devicesetChannelDelete(
|
||||||
|
int deviceSetIndex,
|
||||||
|
int channelIndex,
|
||||||
|
SWGSDRangel::SWGSuccessResponse& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainCore& m_mainCore;
|
MainCore& m_mainCore;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user