1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

RigCrl Server feature: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-11-27 13:36:48 +01:00
parent ecdc464869
commit 541b8449fd
8 changed files with 163 additions and 82 deletions

View File

@ -82,7 +82,8 @@ void RigCtlServer::start()
m_state = ok ? StRunning : StError;
m_thread.start();
RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::create(m_settings, true);
RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::create(
m_settings, QList<QString>(), true);
m_worker->getInputMessageQueue()->push(msg);
}
@ -101,7 +102,7 @@ bool RigCtlServer::handleMessage(const Message& cmd)
{
MsgConfigureRigCtlServer& cfg = (MsgConfigureRigCtlServer&) cmd;
qDebug() << "RigCtlServer::handleMessage: MsgConfigureRigCtlServer";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
return true;
}
@ -125,7 +126,7 @@ bool RigCtlServer::handleMessage(const Message& cmd)
qDebug() << "RigCtlServer::handleMessage: MsgChannelIndexChange: " << newChannelIndex;
RigCtlServerSettings settings = m_settings;
settings.m_channelIndex = newChannelIndex;
applySettings(settings, false);
applySettings(settings, QList<QString>{"channelIndex"}, false);
if (getMessageQueueToGUI())
{
@ -150,76 +151,43 @@ bool RigCtlServer::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, true);
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, true);
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return false;
}
}
void RigCtlServer::applySettings(const RigCtlServerSettings& settings, bool force)
void RigCtlServer::applySettings(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "RigCtlServer::applySettings:"
<< " m_enabled: " << settings.m_enabled
<< " m_deviceIndex: " << settings.m_deviceIndex
<< " m_channelIndex: " << settings.m_channelIndex
<< " m_rigCtlPort: " << settings.m_rigCtlPort
<< " m_maxFrequencyOffset: " << settings.m_maxFrequencyOffset
<< " 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_enabled != settings.m_enabled) || force) {
reverseAPIKeys.append("enabled");
}
if ((m_settings.m_deviceIndex != settings.m_deviceIndex) || force) {
reverseAPIKeys.append("deviceIndex");
}
if ((m_settings.m_channelIndex != settings.m_channelIndex) || force) {
reverseAPIKeys.append("channelIndex");
}
if ((m_settings.m_rigCtlPort != settings.m_rigCtlPort) || force) {
reverseAPIKeys.append("rigCtlPort");
}
if ((m_settings.m_maxFrequencyOffset != settings.m_maxFrequencyOffset) || force) {
reverseAPIKeys.append("maxFrequencyOffset");
}
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() << "RigCtlServer::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
RigCtlServerWorker::MsgConfigureRigCtlServerWorker *msg = RigCtlServerWorker::MsgConfigureRigCtlServerWorker::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 RigCtlServer::webapiRun(bool run,
@ -254,13 +222,13 @@ int RigCtlServer::webapiSettingsPutPatch(
RigCtlServerSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(settings, force);
MsgConfigureRigCtlServer *msg = MsgConfigureRigCtlServer::create(settings, featureSettingsKeys, force);
m_inputMessageQueue.push(msg);
qDebug("RigCtlServer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRigCtlServer *msgToGUI = MsgConfigureRigCtlServer::create(settings, force);
MsgConfigureRigCtlServer *msgToGUI = MsgConfigureRigCtlServer::create(settings, featureSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -404,7 +372,7 @@ void RigCtlServer::webapiUpdateFeatureSettings(
}
}
void RigCtlServer::webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const RigCtlServerSettings& settings, bool force)
void RigCtlServer::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const RigCtlServerSettings& settings, bool force)
{
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());

View File

@ -45,19 +45,22 @@ public:
public:
const RigCtlServerSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureRigCtlServer* create(const RigCtlServerSettings& settings, bool force) {
return new MsgConfigureRigCtlServer(settings, force);
static MsgConfigureRigCtlServer* create(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureRigCtlServer(settings, settingsKeys, force);
}
private:
RigCtlServerSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureRigCtlServer(const RigCtlServerSettings& settings, bool force) :
MsgConfigureRigCtlServer(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -138,8 +141,8 @@ private:
void start();
void stop();
void applySettings(const RigCtlServerSettings& settings, bool force = false);
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const RigCtlServerSettings& settings, bool force);
void applySettings(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const RigCtlServerSettings& settings, bool force);
void webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response);
private slots:

View File

@ -73,7 +73,13 @@ bool RigCtlServerGUI::handleMessage(const Message& message)
{
qDebug("RigCtlServerGUI::handleMessage: RigCtlServer::MsgConfigureRigCtlServer");
const RigCtlServer::MsgConfigureRigCtlServer& cfg = (RigCtlServer::MsgConfigureRigCtlServer&) 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);
@ -114,7 +120,6 @@ void RigCtlServerGUI::onWidgetRolled(QWidget* widget, bool rollDown)
(void) rollDown;
getRollupContents()->saveState(m_rollupState);
applySettings();
}
RigCtlServerGUI::RigCtlServerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) :
@ -158,6 +163,7 @@ RigCtlServerGUI::~RigCtlServerGUI()
void RigCtlServerGUI::setWorkspaceIndex(int index)
{
m_settings.m_workspaceIndex = index;
m_settingsKeys.append("workspaceIndex");
m_feature->setWorkspaceIndex(index);
}
@ -220,6 +226,7 @@ void RigCtlServerGUI::updateDeviceSetList()
{
qDebug("RigCtlServerGUI::updateDeviceSetLists: device index changed: %d", newDeviceIndex);
m_settings.m_deviceIndex = newDeviceIndex;
m_settingsKeys.append("deviceIndex");
}
updateChannelList();
@ -270,6 +277,7 @@ bool RigCtlServerGUI::updateChannelList()
{
qDebug("RigCtlServerGUI::updateChannelList: channel index changed: %d", newChannelIndex);
m_settings.m_channelIndex = newChannelIndex;
m_settingsKeys.append("channelIndex");
return true;
}
@ -302,6 +310,14 @@ void RigCtlServerGUI::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();
}
@ -320,6 +336,7 @@ void RigCtlServerGUI::on_startStop_toggled(bool checked)
void RigCtlServerGUI::on_enable_toggled(bool checked)
{
m_settings.m_enabled = checked;
m_settingsKeys.append("enabled");
applySettings();
}
@ -335,6 +352,7 @@ void RigCtlServerGUI::on_device_currentIndexChanged(int index)
if (index >= 0)
{
m_settings.m_deviceIndex = ui->device->currentData().toInt();
m_settingsKeys.append("deviceIndex");
updateChannelList();
applySettings();
}
@ -345,6 +363,7 @@ void RigCtlServerGUI::on_channel_currentIndexChanged(int index)
if (index >= 0)
{
m_settings.m_channelIndex = index;
m_settingsKeys.append("channelIndex");
applySettings();
}
}
@ -352,12 +371,14 @@ void RigCtlServerGUI::on_channel_currentIndexChanged(int index)
void RigCtlServerGUI::on_rigCtrlPort_valueChanged(int value)
{
m_settings.m_rigCtlPort = value;
m_settingsKeys.append("rigCtlPort");
applySettings();
}
void RigCtlServerGUI::on_maxFrequencyOffset_valueChanged(int value)
{
m_settings.m_maxFrequencyOffset = value;
m_settingsKeys.append("maxFrequencyOffset");
applySettings();
}
@ -394,9 +415,11 @@ void RigCtlServerGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
RigCtlServer::MsgConfigureRigCtlServer* message = RigCtlServer::MsgConfigureRigCtlServer::create( m_settings, force);
RigCtlServer::MsgConfigureRigCtlServer* message = RigCtlServer::MsgConfigureRigCtlServer::create(m_settings, m_settingsKeys, force);
m_rigCtlServer->getInputMessageQueue()->push(message);
}
m_settingsKeys.clear();
}
void RigCtlServerGUI::makeUIConnections()

