1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 13:51:47 -05:00

Web API: fixed segfault when mixing start/stop between GUI and API. Applied to BladeRF input, SDRdaemon input and SDRPlay

This commit is contained in:
f4exb 2017-12-14 00:19:59 +01:00
parent 8798b64471
commit 53925bd4fd
10 changed files with 199 additions and 66 deletions

View File

@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <QDebug> #include <QDebug>
#include "SWGDeviceSettings.h" #include "SWGDeviceSettings.h"
@ -34,6 +35,7 @@
#include "bladerfinputthread.h" #include "bladerfinputthread.h"
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message) MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message)
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgStartStop, Message)
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgFileRecord, Message) MESSAGE_CLASS_DEFINITION(BladerfInput::MsgFileRecord, Message)
BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) : BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) :
@ -244,6 +246,27 @@ bool BladerfInput::handleMessage(const Message& message)
return true; return true;
} }
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;
qDebug() << "BladerfInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
if (cmd.getStartStop())
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
}
return true;
}
else else
{ {
return false; return false;
@ -558,19 +581,16 @@ int BladerfInput::webapiRun(
SWGSDRangel::SWGDeviceState& response, SWGSDRangel::SWGDeviceState& response,
QString& errorMessage __attribute__((unused))) QString& errorMessage __attribute__((unused)))
{ {
if (run) MsgStartStop *message = MsgStartStop::create(run);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue) // forward to GUI if any
{ {
if (m_deviceAPI->initAcquisition()) MsgStartStop *msgToGUI = MsgStartStop::create(run);
{ m_guiMessageQueue->push(msgToGUI);
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutputImmediate();
}
}
else
{
m_deviceAPI->stopAcquisition();
} }
usleep(100000);
m_deviceAPI->getDeviceEngineStateStr(*response.getState()); m_deviceAPI->getDeviceEngineStateStr(*response.getState());
return 200; return 200;
} }

View File

@ -74,6 +74,25 @@ public:
{ } { }
}; };
class MsgStartStop : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
BladerfInput(DeviceSourceAPI *deviceAPI); BladerfInput(DeviceSourceAPI *deviceAPI);
virtual ~BladerfInput(); virtual ~BladerfInput();
virtual void destroy(); virtual void destroy();

View File

@ -124,10 +124,22 @@ bool BladerfInputGui::deserialize(const QByteArray& data)
} }
} }
bool BladerfInputGui::handleMessage(const Message& message __attribute__((unused))) bool BladerfInputGui::handleMessage(const Message& message)
{
if (BladerfInput::MsgStartStop::match(message))
{
BladerfInput::MsgStartStop& notif = (BladerfInput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
else
{ {
return false; return false;
} }
}
void BladerfInputGui::handleInputMessages() void BladerfInputGui::handleInputMessages()
{ {
@ -147,6 +159,13 @@ void BladerfInputGui::handleInputMessages()
delete message; delete message;
} }
else
{
if (handleMessage(*message))
{
delete message;
}
}
} }
} }
@ -339,18 +358,10 @@ void BladerfInputGui::on_xb200_currentIndexChanged(int index)
void BladerfInputGui::on_startStop_toggled(bool checked) void BladerfInputGui::on_startStop_toggled(bool checked)
{ {
if (checked) if (m_doApplySettings)
{ {
if (m_deviceUISet->m_deviceSourceAPI->initAcquisition()) BladerfInput::MsgStartStop *message = BladerfInput::MsgStartStop::create(checked);
{ m_sampleSource->getInputMessageQueue()->push(message);
m_deviceUISet->m_deviceSourceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceUISet->m_deviceSourceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
} }
} }

View File

@ -247,6 +247,15 @@ bool SDRdaemonSourceGui::handleMessage(const Message& message)
updateWithStreamTime(); updateWithStreamTime();
return true; return true;
} }
else if (SDRdaemonSourceInput::MsgStartStop::match(message))
{
SDRdaemonSourceInput::MsgStartStop& notif = (SDRdaemonSourceInput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
else else
{ {
return false; return false;
@ -591,18 +600,10 @@ void SDRdaemonSourceGui::on_nbFECBlocks_valueChanged(int value)
void SDRdaemonSourceGui::on_startStop_toggled(bool checked) void SDRdaemonSourceGui::on_startStop_toggled(bool checked)
{ {
if (checked) if (m_doApplySettings)
{ {
if (m_deviceUISet->m_deviceSourceAPI->initAcquisition()) SDRdaemonSourceInput::MsgStartStop *message = SDRdaemonSourceInput::MsgStartStop::create(checked);
{ m_sampleSource->getInputMessageQueue()->push(message);
m_deviceUISet->m_deviceSourceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceUISet->m_deviceSourceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
} }
} }

View File

@ -16,6 +16,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <QDebug> #include <QDebug>
#include "SWGDeviceSettings.h" #include "SWGDeviceSettings.h"
@ -40,6 +41,7 @@ MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonAcquisition, Me
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamData, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamData, Message)
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamTiming, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamTiming, Message)
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgFileRecord, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgFileRecord, Message)
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgStartStop, Message)
SDRdaemonSourceInput::SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI) : SDRdaemonSourceInput::SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
@ -138,6 +140,27 @@ bool SDRdaemonSourceInput::handleMessage(const Message& message)
return true; return true;
} }
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;
qDebug() << "SDRdaemonSourceInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
if (cmd.getStartStop())
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
}
return true;
}
else if (MsgConfigureSDRdaemonSource::match(message)) else if (MsgConfigureSDRdaemonSource::match(message))
{ {
qDebug() << "SDRdaemonSourceInput::handleMessage:" << message.getIdentifier(); qDebug() << "SDRdaemonSourceInput::handleMessage:" << message.getIdentifier();
@ -222,19 +245,16 @@ int SDRdaemonSourceInput::webapiRun(
SWGSDRangel::SWGDeviceState& response, SWGSDRangel::SWGDeviceState& response,
QString& errorMessage __attribute__((unused))) QString& errorMessage __attribute__((unused)))
{ {
if (run) MsgStartStop *message = MsgStartStop::create(run);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue) // forward to GUI if any
{ {
if (m_deviceAPI->initAcquisition()) MsgStartStop *msgToGUI = MsgStartStop::create(run);
{ m_guiMessageQueue->push(msgToGUI);
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutputImmediate();
}
}
else
{
m_deviceAPI->stopAcquisition();
} }
usleep(100000);
m_deviceAPI->getDeviceEngineStateStr(*response.getState()); m_deviceAPI->getDeviceEngineStateStr(*response.getState());
return 200; return 200;
} }

