mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Local output: Make settings assignments atomic. Part of #1329
This commit is contained in:
parent
77b5d4d5ae
commit
3449293b6a
@ -75,7 +75,7 @@ void LocalOutput::destroy()
|
|||||||
|
|
||||||
void LocalOutput::init()
|
void LocalOutput::init()
|
||||||
{
|
{
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, QList<QString>(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalOutput::start()
|
bool LocalOutput::start()
|
||||||
@ -104,12 +104,12 @@ bool LocalOutput::deserialize(const QByteArray& data)
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgConfigureLocalOutput* message = MsgConfigureLocalOutput::create(m_settings, true);
|
MsgConfigureLocalOutput* message = MsgConfigureLocalOutput::create(m_settings, QList<QString>(), true);
|
||||||
m_inputMessageQueue.push(message);
|
m_inputMessageQueue.push(message);
|
||||||
|
|
||||||
if (m_guiMessageQueue)
|
if (m_guiMessageQueue)
|
||||||
{
|
{
|
||||||
MsgConfigureLocalOutput* messageToGUI = MsgConfigureLocalOutput::create(m_settings, true);
|
MsgConfigureLocalOutput* messageToGUI = MsgConfigureLocalOutput::create(m_settings, QList<QString>(), true);
|
||||||
m_guiMessageQueue->push(messageToGUI);
|
m_guiMessageQueue->push(messageToGUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,8 +178,7 @@ bool LocalOutput::handleMessage(const Message& message)
|
|||||||
|
|
||||||
if (cmd.getStartStop())
|
if (cmd.getStartStop())
|
||||||
{
|
{
|
||||||
if (m_deviceAPI->initDeviceEngine())
|
if (m_deviceAPI->initDeviceEngine()) {
|
||||||
{
|
|
||||||
m_deviceAPI->startDeviceEngine();
|
m_deviceAPI->startDeviceEngine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,7 +197,7 @@ bool LocalOutput::handleMessage(const Message& message)
|
|||||||
{
|
{
|
||||||
qDebug() << "LocalOutput::handleMessage:" << message.getIdentifier();
|
qDebug() << "LocalOutput::handleMessage:" << message.getIdentifier();
|
||||||
MsgConfigureLocalOutput& conf = (MsgConfigureLocalOutput&) message;
|
MsgConfigureLocalOutput& conf = (MsgConfigureLocalOutput&) message;
|
||||||
applySettings(conf.getSettings(), conf.getForce());
|
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -207,27 +206,30 @@ bool LocalOutput::handleMessage(const Message& message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalOutput::applySettings(const LocalOutputSettings& settings, bool force)
|
void LocalOutput::applySettings(const LocalOutputSettings& settings, const QList<QString>& settingsKeys, bool force)
|
||||||
{
|
{
|
||||||
|
qDebug() << "LocalOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force);
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
QString remoteAddress;
|
QString remoteAddress;
|
||||||
QList<QString> reverseAPIKeys;
|
QList<QString> reverseAPIKeys;
|
||||||
|
|
||||||
if (settings.m_useReverseAPI)
|
if (settingsKeys.contains("useReverseAPI"))
|
||||||
{
|
{
|
||||||
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
||||||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
settingsKeys.contains("reverseAPIAddress") ||
|
||||||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
settingsKeys.contains("reverseAPIPort") ||
|
||||||
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex);
|
settingsKeys.contains("reverseAPIDeviceIndex");
|
||||||
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_settings = settings;
|
if (force) {
|
||||||
m_remoteAddress = remoteAddress;
|
m_settings = settings;
|
||||||
|
} else {
|
||||||
|
m_settings.applySettings(settingsKeys, settings);
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "LocalOutput::applySettings: "
|
m_remoteAddress = remoteAddress;
|
||||||
<< " m_remoteAddress: " << m_remoteAddress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int LocalOutput::webapiRunGet(
|
int LocalOutput::webapiRunGet(
|
||||||
@ -279,12 +281,12 @@ int LocalOutput::webapiSettingsPutPatch(
|
|||||||
LocalOutputSettings settings = m_settings;
|
LocalOutputSettings settings = m_settings;
|
||||||
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
||||||
|
|
||||||
MsgConfigureLocalOutput *msg = MsgConfigureLocalOutput::create(settings, force);
|
MsgConfigureLocalOutput *msg = MsgConfigureLocalOutput::create(settings, deviceSettingsKeys, force);
|
||||||
m_inputMessageQueue.push(msg);
|
m_inputMessageQueue.push(msg);
|
||||||
|
|
||||||
if (m_guiMessageQueue) // forward to GUI if any
|
if (m_guiMessageQueue) // forward to GUI if any
|
||||||
{
|
{
|
||||||
MsgConfigureLocalOutput *msgToGUI = MsgConfigureLocalOutput::create(settings, force);
|
MsgConfigureLocalOutput *msgToGUI = MsgConfigureLocalOutput::create(settings, deviceSettingsKeys, force);
|
||||||
m_guiMessageQueue->push(msgToGUI);
|
m_guiMessageQueue->push(msgToGUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +344,7 @@ void LocalOutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respons
|
|||||||
response.getLocalOutputReport()->setSampleRate(m_sampleRate);
|
response.getLocalOutputReport()->setSampleRate(m_sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalOutput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const LocalOutputSettings& settings, bool force)
|
void LocalOutput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const LocalOutputSettings& settings, bool force)
|
||||||
{
|
{
|
||||||
(void) deviceSettingsKeys;
|
(void) deviceSettingsKeys;
|
||||||
(void) force;
|
(void) force;
|
||||||
|
@ -43,20 +43,22 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
const LocalOutputSettings& getSettings() const { return m_settings; }
|
const LocalOutputSettings& getSettings() const { return m_settings; }
|
||||||
|
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
|
||||||
bool getForce() const { return m_force; }
|
bool getForce() const { return m_force; }
|
||||||
|
|
||||||
static MsgConfigureLocalOutput* create(const LocalOutputSettings& settings, bool force = false)
|
static MsgConfigureLocalOutput* create(const LocalOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false) {
|
||||||
{
|
return new MsgConfigureLocalOutput(settings, settingsKeys, force);
|
||||||
return new MsgConfigureLocalOutput(settings, force);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LocalOutputSettings m_settings;
|
LocalOutputSettings m_settings;
|
||||||
|
QList<QString> m_settingsKeys;
|
||||||
bool m_force;
|
bool m_force;
|
||||||
|
|
||||||
MsgConfigureLocalOutput(const LocalOutputSettings& settings, bool force) :
|
MsgConfigureLocalOutput(const LocalOutputSettings& settings, const QList<QString>& settingsKeys, bool force) :
|
||||||
Message(),
|
Message(),
|
||||||
m_settings(settings),
|
m_settings(settings),
|
||||||
|
m_settingsKeys(settingsKeys),
|
||||||
m_force(force)
|
m_force(force)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
@ -166,9 +168,9 @@ private:
|
|||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
void applySettings(const LocalOutputSettings& settings, bool force = false);
|
void applySettings(const LocalOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
|
||||||
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
||||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const LocalOutputSettings& settings, bool force);
|
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const LocalOutputSettings& settings, bool force);
|
||||||
void webapiReverseSendStartStop(bool start);
|
void webapiReverseSendStartStop(bool start);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -144,7 +144,13 @@ bool LocalOutputGui::handleMessage(const Message& message)
|
|||||||
if (LocalOutput::MsgConfigureLocalOutput::match(message))
|
if (LocalOutput::MsgConfigureLocalOutput::match(message))
|
||||||
{
|
{
|
||||||
const LocalOutput::MsgConfigureLocalOutput& cfg = (LocalOutput::MsgConfigureLocalOutput&) message;
|
const LocalOutput::MsgConfigureLocalOutput& cfg = (LocalOutput::MsgConfigureLocalOutput&) message;
|
||||||
m_settings = cfg.getSettings();
|
|
||||||
|
if (cfg.getForce()) {
|
||||||
|
m_settings = cfg.getSettings();
|
||||||
|
} else {
|
||||||
|
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
|
||||||
|
}
|
||||||
|
|
||||||
blockApplySettings(true);
|
blockApplySettings(true);
|
||||||
displaySettings();
|
displaySettings();
|
||||||
blockApplySettings(false);
|
blockApplySettings(false);
|
||||||
@ -202,8 +208,7 @@ void LocalOutputGui::handleInputMessages()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (handleMessage(*message))
|
if (handleMessage(*message)) {
|
||||||
{
|
|
||||||
delete message;
|
delete message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,8 +237,9 @@ void LocalOutputGui::displaySettings()
|
|||||||
|
|
||||||
void LocalOutputGui::sendSettings()
|
void LocalOutputGui::sendSettings()
|
||||||
{
|
{
|
||||||
if(!m_updateTimer.isActive())
|
if (!m_updateTimer.isActive()) {
|
||||||
m_updateTimer.start(100);
|
m_updateTimer.start(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalOutputGui::on_startStop_toggled(bool checked)
|
void LocalOutputGui::on_startStop_toggled(bool checked)
|
||||||
@ -251,9 +257,10 @@ void LocalOutputGui::updateHardware()
|
|||||||
{
|
{
|
||||||
qDebug() << "LocalOutputGui::updateHardware";
|
qDebug() << "LocalOutputGui::updateHardware";
|
||||||
LocalOutput::MsgConfigureLocalOutput* message =
|
LocalOutput::MsgConfigureLocalOutput* message =
|
||||||
LocalOutput::MsgConfigureLocalOutput::create(m_settings, m_forceSettings);
|
LocalOutput::MsgConfigureLocalOutput::create(m_settings, m_settingsKeys, m_forceSettings);
|
||||||
m_sampleSink->getInputMessageQueue()->push(message);
|
m_sampleSink->getInputMessageQueue()->push(message);
|
||||||
m_forceSettings = false;
|
m_forceSettings = false;
|
||||||
|
m_settingsKeys.clear();
|
||||||
m_updateTimer.stop();
|
m_updateTimer.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,6 +311,10 @@ void LocalOutputGui::openDeviceSettingsDialog(const QPoint& p)
|
|||||||
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
||||||
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
||||||
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
||||||
|
m_settingsKeys.append("useReverseAPI");
|
||||||
|
m_settingsKeys.append("reverseAPIAddress");
|
||||||
|
m_settingsKeys.append("reverseAPIPort");
|
||||||
|
m_settingsKeys.append("reverseAPIDeviceIndex");
|
||||||
|
|
||||||
sendSettings();
|
sendSettings();
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ private:
|
|||||||
Ui::LocalOutputGui* ui;
|
Ui::LocalOutputGui* ui;
|
||||||
|
|
||||||
LocalOutputSettings m_settings; //!< current settings
|
LocalOutputSettings m_settings; //!< current settings
|
||||||
|
QList<QString> m_settingsKeys;
|
||||||
LocalOutput* m_sampleSink;
|
LocalOutput* m_sampleSink;
|
||||||
bool m_acquisition;
|
bool m_acquisition;
|
||||||
int m_streamSampleRate; //!< Sample rate of received stream
|
int m_streamSampleRate; //!< Sample rate of received stream
|
||||||
|
@ -77,5 +77,38 @@ bool LocalOutputSettings::deserialize(const QByteArray& data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalOutputSettings::applySettings(const QStringList& settingsKeys, const LocalOutputSettings& settings)
|
||||||
|
{
|
||||||
|
if (settingsKeys.contains("useReverseAPI")) {
|
||||||
|
m_useReverseAPI = settings.m_useReverseAPI;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIAddress")) {
|
||||||
|
m_reverseAPIAddress = settings.m_reverseAPIAddress;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIPort")) {
|
||||||
|
m_reverseAPIPort = settings.m_reverseAPIPort;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIDeviceIndex")) {
|
||||||
|
m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LocalOutputSettings::getDebugString(const QStringList& settingsKeys, bool force) const
|
||||||
|
{
|
||||||
|
std::ostringstream ostr;
|
||||||
|
|
||||||
|
if (settingsKeys.contains("useReverseAPI") || force) {
|
||||||
|
ostr << " m_useReverseAPI: " << m_useReverseAPI;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIAddress") || force) {
|
||||||
|
ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString();
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIPort") || force) {
|
||||||
|
ostr << " m_reverseAPIPort: " << m_reverseAPIPort;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("reverseAPIDeviceIndex") || force) {
|
||||||
|
ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString(ostr.str().c_str());
|
||||||
|
}
|
||||||
|
@ -31,6 +31,8 @@ struct LocalOutputSettings {
|
|||||||
void resetToDefaults();
|
void resetToDefaults();
|
||||||
QByteArray serialize() const;
|
QByteArray serialize() const;
|
||||||
bool deserialize(const QByteArray& data);
|
bool deserialize(const QByteArray& data);
|
||||||
|
void applySettings(const QStringList& settingsKeys, const LocalOutputSettings& settings);
|
||||||
|
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PLUGINS_SAMPLESINK_LOCALOUTPUT_LOCALOUTPUTSETTINGS_H_ */
|
#endif /* PLUGINS_SAMPLESINK_LOCALOUTPUT_LOCALOUTPUTSETTINGS_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user