View File

@ -55,6 +55,7 @@ private:
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
RigCtlServerSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
bool m_doApplySettings;

View File

@ -134,3 +134,88 @@ bool RigCtlServerSettings::deserialize(const QByteArray& data)
return false;
}
}
void RigCtlServerSettings::applySettings(const QStringList& settingsKeys, const RigCtlServerSettings& settings)
{
if (settingsKeys.contains("rigCtlPort")) {
m_rigCtlPort = settings.m_rigCtlPort;
}
if (settingsKeys.contains("maxFrequencyOffset")) {
m_maxFrequencyOffset = settings.m_maxFrequencyOffset;
}
if (settingsKeys.contains("deviceIndex")) {
m_deviceIndex = settings.m_deviceIndex;
}
if (settingsKeys.contains("channelIndex")) {
m_channelIndex = settings.m_channelIndex;
}
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;
}
}
QString RigCtlServerSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("rigCtlPort") || force) {
ostr << " m_rigCtlPort: " << m_rigCtlPort;
}
if (settingsKeys.contains("maxFrequencyOffset") || force) {
ostr << " m_maxFrequencyOffset: " << m_maxFrequencyOffset;
}
if (settingsKeys.contains("deviceIndex") || force) {
ostr << " m_deviceIndex: " << m_deviceIndex;
}
if (settingsKeys.contains("channelIndex") || force) {
ostr << " m_channelIndex: " << m_channelIndex;
}
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;
}
return QString(ostr.str().c_str());
}

