mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
FileInput: Make settings assignments atomic. Part of #1329
This commit is contained in:
parent
8dfda5e534
commit
90cab1dfda
@ -325,12 +325,12 @@ bool FileInput::deserialize(const QByteArray& data)
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgConfigureFileInput* message = MsgConfigureFileInput::create(m_settings, true);
|
MsgConfigureFileInput* message = MsgConfigureFileInput::create(m_settings, QList<QString>(), true);
|
||||||
m_inputMessageQueue.push(message);
|
m_inputMessageQueue.push(message);
|
||||||
|
|
||||||
if (getMessageQueueToGUI())
|
if (getMessageQueueToGUI())
|
||||||
{
|
{
|
||||||
MsgConfigureFileInput* messageToGUI = MsgConfigureFileInput::create(m_settings, true);
|
MsgConfigureFileInput* messageToGUI = MsgConfigureFileInput::create(m_settings, QList<QString>(), true);
|
||||||
getMessageQueueToGUI()->push(messageToGUI);
|
getMessageQueueToGUI()->push(messageToGUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,12 +357,12 @@ void FileInput::setCenterFrequency(qint64 centerFrequency)
|
|||||||
FileInputSettings settings = m_settings;
|
FileInputSettings settings = m_settings;
|
||||||
m_centerFrequency = centerFrequency;
|
m_centerFrequency = centerFrequency;
|
||||||
|
|
||||||
MsgConfigureFileInput* message = MsgConfigureFileInput::create(m_settings, false);
|
MsgConfigureFileInput* message = MsgConfigureFileInput::create(m_settings, QList<QString>{"centerFrequency"}, false);
|
||||||
m_inputMessageQueue.push(message);
|
m_inputMessageQueue.push(message);
|
||||||
|
|
||||||
if (getMessageQueueToGUI())
|
if (getMessageQueueToGUI())
|
||||||
{
|
{
|
||||||
MsgConfigureFileInput* messageToGUI = MsgConfigureFileInput::create(m_settings, false);
|
MsgConfigureFileInput* messageToGUI = MsgConfigureFileInput::create(m_settings, QList<QString>{"centerFrequency"}, false);
|
||||||
getMessageQueueToGUI()->push(messageToGUI);
|
getMessageQueueToGUI()->push(messageToGUI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,8 +377,7 @@ bool FileInput::handleMessage(const Message& message)
|
|||||||
if (MsgConfigureFileInput::match(message))
|
if (MsgConfigureFileInput::match(message))
|
||||||
{
|
{
|
||||||
MsgConfigureFileInput& conf = (MsgConfigureFileInput&) message;
|
MsgConfigureFileInput& conf = (MsgConfigureFileInput&) message;
|
||||||
FileInputSettings settings = conf.getSettings();
|
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
|
||||||
applySettings(settings);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (MsgConfigureFileSourceName::match(message))
|
else if (MsgConfigureFileSourceName::match(message))
|
||||||
@ -482,14 +481,12 @@ bool FileInput::handleMessage(const Message& message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileInput::applySettings(const FileInputSettings& settings, bool force)
|
bool FileInput::applySettings(const FileInputSettings& settings, const QList<QString>& settingsKeys, bool force)
|
||||||
{
|
{
|
||||||
QList<QString> reverseAPIKeys;
|
qDebug() << "FileInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force);
|
||||||
|
|
||||||
if ((m_settings.m_accelerationFactor != settings.m_accelerationFactor) || force)
|
if (settingsKeys.contains("accelerationFactor") || force)
|
||||||
{
|
{
|
||||||
reverseAPIKeys.append("accelerationFactor");
|
|
||||||
|
|
||||||
if (m_fileInputWorker)
|
if (m_fileInputWorker)
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
@ -501,27 +498,25 @@ bool FileInput::applySettings(const FileInputSettings& settings, bool force)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_loop != settings.m_loop)) {
|
if (settingsKeys.contains("useReverseAPI"))
|
||||||
reverseAPIKeys.append("loop");
|
|
||||||
}
|
|
||||||
if ((m_settings.m_fileName != settings.m_fileName)) {
|
|
||||||
reverseAPIKeys.append("fileName");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.m_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);
|
||||||
|
}
|
||||||
|
|
||||||
// Open the file if there isn't a GUI which will open it
|
// Open the file if there isn't a GUI which will open it
|
||||||
if ((m_guiMessageQueue == nullptr) && reverseAPIKeys.contains("fileName") && !m_settings.m_fileName.isEmpty())
|
if ((m_guiMessageQueue == nullptr) && settingsKeys.contains("fileName") && !m_settings.m_fileName.isEmpty()) {
|
||||||
openFileStream();
|
openFileStream();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -547,12 +542,12 @@ int FileInput::webapiSettingsPutPatch(
|
|||||||
FileInputSettings settings = m_settings;
|
FileInputSettings settings = m_settings;
|
||||||
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
||||||
|
|
||||||
MsgConfigureFileInput *msg = MsgConfigureFileInput::create(settings, force);
|
MsgConfigureFileInput *msg = MsgConfigureFileInput::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
|
||||||
{
|
{
|
||||||
MsgConfigureFileInput *msgToGUI = MsgConfigureFileInput::create(settings, force);
|
MsgConfigureFileInput *msgToGUI = MsgConfigureFileInput::create(settings, deviceSettingsKeys, force);
|
||||||
m_guiMessageQueue->push(msgToGUI);
|
m_guiMessageQueue->push(msgToGUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,7 +676,7 @@ void FileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
|
|||||||
response.getFileInputReport()->setSampleSize(m_sampleSize);
|
response.getFileInputReport()->setSampleSize(m_sampleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileInputSettings& settings, bool force)
|
void FileInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileInputSettings& settings, bool force)
|
||||||
{
|
{
|
||||||
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
||||||
swgDeviceSettings->setDirection(0); // single Rx
|
swgDeviceSettings->setDirection(0); // single Rx
|
||||||
|
@ -45,20 +45,22 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
const FileInputSettings& getSettings() const { return m_settings; }
|
const FileInputSettings& 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 MsgConfigureFileInput* create(const FileInputSettings& settings, bool force)
|
static MsgConfigureFileInput* create(const FileInputSettings& settings, const QList<QString>& settingsKeys, bool force) {
|
||||||
{
|
return new MsgConfigureFileInput(settings, settingsKeys, force);
|
||||||
return new MsgConfigureFileInput(settings, force);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileInputSettings m_settings;
|
FileInputSettings m_settings;
|
||||||
|
QList<QString> m_settingsKeys;
|
||||||
bool m_force;
|
bool m_force;
|
||||||
|
|
||||||
MsgConfigureFileInput(const FileInputSettings& settings, bool force) :
|
MsgConfigureFileInput(const FileInputSettings& settings, const QList<QString>& settingsKeys, bool force) :
|
||||||
Message(),
|
Message(),
|
||||||
m_settings(settings),
|
m_settings(settings),
|
||||||
|
m_settingsKeys(settingsKeys),
|
||||||
m_force(force)
|
m_force(force)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
@ -349,9 +351,9 @@ public:
|
|||||||
void stopWorker();
|
void stopWorker();
|
||||||
void openFileStream();
|
void openFileStream();
|
||||||
void seekFileStream(int seekMillis);
|
void seekFileStream(int seekMillis);
|
||||||
bool applySettings(const FileInputSettings& settings, bool force = false);
|
bool applySettings(const FileInputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
|
||||||
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
||||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileInputSettings& settings, bool force);
|
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileInputSettings& settings, bool force);
|
||||||
void webapiReverseSendStartStop(bool start);
|
void webapiReverseSendStartStop(bool start);
|
||||||
bool handleMessage(const Message& message);
|
bool handleMessage(const Message& message);
|
||||||
|
|
||||||
|
@ -156,7 +156,13 @@ bool FileInputGUI::handleMessage(const Message& message)
|
|||||||
if (FileInput::MsgConfigureFileInput::match(message))
|
if (FileInput::MsgConfigureFileInput::match(message))
|
||||||
{
|
{
|
||||||
const FileInput::MsgConfigureFileInput& cfg = (FileInput::MsgConfigureFileInput&) message;
|
const FileInput::MsgConfigureFileInput& cfg = (FileInput::MsgConfigureFileInput&) message;
|
||||||
|
|
||||||
|
if (cfg.getForce()) {
|
||||||
m_settings = cfg.getSettings();
|
m_settings = cfg.getSettings();
|
||||||
|
} else {
|
||||||
|
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
|
||||||
|
}
|
||||||
|
|
||||||
displaySettings();
|
displaySettings();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -249,7 +255,7 @@ void FileInputGUI::on_playLoop_toggled(bool checked)
|
|||||||
if (m_doApplySettings)
|
if (m_doApplySettings)
|
||||||
{
|
{
|
||||||
m_settings.m_loop = checked;
|
m_settings.m_loop = checked;
|
||||||
FileInput::MsgConfigureFileInput *message = FileInput::MsgConfigureFileInput::create(m_settings, false);
|
FileInput::MsgConfigureFileInput *message = FileInput::MsgConfigureFileInput::create(m_settings, QList<QString>{"loop"}, false);
|
||||||
m_sampleSource->getInputMessageQueue()->push(message);
|
m_sampleSource->getInputMessageQueue()->push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,7 +336,7 @@ void FileInputGUI::on_acceleration_currentIndexChanged(int index)
|
|||||||
if (m_doApplySettings)
|
if (m_doApplySettings)
|
||||||
{
|
{
|
||||||
m_settings.m_accelerationFactor = FileInputSettings::getAccelerationValue(index);
|
m_settings.m_accelerationFactor = FileInputSettings::getAccelerationValue(index);
|
||||||
FileInput::MsgConfigureFileInput *message = FileInput::MsgConfigureFileInput::create(m_settings, false);
|
FileInput::MsgConfigureFileInput *message = FileInput::MsgConfigureFileInput::create(m_settings, QList<QString>{"accelerationFactor"}, false);
|
||||||
m_sampleSource->getInputMessageQueue()->push(message);
|
m_sampleSource->getInputMessageQueue()->push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ private:
|
|||||||
Ui::FileInputGUI* ui;
|
Ui::FileInputGUI* ui;
|
||||||
|
|
||||||
FileInputSettings m_settings;
|
FileInputSettings m_settings;
|
||||||
|
QList<QString> m_settingsKeys;
|
||||||
bool m_doApplySettings;
|
bool m_doApplySettings;
|
||||||
QTimer m_statusTimer;
|
QTimer m_statusTimer;
|
||||||
std::vector<int> m_gains;
|
std::vector<int> m_gains;
|
||||||
|
@ -143,7 +143,56 @@ int FileInputSettings::getAccelerationValue(int accelerationIndex)
|
|||||||
return x * m;
|
return x * m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileInputSettings::applySettings(const QStringList& settingsKeys, const FileInputSettings& settings)
|
||||||
|
{
|
||||||
|
if (settingsKeys.contains("fileName")) {
|
||||||
|
m_fileName = settings.m_fileName;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("accelerationFactor")) {
|
||||||
|
m_accelerationFactor = settings.m_accelerationFactor;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("loop")) {
|
||||||
|
m_loop = settings.m_loop;
|
||||||
|
}
|
||||||
|
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 FileInputSettings::getDebugString(const QStringList& settingsKeys, bool force) const
|
||||||
|
{
|
||||||
|
std::ostringstream ostr;
|
||||||
|
|
||||||
|
if (settingsKeys.contains("m_fileName") || force) {
|
||||||
|
ostr << " m_fileName: " << m_fileName.toStdString();
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("accelerationFactor") || force) {
|
||||||
|
ostr << " m_accelerationFactor: " << m_accelerationFactor;
|
||||||
|
}
|
||||||
|
if (settingsKeys.contains("loop") || force) {
|
||||||
|
ostr << " m_loop: " << m_loop;
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
@ -38,6 +38,8 @@ struct FileInputSettings {
|
|||||||
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 FileInputSettings& settings);
|
||||||
|
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
|
||||||
static int getAccelerationIndex(int averaging);
|
static int getAccelerationIndex(int averaging);
|
||||||
static int getAccelerationValue(int averagingIndex);
|
static int getAccelerationValue(int averagingIndex);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user