make settings manager methods used for backup/restore thread safe

This commit is contained in:
Stephen Birarda 2018-02-15 15:51:49 -08:00
parent f5cad5683d
commit e06c95f586
2 changed files with 28 additions and 2 deletions

View file

@ -19,6 +19,7 @@
#include <QtCore/QJsonArray>
#include <QtCore/QJsonObject>
#include <QtCore/QStandardPaths>
#include <QtCore/QThread>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
@ -1196,6 +1197,16 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
}
bool DomainServerSettingsManager::restoreSettingsFromObject(QJsonObject settingsToRestore, SettingsType settingsType) {
if (thread() != QThread::currentThread()) {
bool success;
QMetaObject::invokeMethod(this, "restoreSettingsFromObject", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, success),
Q_ARG(QJsonObject, settingsToRestore),
Q_ARG(SettingsType, settingsType));
return success;
}
QJsonArray& filteredDescriptionArray = settingsType == DomainSettings
? _domainSettingsDescription : _contentSettingsDescription;
@ -1321,6 +1332,19 @@ QJsonObject DomainServerSettingsManager::settingsResponseObjectForType(const QSt
bool includeDefaults, bool isForBackup) {
QJsonObject responseObject;
if (thread() != QThread::currentThread()) {
QMetaObject::invokeMethod(this, "settingsResponseObjectForType", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QJsonObject, responseObject),
Q_ARG(const QString&, typeValue),
Q_ARG(bool, isAuthenticated),
Q_ARG(bool, includeDomainSettings),
Q_ARG(bool, includeContentSettings),
Q_ARG(bool, includeDefaults),
Q_ARG(bool, isForBackup));
return responseObject;
}
if (!typeValue.isEmpty() || isAuthenticated) {
// convert the string type value to a QJsonValue
QJsonValue queryType = typeValue.isEmpty() ? QJsonValue() : QJsonValue(typeValue.toInt());

View file

@ -111,10 +111,12 @@ public:
void debugDumpGroupsState();
QJsonObject settingsResponseObjectForType(const QString& typeValue, bool isAuthenticated = false,
/// thread safe method to retrieve a JSON representation of settings
Q_INVOKABLE QJsonObject settingsResponseObjectForType(const QString& typeValue, bool isAuthenticated = false,
bool includeDomainSettings = true, bool includeContentSettings = true,
bool includeDefaults = true, bool isForBackup = false);
bool restoreSettingsFromObject(QJsonObject settingsToRestore, SettingsType settingsType);
/// thread safe method to restore settings from a JSON object
Q_INVOKABLE bool restoreSettingsFromObject(QJsonObject settingsToRestore, SettingsType settingsType);
signals:
void updateNodePermissions();