Skip to content

Commit

Permalink
Radiosonde feature: Make settings assignments atomic. Part of #1329
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Nov 27, 2022
1 parent 6bba016 commit ecdc464
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 42 deletions.
91 changes: 58 additions & 33 deletions plugins/feature/radiosonde/radiosonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool Radiosonde::handleMessage(const Message& cmd)
{
MsgConfigureRadiosonde& cfg = (MsgConfigureRadiosonde&) cmd;
qDebug() << "Radiosonde::handleMessage: MsgConfigureRadiosonde";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());

return true;
}
Expand Down Expand Up @@ -127,51 +127,38 @@ bool Radiosonde::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(m_settings, true);
MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(m_settings, true);
MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return false;
}
}

void Radiosonde::applySettings(const RadiosondeSettings& settings, bool force)
void Radiosonde::applySettings(const RadiosondeSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "Radiosonde::applySettings:"
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_useReverseAPI: " << settings.m_useReverseAPI
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
<< " m_reverseAPIFeatureSetIndex: " << settings.m_reverseAPIFeatureSetIndex
<< " m_reverseAPIFeatureIndex: " << settings.m_reverseAPIFeatureIndex
<< " force: " << force;
qDebug() << "Radiosonde::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;

QList<QString> reverseAPIKeys;

if ((m_settings.m_title != settings.m_title) || force) {
reverseAPIKeys.append("title");
}
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
reverseAPIKeys.append("rgbColor");
}

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_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) ||
(m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex);
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
settingsKeys.contains("m_reverseAPIFeatureIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}

m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}

int Radiosonde::webapiSettingsGet(
Expand All @@ -195,12 +182,12 @@ int Radiosonde::webapiSettingsPutPatch(
RadiosondeSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);

MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(settings, force);
MsgConfigureRadiosonde *msg = MsgConfigureRadiosonde::create(settings, featureSettingsKeys, force);
m_inputMessageQueue.push(msg);

if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRadiosonde *msgToGUI = MsgConfigureRadiosonde::create(settings, force);
MsgConfigureRadiosonde *msgToGUI = MsgConfigureRadiosonde::create(settings, featureSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}

Expand Down Expand Up @@ -245,6 +232,26 @@ void Radiosonde::webapiFormatFeatureSettings(
response.getRadiosondeSettings()->setRollupState(swgRollupState);
}
}

if (!response.getRadiosondeSettings()->getRadiosondesColumnIndexes()) {
response.getRadiosondeSettings()->setRadiosondesColumnIndexes(new QList<int>());
}

response.getRadiosondeSettings()->getRadiosondesColumnIndexes()->clear();

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
response.getRadiosondeSettings()->getRadiosondesColumnIndexes()->push_back(settings.m_radiosondesColumnIndexes[i]);
}

if (!response.getRadiosondeSettings()->getRadiosondesColumnSizes()) {
response.getRadiosondeSettings()->setRadiosondesColumnSizes(new QList<int>());
}

response.getRadiosondeSettings()->getRadiosondesColumnSizes()->clear();

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
response.getRadiosondeSettings()->getRadiosondesColumnSizes()->push_back(settings.m_radiosondesColumnSizes[i]);
}
}

void Radiosonde::webapiUpdateFeatureSettings(
Expand Down Expand Up @@ -276,9 +283,27 @@ void Radiosonde::webapiUpdateFeatureSettings(
if (settings.m_rollupState && featureSettingsKeys.contains("rollupState")) {
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getRadiosondeSettings()->getRollupState());
}

if (featureSettingsKeys.contains("radiosondesColumnIndexes"))
{
const QList<int> *indexes = response.getRadiosondeSettings()->getRadiosondesColumnIndexes();

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
settings.m_radiosondesColumnIndexes[i] = (*indexes)[i];
}
}