View File

@ -68,6 +68,8 @@ struct RigCtlServerSettings
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; }
void applySettings(const QStringList& settingsKeys, const RigCtlServerSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
};
#endif // INCLUDE_FEATURE_RIGCTLSERVERSETTINGS_H_

View File

@ -107,7 +107,7 @@ bool RigCtlServerWorker::handleMessage(const Message& cmd)
MsgConfigureRigCtlServerWorker& cfg = (MsgConfigureRigCtlServerWorker&) cmd;
qDebug() << "RigCtlServerWorker::handleMessage: MsgConfigureRigCtlServerWorker";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
return true;
}
@ -117,25 +117,21 @@ bool RigCtlServerWorker::handleMessage(const Message& cmd)
}
}
void RigCtlServerWorker::applySettings(const RigCtlServerSettings& settings, bool force)
void RigCtlServerWorker::applySettings(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "RigCtlServerWorker::applySettings:"
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_enabled: " << settings.m_enabled
<< " m_deviceIndex: " << settings.m_deviceIndex
<< " m_channelIndex: " << settings.m_channelIndex
<< " m_rigCtlPort: " << settings.m_rigCtlPort
<< " m_maxFrequencyOffset: " << settings.m_maxFrequencyOffset
<< " force: " << force;
qDebug() << "RigCtlServerWorker::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
if ((settings.m_rigCtlPort != m_settings.m_rigCtlPort) ||
(settings.m_enabled != m_settings.m_enabled) || force)
if (settingsKeys.contains("rigCtlPort") ||
settingsKeys.contains("enabled") || force)
{
restartServer(settings.m_enabled, settings.m_rigCtlPort);
}
m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}
void RigCtlServerWorker::restartServer(bool enabled, uint32_t port)

View File

@ -39,20 +39,23 @@ public:
public:
const RigCtlServerSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureRigCtlServerWorker* create(const RigCtlServerSettings& settings, bool force)
static MsgConfigureRigCtlServerWorker* create(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
return new MsgConfigureRigCtlServerWorker(settings, force);
return new MsgConfigureRigCtlServerWorker(settings, settingsKeys, force);
}
private:
RigCtlServerSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureRigCtlServerWorker(const RigCtlServerSettings& settings, bool force) :
MsgConfigureRigCtlServerWorker(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -125,7 +128,7 @@ private:
static const ModeDemod m_modeMap[];
bool handleMessage(const Message& cmd);
void applySettings(const RigCtlServerSettings& settings, bool force = false);
void applySettings(const RigCtlServerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void restartServer(bool enabled, uint32_t port);
bool setFrequency(double frequency, rig_errcode_e& rigCtlRC);
bool getFrequency(double& frequency, rig_errcode_e& rigCtlRC);