View File

@ -303,6 +303,25 @@ public:
{ } { }
}; };
class MsgStartStop : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI); SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI);
virtual ~SDRdaemonSourceInput(); virtual ~SDRdaemonSourceInput();
virtual void destroy(); virtual void destroy();

View File

@ -33,6 +33,7 @@ SDRPlayGui::SDRPlayGui(DeviceUISet *deviceUISet, QWidget* parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::SDRPlayGui), ui(new Ui::SDRPlayGui),
m_deviceUISet(deviceUISet), m_deviceUISet(deviceUISet),
m_doApplySettings(true),
m_forceSettings(true) m_forceSettings(true)
{ {
m_sampleSource = (SDRPlayInput*) m_deviceUISet->m_deviceSourceAPI->getSampleSource(); m_sampleSource = (SDRPlayInput*) m_deviceUISet->m_deviceSourceAPI->getSampleSource();
@ -163,6 +164,15 @@ bool SDRPlayGui::handleMessage(const Message& message)
return true; return true;
} }
else if (SDRPlayInput::MsgStartStop::match(message))
{
SDRPlayInput::MsgStartStop& notif = (SDRPlayInput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
else else
{ {
return false; return false;
@ -433,18 +443,10 @@ void SDRPlayGui::on_gainBaseband_valueChanged(int value)
void SDRPlayGui::on_startStop_toggled(bool checked) void SDRPlayGui::on_startStop_toggled(bool checked)
{ {
if (checked) if (m_doApplySettings)
{ {
if (m_deviceUISet->m_deviceSourceAPI->initAcquisition()) SDRPlayInput::MsgStartStop *message = SDRPlayInput::MsgStartStop::create(checked);
{ m_sampleSource->getInputMessageQueue()->push(message);
m_deviceUISet->m_deviceSourceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceUISet->m_deviceSourceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
} }
} }

View File

@ -57,6 +57,7 @@ private:
Ui::SDRPlayGui* ui; Ui::SDRPlayGui* ui;
DeviceUISet* m_deviceUISet; DeviceUISet* m_deviceUISet;
bool m_doApplySettings;
bool m_forceSettings; bool m_forceSettings;
SDRPlaySettings m_settings; SDRPlaySettings m_settings;
QTimer m_updateTimer; QTimer m_updateTimer;
@ -67,6 +68,7 @@ private:
int m_lastEngineState; int m_lastEngineState;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
void blockApplySettings(bool block) { m_doApplySettings = !block; }
void displaySettings(); void displaySettings();
void sendSettings(); void sendSettings();
void updateSampleRateAndFrequency(); void updateSampleRateAndFrequency();

View File

@ -16,6 +16,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <QDebug> #include <QDebug>
#include "SWGDeviceSettings.h" #include "SWGDeviceSettings.h"
@ -35,6 +36,7 @@
MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgConfigureSDRPlay, Message) MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgConfigureSDRPlay, Message)
MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgReportSDRPlayGains, Message) MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgReportSDRPlayGains, Message)
MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgFileRecord, Message) MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgFileRecord, Message)
MESSAGE_CLASS_DEFINITION(SDRPlayInput::MsgStartStop, Message)
SDRPlayInput::SDRPlayInput(DeviceSourceAPI *deviceAPI) : SDRPlayInput::SDRPlayInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
@ -256,6 +258,27 @@ bool SDRPlayInput::handleMessage(const Message& message)
return true; return true;
} }
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;
qDebug() << "SDRPlayInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
if (cmd.getStartStop())
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
}
return true;
}
else else
{ {
return false; return false;
@ -582,19 +605,16 @@ int SDRPlayInput::webapiRun(
SWGSDRangel::SWGDeviceState& response, SWGSDRangel::SWGDeviceState& response,
QString& errorMessage __attribute__((unused))) QString& errorMessage __attribute__((unused)))
{ {
if (run) MsgStartStop *message = MsgStartStop::create(run);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue) // forward to GUI if any
{ {
if (m_deviceAPI->initAcquisition()) MsgStartStop *msgToGUI = MsgStartStop::create(run);
{ m_guiMessageQueue->push(msgToGUI);
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutputImmediate();
}
}
else
{
m_deviceAPI->stopAcquisition();
} }
usleep(100000);
m_deviceAPI->getDeviceEngineStateStr(*response.getState()); m_deviceAPI->getDeviceEngineStateStr(*response.getState());
return 200; return 200;
} }

View File

@ -101,6 +101,25 @@ public:
{ } { }
}; };
class MsgStartStop : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
SDRPlayInput(DeviceSourceAPI *deviceAPI); SDRPlayInput(DeviceSourceAPI *deviceAPI);
virtual ~SDRPlayInput(); virtual ~SDRPlayInput();
virtual void destroy(); virtual void destroy();