3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-27 05:15:34 +02:00

add ability for domain-server to restart after setting save

This commit is contained in:
Stephen Birarda 2014-09-26 11:26:21 -07:00
parent e6449da890
commit 3c71d4d96e
5 changed files with 29 additions and 5 deletions

View file

@ -30,6 +30,8 @@
#include "DomainServer.h"
int const DomainServer::EXIT_CODE_REBOOT = 234923;
DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv),
_shutdownEventListener(this),
@ -56,7 +58,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
QSettings::setDefaultFormat(QSettings::IniFormat);
_settingsManager.loadSettingsMap(arguments());
installNativeEventFilter(&_shutdownEventListener);
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
@ -77,6 +79,11 @@ DomainServer::DomainServer(int argc, char* argv[]) :
}
}
void DomainServer::restart() {
qDebug() << "domain-server is restarting.";
exit(DomainServer::EXIT_CODE_REBOOT);
}
bool DomainServer::optionallyReadX509KeyAndCertificate() {
const QString X509_CERTIFICATE_OPTION = "cert";
const QString X509_PRIVATE_KEY_OPTION = "key";

View file

@ -35,16 +35,17 @@
typedef QSharedPointer<Assignment> SharedAssignmentPointer;
typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
class DomainServer : public QCoreApplication, public HTTPSRequestHandler {
Q_OBJECT
public:
DomainServer(int argc, char* argv[]);
static int const EXIT_CODE_REBOOT;
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url);
void exit(int retCode = 0);
public slots:
/// Called by NodeList to inform us a node has been added
void nodeAdded(SharedNodePointer node);
@ -53,6 +54,8 @@ public slots:
void transactionJSONCallback(const QJsonObject& data);
void restart();
private slots:
void loginFailed();
void readAvailableDatagrams();

View file

@ -146,6 +146,10 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
QString jsonSuccess = "{\"status\": \"success\"}";
connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json");
// defer a restart to the domain-server, this gives our HTTPConnection enough time to respond
const int DOMAIN_SERVER_RESTART_TIMER_MSECS = 1000;
QTimer::singleShot(DOMAIN_SERVER_RESTART_TIMER_MSECS, qApp, SLOT(restart()));
return true;
}

View file

@ -28,6 +28,8 @@ public:
QByteArray getJSONSettingsMap() const;
const QVariantMap& getSettingsMap() const { return _settingsMap; }
signals:
void saveRequiresRestart();
private:
void recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant,
QJsonArray descriptionArray);

View file

@ -28,8 +28,16 @@ int main(int argc, char* argv[]) {
#endif
qInstallMessageHandler(Logging::verboseMessageHandler);
DomainServer domainServer(argc, argv);
return domainServer.exec();
int currentExitCode = 0;
// use a do-while to handle domain-server restart
do {
DomainServer domainServer(argc, argv);
currentExitCode = domainServer.exec();
} while (currentExitCode == DomainServer::EXIT_CODE_REBOOT);
return currentExitCode;
}