diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 4d2538eb25..71fbef4cf8 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -36,7 +36,8 @@ int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), - _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME) + _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), + _shutdownEventListener(this) { #ifdef Q_OS_WIN @@ -54,7 +55,8 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : setApplicationName("assignment-client"); QSettings::setDefaultFormat(QSettings::IniFormat); - installNativeEventFilter(this); + installNativeEventFilter(&_shutdownEventListener); + connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit())); // set the logging target to the the CHILD_TARGET_NAME Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME); @@ -121,20 +123,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : NetworkAccessManager::getInstance(); } -bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { -#ifdef Q_OS_WIN - if (eventType == "windows_generic_MSG") { - MSG* message = (MSG*)msg; - if (message->message == WM_CLOSE) { - qDebug() << "Received WM_CLOSE message, closing"; - quit(); - return false; - } - } -#endif - return true; -} - void AssignmentClient::sendAssignmentRequest() { if (!_currentAssignment) { NodeList::getInstance()->sendAssignment(_requestAssignment); diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 5c8d1945ee..24a4c97f73 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -15,14 +15,14 @@ #include #include +#include "ShutdownEventListener.h" #include "ThreadedAssignment.h" -class AssignmentClient : public QCoreApplication, public QAbstractNativeEventFilter { +class AssignmentClient : public QCoreApplication { Q_OBJECT public: AssignmentClient(int &argc, char **argv); static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; } - virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result); private slots: void sendAssignmentRequest(); @@ -33,6 +33,7 @@ private slots: private: Assignment _requestAssignment; static SharedAssignmentPointer _currentAssignment; + ShutdownEventListener _shutdownEventListener; QString _assignmentServerHostname; }; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index a4a50bbe2c..f96444d8fb 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -31,6 +31,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : QCoreApplication(argc, argv), + _shutdownEventListener(this), _httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), _httpsManager(NULL), _allAssignments(), @@ -62,7 +63,8 @@ DomainServer::DomainServer(int argc, char* argv[]) : setApplicationName("domain-server"); QSettings::setDefaultFormat(QSettings::IniFormat); - installNativeEventFilter(this); + installNativeEventFilter(&_shutdownEventListener); + connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit())); qRegisterMetaType("DomainServerWebSessionData"); qRegisterMetaTypeStreamOperators("DomainServerWebSessionData"); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 12a4970612..524f237c9d 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -27,6 +27,7 @@ #include "DomainServerSettingsManager.h" #include "DomainServerWebSessionData.h" +#include "ShutdownEventListener.h" #include "WalletTransaction.h" #include "PendingAssignedNodeData.h" @@ -100,6 +101,8 @@ private: QJsonObject jsonForSocket(const HifiSockAddr& socket); QJsonObject jsonObjectForNode(const SharedNodePointer& node); + + ShutdownEventListener _shutdownEventListener; HTTPManager _httpManager; HTTPSManager* _httpsManager; diff --git a/libraries/shared/src/ShutdownEventListener.cpp b/libraries/shared/src/ShutdownEventListener.cpp new file mode 100644 index 0000000000..e800c61110 --- /dev/null +++ b/libraries/shared/src/ShutdownEventListener.cpp @@ -0,0 +1,27 @@ +// +// ShutdownEventListener.cpp +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ShutdownEventListener.h" + +ShutdownEventListener::ShutdownEventListener(QObject* parent) : QObject(parent) { +} + +bool ShutdownEventListener::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { +#ifdef Q_OS_WIN + if (eventType == "windows_generic_MSG") { + MSG* message = (MSG*)msg; + if (message->message == WM_CLOSE) { + emit receivedCloseEvent(); + } + } +#endif + return true; +} diff --git a/libraries/shared/src/ShutdownEventListener.h b/libraries/shared/src/ShutdownEventListener.h new file mode 100644 index 0000000000..e39770c13d --- /dev/null +++ b/libraries/shared/src/ShutdownEventListener.h @@ -0,0 +1,29 @@ +// +// ShutdownEventListener.h +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ShutdownEventListener_h +#define hifi_ShutdownEventListener_h + +#include +#include + +class ShutdownEventListener : public QObject, public QAbstractNativeEventFilter { + Q_OBJECT +public: + ShutdownEventListener(QObject* parent = NULL); + + virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result); + +signals: + void receivedCloseEvent(); +}; + +#endif // hifi_ShutdownEventListener_h