Move wm_close handling to a shared library

This commit is contained in:
Ryan Huffman 2014-09-03 06:47:05 -07:00
parent 444a974bd6
commit c27bee2c06
6 changed files with 69 additions and 19 deletions

View file

@ -36,7 +36,8 @@ int hifiSockAddrMeta = qRegisterMetaType<HifiSockAddr>("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);

View file

@ -15,14 +15,14 @@
#include <QtCore/QCoreApplication>
#include <QAbstractNativeEventFilter>
#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;
};

View file

@ -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>("DomainServerWebSessionData");
qRegisterMetaTypeStreamOperators<DomainServerWebSessionData>("DomainServerWebSessionData");

View file

@ -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;

View file

@ -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;
}

View file

@ -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 <QObject>
#include <QAbstractNativeEventFilter>
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