mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
File output: Make settings assignments atomic. Part of #1329
This commit is contained in:
parent
565d0dd1a0
commit
ba2e407f0c
@ -86,7 +86,7 @@ void FileOutput::openFileStream()
|
||||
|
||||
void FileOutput::init()
|
||||
{
|
||||
applySettings(m_settings, true);
|
||||
applySettings(m_settings, QList<QString>(), true);
|
||||
}
|
||||
|
||||
bool FileOutput::start()
|
||||
@ -167,12 +167,12 @@ bool FileOutput::deserialize(const QByteArray& data)
|
||||
success = false;
|
||||
}
|
||||
|
||||
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(m_settings, true);
|
||||
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(m_settings, true);
|
||||
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
|
||||
@ -199,12 +199,12 @@ void FileOutput::setCenterFrequency(qint64 centerFrequency)
|
||||
FileOutputSettings settings = m_settings;
|
||||
settings.m_centerFrequency = centerFrequency;
|
||||
|
||||
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(settings, false);
|
||||
MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(settings, false);
|
||||
MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
}
|
||||
@ -230,8 +230,7 @@ bool FileOutput::handleMessage(const Message& message)
|
||||
|
||||
if (cmd.getStartStop())
|
||||
{
|
||||
if (m_deviceAPI->initDeviceEngine())
|
||||
{
|
||||
if (m_deviceAPI->initDeviceEngine()) {
|
||||
m_deviceAPI->startDeviceEngine();
|
||||
}
|
||||
}
|
||||
@ -250,7 +249,7 @@ bool FileOutput::handleMessage(const Message& message)
|
||||
{
|
||||
qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput";
|
||||
MsgConfigureFileOutput& conf = (MsgConfigureFileOutput&) message;
|
||||
applySettings(conf.getSettings(), conf.getForce());
|
||||
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
bool forwardChange = false;
|
||||
QList<QString> reverseAPIKeys;
|
||||
|
||||
if (force || (m_settings.m_fileName != settings.m_fileName)) {
|
||||
reverseAPIKeys.append("fileName");
|
||||
}
|
||||
|
||||
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency))
|
||||
if (force || settingsKeys.contains("centerFrequency"))
|
||||
{
|
||||
reverseAPIKeys.append("centerFrequency");
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (force || (m_settings.m_sampleRate != settings.m_sampleRate))
|
||||
if (force || settingsKeys.contains("sampleRate"))
|
||||
{
|
||||
if (m_fileOutputWorker != 0) {
|
||||
m_fileOutputWorker->setSamplerate(settings.m_sampleRate);
|
||||
}
|
||||
|
||||
reverseAPIKeys.append("sampleRate");
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (force || (m_settings.m_log2Interp != settings.m_log2Interp))
|
||||
if (force || settingsKeys.contains("log2Interp"))
|
||||
{
|
||||
if (m_fileOutputWorker != 0) {
|
||||
m_fileOutputWorker->setLog2Interpolation(settings.m_log2Interp);
|
||||
}
|
||||
|
||||
reverseAPIKeys.append("log2Interp");
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (settings.m_useReverseAPI)
|
||||
if (settingsKeys.contains("useReverseAPI"))
|
||||
{
|
||||
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
||||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
||||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
||||
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex);
|
||||
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
||||
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
||||
settingsKeys.contains("reverseAPIAddress") ||
|
||||
settingsKeys.contains("reverseAPIPort") ||
|
||||
settingsKeys.contains("reverseAPIDeviceIndex");
|
||||
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
||||
}
|
||||
|
||||
m_settings = settings;
|
||||
if (force) {
|
||||
m_settings = settings;
|
||||
} else {
|
||||
m_settings.applySettings(settingsKeys, settings);
|
||||
}
|
||||
|
||||
if (forwardChange)
|
||||
{
|
||||
@ -366,12 +362,12 @@ int FileOutput::webapiSettingsPutPatch(
|
||||
FileOutputSettings settings = m_settings;
|
||||
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
||||
|
||||
MsgConfigureFileOutput *msg = MsgConfigureFileOutput::create(settings, force);
|
||||
MsgConfigureFileOutput *msg = MsgConfigureFileOutput::create(settings, deviceSettingsKeys, force);
|
||||
m_inputMessageQueue.push(msg);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
swgDeviceSettings->setDirection(1); // single Tx
|
||||
|
@ -42,20 +42,22 @@ public:
|
||||
|
||||
public:
|
||||
const FileOutputSettings& getSettings() const { return m_settings; }
|
||||
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
|
||||
bool getForce() const { return m_force; }
|
||||
|
||||
static MsgConfigureFileOutput* create(const FileOutputSettings& settings, bool force)
|
||||
{
|
||||
return new MsgConfigureFileOutput(settings, force);
|
||||
static MsgConfigureFileOutput* create(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) {
|
||||
return new MsgConfigureFileOutput(settings, settingsKeys, force);
|
||||
}
|
||||
|
||||
private:
|
||||
FileOutputSettings m_settings;
|
||||
QList<QString> m_settingsKeys;
|
||||
bool m_force;
|
||||
|
||||
MsgConfigureFileOutput(const FileOutputSettings& settings, bool force) :
|
||||
MsgConfigureFileOutput(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) :
|
||||
Message(),
|
||||
m_settings(settings),
|
||||
m_settingsKeys(settingsKeys),
|
||||
m_force(force)
|
||||
{ }
|
||||
};
|
||||
@ -241,8 +243,8 @@ private:
|
||||
void startWorker();
|
||||
void stopWorker();
|
||||
void openFileStream();
|
||||
void applySettings(const FileOutputSettings& settings, bool force = false);
|
||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force);
|
||||
void applySettings(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
|
||||
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force);
|
||||
void webapiReverseSendStartStop(bool start);
|
||||
|
||||
private slots:
|
||||
|
@ -97,6 +97,7 @@ void FileOutputGui::resetToDefaults()
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
displaySettings();
|
||||
m_forceSettings = true;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -130,7 +131,13 @@ bool FileOutputGui::handleMessage(const Message& message)
|
||||
{
|
||||
qDebug("FileOutputGui::handleMessage: message: MsgConfigureFileOutput");
|
||||
const FileOutput::MsgConfigureFileOutput& cfg = (FileOutput::MsgConfigureFileOutput&) message;
|
||||
m_settings = cfg.getSettings();
|
||||
|
||||
if (cfg.getForce()) {
|
||||
m_settings = cfg.getSettings();
|
||||
} else {
|
||||
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
|
||||
}
|
||||
|
||||
blockApplySettings(true);
|
||||
displaySettings();
|
||||
blockApplySettings(false);
|
||||
@ -203,21 +210,24 @@ void FileOutputGui::displaySettings()
|
||||
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
|
||||
ui->sampleRate->setValue(m_settings.m_sampleRate);
|
||||
ui->fileNameText->setText(m_settings.m_fileName);
|
||||
ui->interp->setCurrentIndex(m_settings.m_log2Interp);
|
||||
}
|
||||
|
||||
void FileOutputGui::sendSettings()
|
||||
{
|
||||
if(!m_updateTimer.isActive())
|
||||
if (!m_updateTimer.isActive()) {
|
||||
m_updateTimer.start(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void 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_forceSettings = false;
|
||||
m_settingsKeys.clear();
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
||||
@ -253,12 +263,14 @@ void FileOutputGui::updateStatus()
|
||||
void FileOutputGui::on_centerFrequency_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_centerFrequency = value * 1000;
|
||||
m_settingsKeys.append("centerFrequency");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void FileOutputGui::on_sampleRate_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_sampleRate = value;
|
||||
m_settingsKeys.append("sampleRate");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -269,6 +281,7 @@ void FileOutputGui::on_interp_currentIndexChanged(int index)
|
||||
}
|
||||
|
||||
m_settings.m_log2Interp = index;
|
||||
m_settingsKeys.append("log2Interp");
|
||||
updateSampleRateAndFrequency();
|
||||
sendSettings();
|
||||
}
|
||||
@ -351,6 +364,10 @@ void FileOutputGui::openDeviceSettingsDialog(const QPoint& p)
|
||||
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
||||
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
||||
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
||||
m_settingsKeys.append("useReverseAPI");
|
||||
m_settingsKeys.append("reverseAPIAddress");
|
||||
m_settingsKeys.append("reverseAPIPort");
|
||||
m_settingsKeys.append("reverseAPIDeviceIndex");
|
||||
|
||||
sendSettings();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ private:
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
FileOutputSettings m_settings;
|
||||
QList<QString> m_settingsKeys;
|
||||
QTimer m_updateTimer;
|
||||
QTimer m_statusTimer;
|
||||
DeviceSampleSink* m_deviceSampleSink;
|
||||
|
@ -88,3 +88,63 @@ bool FileOutputSettings::deserialize(const QByteArray& data)
|
||||
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());
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ struct FileOutputSettings {
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user