Skip to content

Commit

Permalink
AIS 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 20, 2022
1 parent f3c5cd0 commit 1972b74
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 45 deletions.
6 changes: 2 additions & 4 deletions plugins/feature/afc/afc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ void AFC::applySettings(const AFCSettings& settings, const QList<QString>& setti
{
qDebug() << "AFC::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;

QList<QString> reverseAPIKeys;

if (settingsKeys.contains("trackerDeviceSetIndex") || force)
{
removeTrackerFeatureReference();
Expand Down Expand Up @@ -272,14 +270,14 @@ void AFC::applySettings(const AFCSettings& settings, const QList<QString>& setti
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
settingsKeys.contains("m_reverseAPIFeatureIndex");
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}

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

void AFC::updateDeviceSetLists()
Expand Down
2 changes: 2 additions & 0 deletions plugins/feature/afc/afcgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ void AFCGUI::applySettings(bool force)
AFC::MsgConfigureAFC* message = AFC::MsgConfigureAFC::create( m_settings, m_settingsKeys, force);
m_afc->getInputMessageQueue()->push(message);
}

m_settingsKeys.clear();
}

void AFCGUI::makeUIConnections()
Expand Down
89 changes: 57 additions & 32 deletions plugins/feature/ais/ais.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool AIS::handleMessage(const Message& cmd)
{
MsgConfigureAIS& cfg = (MsgConfigureAIS&) cmd;
qDebug() << "AIS::handleMessage: MsgConfigureAIS";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());

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

void AIS::applySettings(const AISSettings& settings, bool force)
void AIS::applySettings(const AISSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "AIS::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;

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");
}
qDebug() << "AIS::applySettings:" << settings.getDebugString(settingsKeys, force) << force;

if (settings.m_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 AIS::webapiSettingsGet(
Expand All @@ -195,12 +182,12 @@ int AIS::webapiSettingsPutPatch(
AISSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);

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

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

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

if (!response.getAisSettings()->getVesselColumnIndexes()) {
response.getAisSettings()->setVesselColumnIndexes(new QList<int>());
}

response.getAisSettings()->getVesselColumnIndexes()->clear();

for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
response.getAisSettings()->getVesselColumnIndexes()->push_back(settings.m_vesselColumnIndexes[i]);
}

if (!response.getAisSettings()->getVesselColumnSizes()) {
response.getAisSettings()->setVesselColumnSizes(new QList<int>());
}

response.getAisSettings()->getVesselColumnSizes()->clear();

for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
response.getAisSettings()->getVesselColumnSizes()->push_back(settings.m_vesselColumnSizes[i]);
}
}

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

if (featureSettingsKeys.contains("vesselColumnIndexes"))
{
const QList<int> *indexes = response.getAisSettings()->getVesselColumnIndexes();

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

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

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

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

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

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

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

MsgConfigureAIS(const AISSettings& settings, bool force) :
MsgConfigureAIS(const AISSettings& 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 AIS : public Feature

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

private slots:
Expand Down
24 changes: 22 additions & 2 deletions plugins/feature/ais/aisgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ bool AISGUI::handleMessage(const Message& message)
{
qDebug("AISGUI::handleMessage: AIS::MsgConfigureAIS");
const AIS::MsgConfigureAIS& cfg = (AIS::MsgConfigureAIS&) 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 @@ -258,9 +264,11 @@ void AISGUI::displaySettings()
bool hidden = m_settings.m_vesselColumnSizes[i] == 0;
header->setSectionHidden(i, hidden);
vesselsMenu->actions().at(i)->setChecked(!hidden);

if (m_settings.m_vesselColumnSizes[i] > 0) {
ui->vessels->setColumnWidth(i, m_settings.m_vesselColumnSizes[i]);
}

header->moveSection(header->visualIndex(i), m_settings.m_vesselColumnIndexes[i]);
}

Expand Down Expand Up @@ -295,6 +303,12 @@ void AISGUI::onMenuDialogCalled(const QPoint &p)
setTitle(m_settings.m_title);
setTitleColor(m_settings.m_rgbColor);

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

applySettings();
}

Expand Down Expand Up @@ -333,9 +347,11 @@ void AISGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
AIS::MsgConfigureAIS* message = AIS::MsgConfigureAIS::create(m_settings, force);
AIS::MsgConfigureAIS* message = AIS::MsgConfigureAIS::create(m_settings, m_settingsKeys, force);
m_ais->getInputMessageQueue()->push(message);
}

m_settingsKeys.clear();
}

void AISGUI::resizeTable()
Expand Down Expand Up @@ -370,6 +386,8 @@ void AISGUI::vessels_sectionMoved(int logicalIndex, int oldVisualIndex, int newV
(void) oldVisualIndex;

m_settings.m_vesselColumnIndexes[logicalIndex] = newVisualIndex;
m_settingsKeys.append("vesselColumnIndexes");
applySettings();
}

// Column in table resized (when hidden size is 0)
Expand All @@ -378,6 +396,8 @@ void AISGUI::vessels_sectionResized(int logicalIndex, int oldSize, int newSize)
(void) oldSize;

m_settings.m_vesselColumnSizes[logicalIndex] = newSize;
m_settingsKeys.append("vesselColumnSizes");
applySettings();
}

// Right click in table header - show column select menu
Expand Down
1 change: 1 addition & 0 deletions plugins/feature/ais/aisgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AISGUI : public FeatureGUI {
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
AISSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
bool m_doApplySettings;

Expand Down
93 changes: 93 additions & 0 deletions plugins/feature/ais/aissettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,96 @@ bool AISSettings::deserialize(const QByteArray& data)
return false;
}
}

void AISSettings::applySettings(const QStringList& settingsKeys, const AISSettings& 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("workspaceIndex")) {
m_workspaceIndex = settings.m_workspaceIndex;
}

if (settingsKeys.contains("vesselColumnIndexes"))
{
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
m_vesselColumnIndexes[i] = settings.m_vesselColumnIndexes[i];
}
}

if (settingsKeys.contains("vesselColumnSizes"))
{
for (int i = 0; i < AIS_VESSEL_COLUMNS; i++) {
m_vesselColumnSizes[i] = settings.m_vesselColumnSizes[i];
}
}
}

QString AISSettings::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("workspaceIndex") || force) {
ostr << " m_workspaceIndex: " << m_workspaceIndex;
}

if (settingsKeys.contains("vesselColumnIndexes"))
{
ostr << "m_vesselColumnIndexes:";

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


if (settingsKeys.contains("vesselColumnSizes"))
{
ostr << "m_vesselColumnSizes:";

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

return QString(ostr.str().c_str());
}
Loading

0 comments on commit 1972b74

Please sign in to comment.