1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

File output: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-10-30 10:25:19 +01:00
parent 565d0dd1a0
commit ba2e407f0c
6 changed files with 117 additions and 39 deletions

View File

@ -86,7 +86,7 @@ void FileOutput::openFileStream()
void FileOutput::init() void FileOutput::init()
{ {
applySettings(m_settings, true); applySettings(m_settings, QList<QString>(), true);
} }
bool FileOutput::start() bool FileOutput::start()
@ -167,12 +167,12 @@ bool FileOutput::deserialize(const QByteArray& data)
success = false; success = false;
} }
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(m_settings, true); MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message); m_inputMessageQueue.push(message);
if (m_guiMessageQueue) if (m_guiMessageQueue)
{ {
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(m_settings, true); MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI); m_guiMessageQueue->push(messageToGUI);
} }
@ -199,12 +199,12 @@ void FileOutput::setCenterFrequency(qint64 centerFrequency)
FileOutputSettings settings = m_settings; FileOutputSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency; settings.m_centerFrequency = centerFrequency;
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(settings, false); MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message); m_inputMessageQueue.push(message);
if (m_guiMessageQueue) if (m_guiMessageQueue)
{ {
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(settings, false); MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI); m_guiMessageQueue->push(messageToGUI);
} }
} }
@ -230,8 +230,7 @@ bool FileOutput::handleMessage(const Message& message)
if (cmd.getStartStop()) if (cmd.getStartStop())
{ {
if (m_deviceAPI->initDeviceEngine()) if (m_deviceAPI->initDeviceEngine()) {
{
m_deviceAPI->startDeviceEngine(); m_deviceAPI->startDeviceEngine();
} }
} }
@ -250,7 +249,7 @@ bool FileOutput::handleMessage(const Message& message)
{ {
qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput"; qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput";
MsgConfigureFileOutput& conf = (MsgConfigureFileOutput&) message; MsgConfigureFileOutput& conf = (MsgConfigureFileOutput&) message;
applySettings(conf.getSettings(), conf.getForce()); applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
return true; return true;
} }
else if (MsgConfigureFileOutputWork::match(message)) else if (MsgConfigureFileOutputWork::match(message))
@ -287,52 +286,49 @@ bool FileOutput::handleMessage(const Message& message)
} }
} }
void FileOutput::applySettings(const FileOutputSettings& settings, bool force) void FileOutput::applySettings(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force)
{ {
qDebug() << "FileOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force);
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false; bool forwardChange = false;
QList<QString> reverseAPIKeys;
if (force || (m_settings.m_fileName != settings.m_fileName)) { if (force || settingsKeys.contains("centerFrequency"))
reverseAPIKeys.append("fileName");
}
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency))
{ {
reverseAPIKeys.append("centerFrequency");
forwardChange = true; forwardChange = true;
} }
if (force || (m_settings.m_sampleRate != settings.m_sampleRate)) if (force || settingsKeys.contains("sampleRate"))
{ {
if (m_fileOutputWorker != 0) { if (m_fileOutputWorker != 0) {
m_fileOutputWorker->setSamplerate(settings.m_sampleRate); m_fileOutputWorker->setSamplerate(settings.m_sampleRate);
} }
reverseAPIKeys.append("sampleRate");
forwardChange = true; forwardChange = true;
} }
if (force || (m_settings.m_log2Interp != settings.m_log2Interp)) if (force || settingsKeys.contains("log2Interp"))
{ {
if (m_fileOutputWorker != 0) { if (m_fileOutputWorker != 0) {
m_fileOutputWorker->setLog2Interpolation(settings.m_log2Interp); m_fileOutputWorker->setLog2Interpolation(settings.m_log2Interp);
} }
reverseAPIKeys.append("log2Interp");
forwardChange = true; forwardChange = true;
} }
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);
} }
if (force) {
m_settings = settings; m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
if (forwardChange) if (forwardChange)
{ {
@ -366,12 +362,12 @@ int FileOutput::webapiSettingsPutPatch(
FileOutputSettings settings = m_settings; FileOutputSettings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
MsgConfigureFileOutput *msg = MsgConfigureFileOutput::create(settings, force); MsgConfigureFileOutput *msg = MsgConfigureFileOutput::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
{ {
MsgConfigureFileOutput *msgToGUI = MsgConfigureFileOutput::create(settings, force); MsgConfigureFileOutput *msgToGUI = MsgConfigureFileOutput::create(settings, deviceSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI); m_guiMessageQueue->push(msgToGUI);
} }
@ -457,7 +453,7 @@ void FileOutput::webapiUpdateDeviceSettings(
} }
} }
void FileOutput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force) void FileOutput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force)
{ {
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
swgDeviceSettings->setDirection(1); // single Tx swgDeviceSettings->setDirection(1); // single Tx

View File

@ -42,20 +42,22 @@ public:
public: public:
const FileOutputSettings& getSettings() const { return m_settings; } const FileOutputSettings& 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 MsgConfigureFileOutput* create(const FileOutputSettings& settings, bool force) static MsgConfigureFileOutput* create(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) {
{ return new MsgConfigureFileOutput(settings, settingsKeys, force);
return new MsgConfigureFileOutput(settings, force);
} }
private: private:
FileOutputSettings m_settings; FileOutputSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force; bool m_force;
MsgConfigureFileOutput(const FileOutputSettings& settings, bool force) : MsgConfigureFileOutput(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(), Message(),
m_settings(settings), m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force) m_force(force)
{ } { }
}; };
@ -241,8 +243,8 @@ private:
void startWorker(); void startWorker();
void stopWorker(); void stopWorker();
void openFileStream(); void openFileStream();
void applySettings(const FileOutputSettings& settings, bool force = false); void applySettings(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force); void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force);
void webapiReverseSendStartStop(bool start); void webapiReverseSendStartStop(bool start);
private slots: private slots:

View File

@ -97,6 +97,7 @@ void FileOutputGui::resetToDefaults()
{ {
m_settings.resetToDefaults(); m_settings.resetToDefaults();
displaySettings(); displaySettings();
m_forceSettings = true;
sendSettings(); sendSettings();
} }
@ -130,7 +131,13 @@ bool FileOutputGui::handleMessage(const Message& message)
{ {
qDebug("FileOutputGui::handleMessage: message: MsgConfigureFileOutput"); qDebug("FileOutputGui::handleMessage: message: MsgConfigureFileOutput");
const FileOutput::MsgConfigureFileOutput& cfg = (FileOutput::MsgConfigureFileOutput&) message; const FileOutput::MsgConfigureFileOutput& cfg = (FileOutput::MsgConfigureFileOutput&) message;
if (cfg.getForce()) {
m_settings = cfg.getSettings(); m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true); blockApplySettings(true);
displaySettings(); displaySettings();
blockApplySettings(false); blockApplySettings(false);
@ -203,21 +210,24 @@ void FileOutputGui::displaySettings()
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->sampleRate->setValue(m_settings.m_sampleRate); ui->sampleRate->setValue(m_settings.m_sampleRate);
ui->fileNameText->setText(m_settings.m_fileName); ui->fileNameText->setText(m_settings.m_fileName);
ui->interp->setCurrentIndex(m_settings.m_log2Interp);
} }
void FileOutputGui::sendSettings() void FileOutputGui::sendSettings()
{ {
if(!m_updateTimer.isActive()) if (!m_updateTimer.isActive()) {
m_updateTimer.start(100); m_updateTimer.start(100);
} }
}
void FileOutputGui::updateHardware() void FileOutputGui::updateHardware()
{ {
qDebug() << "FileOutputGui::updateHardware"; qDebug() << "FileOutputGui::updateHardware";
FileOutput::MsgConfigureFileOutput* message = FileOutput::MsgConfigureFileOutput::create(m_settings, m_forceSettings); FileOutput::MsgConfigureFileOutput* message = FileOutput::MsgConfigureFileOutput::create(m_settings, m_settingsKeys, m_forceSettings);
m_deviceSampleSink->getInputMessageQueue()->push(message); m_deviceSampleSink->getInputMessageQueue()->push(message);
m_forceSettings = false; m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop(); m_updateTimer.stop();
} }
@ -253,12 +263,14 @@ void FileOutputGui::updateStatus()
void FileOutputGui::on_centerFrequency_changed(quint64 value) void FileOutputGui::on_centerFrequency_changed(quint64 value)
{ {
m_settings.m_centerFrequency = value * 1000; m_settings.m_centerFrequency = value * 1000;
m_settingsKeys.append("centerFrequency");
sendSettings(); sendSettings();
} }
void FileOutputGui::on_sampleRate_changed(quint64 value) void FileOutputGui::on_sampleRate_changed(quint64 value)
{ {
m_settings.m_sampleRate = value; m_settings.m_sampleRate = value;
m_settingsKeys.append("sampleRate");
sendSettings(); sendSettings();
} }
@ -269,6 +281,7 @@ void FileOutputGui::on_interp_currentIndexChanged(int index)
} }
m_settings.m_log2Interp = index; m_settings.m_log2Interp = index;
m_settingsKeys.append("log2Interp");
updateSampleRateAndFrequency(); updateSampleRateAndFrequency();
sendSettings(); sendSettings();
} }
@ -351,6 +364,10 @@ void FileOutputGui::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();
} }

View File

@ -57,6 +57,7 @@ private:
bool m_doApplySettings; bool m_doApplySettings;
bool m_forceSettings; bool m_forceSettings;
FileOutputSettings m_settings; FileOutputSettings m_settings;
QList<QString> m_settingsKeys;
QTimer m_updateTimer; QTimer m_updateTimer;
QTimer m_statusTimer; QTimer m_statusTimer;
DeviceSampleSink* m_deviceSampleSink; DeviceSampleSink* m_deviceSampleSink;

View File

@ -88,3 +88,63 @@ bool FileOutputSettings::deserialize(const QByteArray& data)
return false; return false;
} }
} }
void FileOutputSettings::applySettings(const QStringList& settingsKeys, const FileOutputSettings& settings)
{
if (settingsKeys.contains("centerFrequency")) {
m_centerFrequency = settings.m_centerFrequency;
}
if (settingsKeys.contains("sampleRate")) {
m_sampleRate = settings.m_sampleRate;
}
if (settingsKeys.contains("log2Interp")) {
m_log2Interp = settings.m_log2Interp;
}
if (settingsKeys.contains("fileName")) {
m_fileName = settings.m_fileName;
}
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 FileOutputSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("centerFrequency") || force) {
ostr << " m_centerFrequency: " << m_centerFrequency;
}
if (settingsKeys.contains("sampleRate") || force) {
ostr << " m_sampleRate: " << m_sampleRate;
}
if (settingsKeys.contains("log2Interp") || force) {
ostr << " m_log2Interp: " << m_log2Interp;
}
if (settingsKeys.contains("fileName") || force) {
ostr << " m_fileName: " << m_fileName.toStdString();
}
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());
}

View File

@ -32,6 +32,8 @@ struct FileOutputSettings {
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 FileOutputSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
}; };
#endif /* PLUGINS_SAMPLESINK_FILEOUTPUT_FILEOUTPUTSETTINGS_H_ */ #endif /* PLUGINS_SAMPLESINK_FILEOUTPUT_FILEOUTPUTSETTINGS_H_ */