if (featureSettingsKeys.contains("vesselColumnSizes"))
{
const QList<int> *indexes = response.getRadiosondeSettings()->getRadiosondesColumnSizes();

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
settings.m_radiosondesColumnSizes[i] = (*indexes)[i];
}
}
}

void Radiosonde::webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const RadiosondeSettings& settings, bool force)
void Radiosonde::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const RadiosondeSettings& settings, bool force)
{
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());
Expand Down
13 changes: 8 additions & 5 deletions plugins/feature/radiosonde/radiosonde.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ class Radiosonde : public Feature

public:
const RadiosondeSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }

static MsgConfigureRadiosonde* create(const RadiosondeSettings& settings, bool force) {
return new MsgConfigureRadiosonde(settings, force);
static MsgConfigureRadiosonde* create(const RadiosondeSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureRadiosonde(settings, settingsKeys, force);
}

private:
RadiosondeSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;

MsgConfigureRadiosonde(const RadiosondeSettings& settings, bool force) :
MsgConfigureRadiosonde(const RadiosondeSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
Expand Down Expand Up @@ -104,8 +107,8 @@ class Radiosonde : public Feature

void start();
void stop();
void applySettings(const RadiosondeSettings& settings, bool force = false);
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const RadiosondeSettings& settings, bool force);
void applySettings(const RadiosondeSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const RadiosondeSettings& settings, bool force);
void scanAvailableChannels();

private slots:
Expand Down
25 changes: 23 additions & 2 deletions plugins/feature/radiosonde/radiosondegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ bool RadiosondeGUI::handleMessage(const Message& message)
{
qDebug("RadiosondeGUI::handleMessage: Radiosonde::MsgConfigureRadiosonde");
const Radiosonde::MsgConfigureRadiosonde& cfg = (Radiosonde::MsgConfigureRadiosonde&) 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);
Expand Down Expand Up @@ -198,6 +204,7 @@ void RadiosondeGUI::setWorkspaceIndex(int index)
{
m_settings.m_workspaceIndex = index;
m_feature->setWorkspaceIndex(index);
m_settingsKeys.append("workspaceIndex");
}

void RadiosondeGUI::blockApplySettings(bool block)
Expand Down Expand Up @@ -259,6 +266,14 @@ void RadiosondeGUI::onMenuDialogCalled(const QPoint &p)
setTitle(m_settings.m_title);
setTitleColor(m_settings.m_rgbColor);

m_settingsKeys.append("title");
m_settingsKeys.append("rgbColor");
m_settingsKeys.append("useReverseAPI");
m_settingsKeys.append("reverseAPIAddress");
m_settingsKeys.append("reverseAPIPort");
m_settingsKeys.append("reverseAPIFeatureSetIndex");
m_settingsKeys.append("reverseAPIFeatureIndex");

applySettings();
}

Expand All @@ -269,9 +284,11 @@ void RadiosondeGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
Radiosonde::MsgConfigureRadiosonde* message = Radiosonde::MsgConfigureRadiosonde::create(m_settings, force);
Radiosonde::MsgConfigureRadiosonde* message = Radiosonde::MsgConfigureRadiosonde::create(m_settings, m_settingsKeys, force);
m_radiosonde->getInputMessageQueue()->push(message);
}

m_settingsKeys.clear();
}

void RadiosondeGUI::resizeTable()
Expand Down Expand Up @@ -307,6 +324,7 @@ void RadiosondeGUI::radiosondes_sectionMoved(int logicalIndex, int oldVisualInde
(void) oldVisualIndex;

m_settings.m_radiosondesColumnIndexes[logicalIndex] = newVisualIndex;
m_settingsKeys.append("radiosondesColumnIndexes");
}

// Column in table resized (when hidden size is 0)
Expand All @@ -315,6 +333,7 @@ void RadiosondeGUI::radiosondes_sectionResized(int logicalIndex, int oldSize, in
(void) oldSize;

m_settings.m_radiosondesColumnSizes[logicalIndex] = newSize;
m_settingsKeys.append("radiosondesColumnSizes");
}

