Merge pull request #3360 from huffman/fix-domain-server

Revert the revert and fix domain server
This commit is contained in:
Leonardo Murillo 2014-09-05 12:39:07 -06:00
commit c2db0c6a30
8 changed files with 127 additions and 1 deletions

View file

@ -17,6 +17,7 @@
#include <Assignment.h>
#include <HifiConfigVariantMap.h>
#include <Logging.h>
#include <LogUtils.h>
#include <NodeList.h>
#include <PacketHeaders.h>
#include <SharedUtil.h>
@ -36,13 +37,19 @@ 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)
{
LogUtils::init();
setOrganizationName("High Fidelity");
setOrganizationDomain("highfidelity.io");
setApplicationName("assignment-client");
QSettings::setDefaultFormat(QSettings::IniFormat);
installNativeEventFilter(&_shutdownEventListener);
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
// set the logging target to the the CHILD_TARGET_NAME
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);

View file

@ -14,6 +14,7 @@
#include <QtCore/QCoreApplication>
#include "ShutdownEventListener.h"
#include "ThreadedAssignment.h"
class AssignmentClient : public QCoreApplication {
@ -21,6 +22,7 @@ class AssignmentClient : public QCoreApplication {
public:
AssignmentClient(int &argc, char **argv);
static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; }
private slots:
void sendAssignmentRequest();
void readPendingDatagrams();
@ -30,6 +32,7 @@ private slots:
private:
Assignment _requestAssignment;
static SharedAssignmentPointer _currentAssignment;
ShutdownEventListener _shutdownEventListener;
QString _assignmentServerHostname;
};

View file

@ -21,6 +21,7 @@
#include <AccountManager.h>
#include <HifiConfigVariantMap.h>
#include <HTTPConnection.h>
#include <LogUtils.h>
#include <PacketHeaders.h>
#include <SharedUtil.h>
#include <UUID.h>
@ -31,6 +32,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(),
@ -46,10 +48,16 @@ DomainServer::DomainServer(int argc, char* argv[]) :
_cookieSessionHash(),
_settingsManager()
{
LogUtils::init();
setOrganizationName("High Fidelity");
setOrganizationDomain("highfidelity.io");
setApplicationName("domain-server");
QSettings::setDefaultFormat(QSettings::IniFormat);
installNativeEventFilter(&_shutdownEventListener);
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
qRegisterMetaType<DomainServerWebSessionData>("DomainServerWebSessionData");
qRegisterMetaTypeStreamOperators<DomainServerWebSessionData>("DomainServerWebSessionData");

View file

@ -19,6 +19,7 @@
#include <QtCore/QSharedPointer>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QAbstractNativeEventFilter>
#include <Assignment.h>
#include <HTTPSConnection.h>
@ -26,6 +27,7 @@
#include "DomainServerSettingsManager.h"
#include "DomainServerWebSessionData.h"
#include "ShutdownEventListener.h"
#include "WalletTransaction.h"
#include "PendingAssignedNodeData.h"
@ -97,6 +99,8 @@ private:
QJsonObject jsonForSocket(const HifiSockAddr& socket);
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
ShutdownEventListener _shutdownEventListener;
HTTPManager _httpManager;
HTTPSManager* _httpsManager;

View file

@ -0,0 +1,24 @@
//
// LogUtils.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 "LogUtils.h"
void LogUtils::init() {
#ifdef Q_OS_WIN
// Windows applications buffer stdout/err hard when not run from a terminal,
// making assignment clients run from the Stack Manager application not flush
// log messages.
// This will disable the buffering. If this becomes a performance issue,
// an alternative is to call fflush(...) periodically.
setbuf(stdout, NULL);
setbuf(stderr, NULL);
#endif
}

View file

@ -0,0 +1,20 @@
//
// LogUtils.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_LogUtils_h
#define hifi_LogUtils_h
class LogUtils {
public:
static void init();
};
#endif // hifi_LogUtils_h

View file

@ -0,0 +1,31 @@
//
// 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"
#ifdef Q_OS_WIN
#include <Windows.h>
#endif
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 false;
}

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