Skip to content

Commit

Permalink
Simple PTT 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 28, 2022
1 parent b3e6ea9 commit 7906ece
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 95 deletions.
85 changes: 22 additions & 63 deletions plugins/feature/simpleptt/simpleptt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void SimplePTT::start()
m_state = StRunning;
m_thread->start();

SimplePTTWorker::MsgConfigureSimplePTTWorker *msg = SimplePTTWorker::MsgConfigureSimplePTTWorker::create(m_settings, true);
SimplePTTWorker::MsgConfigureSimplePTTWorker *msg = SimplePTTWorker::MsgConfigureSimplePTTWorker::create(m_settings, QList<QString>(), true);
m_worker->getInputMessageQueue()->push(msg);

m_running = true;
Expand Down Expand Up @@ -135,7 +135,7 @@ bool SimplePTT::handleMessage(const Message& cmd)
{
MsgConfigureSimplePTT& cfg = (MsgConfigureSimplePTT&) cmd;
qDebug() << "SimplePTT::handleMessage: MsgConfigureSimplePTT";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());

return true;
}
Expand Down Expand Up @@ -181,14 +181,14 @@ bool SimplePTT::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureSimplePTT *msg = MsgConfigureSimplePTT::create(m_settings, true);
MsgConfigureSimplePTT *msg = MsgConfigureSimplePTT::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureSimplePTT *msg = MsgConfigureSimplePTT::create(m_settings, true);
MsgConfigureSimplePTT *msg = MsgConfigureSimplePTT::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return false;
}
Expand All @@ -201,74 +201,33 @@ void SimplePTT::getAudioPeak(float& peak)
}
}

void SimplePTT::applySettings(const SimplePTTSettings& settings, bool force)
void SimplePTT::applySettings(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "SimplePTT::applySettings:"
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_rxDeviceSetIndex: " << settings.m_rxDeviceSetIndex
<< " m_txDeviceSetIndex: " << settings.m_txDeviceSetIndex
<< " m_rx2TxDelayMs: " << settings.m_rx2TxDelayMs
<< " m_tx2RxDelayMs: " << settings.m_tx2RxDelayMs
<< " m_vox: " << settings.m_vox
<< " m_voxEnable: " << settings.m_voxEnable
<< " m_audioDeviceName: " << settings.m_audioDeviceName
<< " m_voxLevel: " << settings.m_voxLevel
<< " m_voxHold: " << settings.m_voxHold
<< " 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 ((m_settings.m_rxDeviceSetIndex != settings.m_rxDeviceSetIndex) || force) {
reverseAPIKeys.append("rxDeviceSetIndex");
}
if ((m_settings.m_txDeviceSetIndex != settings.m_txDeviceSetIndex) || force) {
reverseAPIKeys.append("txDeviceSetIndex");
}
if ((m_settings.m_rx2TxDelayMs != settings.m_rx2TxDelayMs) || force) {
reverseAPIKeys.append("rx2TxDelayMs");
}
if ((m_settings.m_tx2RxDelayMs != settings.m_tx2RxDelayMs) || force) {
reverseAPIKeys.append("tx2RxDelayMs");
}
if ((m_settings.m_vox != settings.m_vox) || force) {
reverseAPIKeys.append("vox");
}
if ((m_settings.m_voxEnable != settings.m_voxEnable) || force) {
reverseAPIKeys.append("voxEnable");
}
if ((m_settings.m_voxHold != settings.m_voxHold) || force) {
reverseAPIKeys.append("voxHold");
}
if ((m_settings.m_voxLevel != settings.m_voxLevel) || force) {
reverseAPIKeys.append("voxLevel");
}
qDebug() << "SimplePTT::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;

if (m_running)
{
SimplePTTWorker::MsgConfigureSimplePTTWorker *msg = SimplePTTWorker::MsgConfigureSimplePTTWorker::create(
settings, force
settings, settingsKeys, force
);
m_worker->getInputMessageQueue()->push(msg);
}

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 SimplePTT::webapiRun(bool run,
Expand Down Expand Up @@ -303,13 +262,13 @@ int SimplePTT::webapiSettingsPutPatch(
SimplePTTSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);

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

qDebug("SimplePTT::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureSimplePTT *msgToGUI = MsgConfigureSimplePTT::create(settings, force);
MsgConfigureSimplePTT *msgToGUI = MsgConfigureSimplePTT::create(settings, featureSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}

Expand Down Expand Up @@ -488,7 +447,7 @@ void SimplePTT::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& respons
response.getSimplePttReport()->setRunningState(getState());
}

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

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

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

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

MsgConfigureSimplePTT(const SimplePTTSettings& settings, bool force) :
MsgConfigureSimplePTT(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
Expand Down Expand Up @@ -162,9 +165,9 @@ class SimplePTT : public Feature

void start();
void stop();
void applySettings(const SimplePTTSettings& settings, bool force = false);
void applySettings(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response);
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const SimplePTTSettings& settings, bool force);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const SimplePTTSettings& settings, bool force);