// Right click in table header - show column select menu
Expand Down Expand Up @@ -682,13 +701,15 @@ void RadiosondeGUI::radiosondes_customContextMenuRequested(QPoint pos)
void RadiosondeGUI::on_y1_currentIndexChanged(int index)
{
m_settings.m_y1 = (RadiosondeSettings::ChartData)index;
m_settingsKeys.append("y1");
applySettings();
plotChart();
}

void RadiosondeGUI::on_y2_currentIndexChanged(int index)
{
m_settings.m_y2 = (RadiosondeSettings::ChartData)index;
m_settingsKeys.append("y2");
applySettings();
plotChart();
}
Expand Down
1 change: 1 addition & 0 deletions plugins/feature/radiosonde/radiosondegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class RadiosondeGUI : public FeatureGUI {
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
RadiosondeSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
bool m_doApplySettings;

Expand Down
104 changes: 104 additions & 0 deletions plugins/feature/radiosonde/radiosondesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,107 @@ bool RadiosondeSettings::deserialize(const QByteArray& data)
return false;
}
}

void RadiosondeSettings::applySettings(const QStringList& settingsKeys, const RadiosondeSettings& settings)
{
if (settingsKeys.contains("title")) {
m_title = settings.m_title;
}
if (settingsKeys.contains("rgbColor")) {
m_rgbColor = settings.m_rgbColor;
}
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("reverseAPIFeatureSetIndex")) {
m_reverseAPIFeatureSetIndex = settings.m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex")) {
m_reverseAPIFeatureIndex = settings.m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("y1")) {
m_y1 = settings.m_y1;
}
if (settingsKeys.contains("y2")) {
m_y2 = settings.m_y2;
}
if (settingsKeys.contains("workspaceIndex")) {
m_workspaceIndex = settings.m_workspaceIndex;
}

if (settingsKeys.contains("radiosondesColumnIndexes"))
{
for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
m_radiosondesColumnIndexes[i] = settings.m_radiosondesColumnIndexes[i];
}
}

if (settingsKeys.contains("radiosondesColumnSizes"))
{
for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
m_radiosondesColumnSizes[i] = settings.m_radiosondesColumnSizes[i];
}
}
}

QString RadiosondeSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;

if (settingsKeys.contains("title") || force) {
ostr << " m_title: " << m_title.toStdString();
}
if (settingsKeys.contains("rgbColor") || force) {
ostr << " m_rgbColor: " << m_rgbColor;
}
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("reverseAPIFeatureSetIndex") || force) {
ostr << " m_reverseAPIFeatureSetIndex: " << m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex") || force) {
ostr << " m_reverseAPIFeatureIndex: " << m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("y1") || force) {
ostr << " m_y1: " << m_y1;
}
if (settingsKeys.contains("y2") || force) {
ostr << " m_y2: " << m_y2;
}
if (settingsKeys.contains("workspaceIndex") || force) {
ostr << " m_workspaceIndex: " << m_workspaceIndex;
}

if (settingsKeys.contains("radiosondesColumnIndexes"))
{
ostr << "m_radiosondesColumnIndexes:";

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
ostr << " " << m_radiosondesColumnIndexes[i];
}
}

if (settingsKeys.contains("radiosondesColumnSizes"))
{
ostr << "m_radiosondesColumnSizes:";

for (int i = 0; i < RADIOSONDES_COLUMNS; i++) {
ostr << " " << m_radiosondesColumnSizes[i];
}
}

return QString(ostr.str().c_str());
}
2 changes: 2 additions & 0 deletions plugins/feature/radiosonde/radiosondesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct RadiosondeSettings
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; }
void applySettings(const QStringList& settingsKeys, const RadiosondeSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;

static const QStringList m_pipeTypes;
static const QStringList m_pipeURIs;
Expand Down
Loading

0 comments on commit ecdc464

Please sign in to comment.