private slots:
void networkManagerFinished(QNetworkReply *reply);
Expand Down
32 changes: 30 additions & 2 deletions plugins/feature/simpleptt/simplepttgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ bool SimplePTTGUI::handleMessage(const Message& message)
{
qDebug("SimplePTTGUI::handleMessage: SimplePTT::MsgConfigureSimplePTT");
const SimplePTT::MsgConfigureSimplePTT& cfg = (SimplePTT::MsgConfigureSimplePTT&) 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 @@ -194,6 +200,7 @@ SimplePTTGUI::~SimplePTTGUI()
void SimplePTTGUI::setWorkspaceIndex(int index)
{
m_settings.m_workspaceIndex = index;
m_settingsKeys.append("workspaceIndex");
m_feature->setWorkspaceIndex(index);
}

Expand Down Expand Up @@ -291,6 +298,8 @@ void SimplePTTGUI::updateDeviceSetLists()
qDebug("SimplePTTGUI::updateDeviceSetLists: device index changed: %d:%d", rxDeviceIndex, txDeviceIndex);
m_settings.m_rxDeviceSetIndex = rxDeviceIndex;
m_settings.m_txDeviceSetIndex = txDeviceIndex;
m_settingsKeys.append("rxDeviceSetIndex");
m_settingsKeys.append("txDeviceSetIndex");
applySettings();
}

Expand Down Expand Up @@ -324,6 +333,14 @@ void SimplePTTGUI::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 Down Expand Up @@ -357,6 +374,7 @@ void SimplePTTGUI::on_rxDevice_currentIndexChanged(int index)
if (index >= 0)
{
m_settings.m_rxDeviceSetIndex = index;
m_settingsKeys.append("rxDeviceSetIndex");
applySettings();
}
}
Expand All @@ -366,6 +384,7 @@ void SimplePTTGUI::on_txDevice_currentIndexChanged(int index)
if (index >= 0)
{
m_settings.m_txDeviceSetIndex = index;
m_settingsKeys.append("txDeviceSetIndex");
applySettings();
}

Expand All @@ -374,12 +393,14 @@ void SimplePTTGUI::on_txDevice_currentIndexChanged(int index)
void SimplePTTGUI::on_rxtxDelay_valueChanged(int value)
{
m_settings.m_rx2TxDelayMs = value;
m_settingsKeys.append("rx2TxDelayMs");
applySettings();
}

void SimplePTTGUI::on_txrxDelay_valueChanged(int value)
{
m_settings.m_tx2RxDelayMs = value;
m_settingsKeys.append("tx2RxDelayMs");
applySettings();
}

Expand All @@ -391,25 +412,29 @@ void SimplePTTGUI::on_ptt_toggled(bool checked)
void SimplePTTGUI::on_vox_toggled(bool checked)
{
m_settings.m_vox = checked;
m_settingsKeys.append("vox");
applySettings();
}

void SimplePTTGUI::on_voxEnable_clicked(bool checked)
{
m_settings.m_voxEnable = checked;
m_settingsKeys.append("voxEnable");
applySettings();
}

void SimplePTTGUI::on_voxLevel_valueChanged(int value)
{
m_settings.m_voxLevel = value;
ui->voxLevelText->setText(tr("%1").arg(m_settings.m_voxLevel));
m_settingsKeys.append("voxLevel");
applySettings();
}

void SimplePTTGUI::on_voxHold_valueChanged(int value)
{
m_settings.m_voxHold = value;
m_settingsKeys.append("voxHold");
applySettings();
}

Expand Down Expand Up @@ -454,9 +479,11 @@ void SimplePTTGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
SimplePTT::MsgConfigureSimplePTT* message = SimplePTT::MsgConfigureSimplePTT::create( m_settings, force);
SimplePTT::MsgConfigureSimplePTT* message = SimplePTT::MsgConfigureSimplePTT::create( m_settings, m_settingsKeys, force);
m_simplePTT->getInputMessageQueue()->push(message);
}

m_settingsKeys.clear();
}

void SimplePTTGUI::applyPTT(bool tx)
Expand All @@ -478,6 +505,7 @@ void SimplePTTGUI::audioSelect()
if (audioSelect.m_selected)
{
m_settings.m_audioDeviceName = audioSelect.m_audioDeviceName;
m_settingsKeys.append("audioDeviceName");
applySettings();
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/feature/simpleptt/simplepttgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SimplePTTGUI : public FeatureGUI {
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
SimplePTTSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
bool m_doApplySettings;

Expand Down
Loading

0 comments on commit 7906ece

Please sign in to comment.