Merge pull request #33 from huffman/feat/entity-server-script-property

Fix compilation error and move MessageID to CilentServerUtils
This commit is contained in:
Clément Brisset 2017-01-20 17:37:01 -08:00 committed by GitHub
commit 6da188b6ae
9 changed files with 37 additions and 13 deletions

View file

@ -27,6 +27,7 @@
#include "NodeType.h"
#include "SendAssetTask.h"
#include "UploadAssetTask.h"
#include <ClientServerUtils.h>
const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server";

View file

@ -21,6 +21,7 @@
#include <udt/Packet.h>
#include "AssetUtils.h"
#include "ClientServerUtils.h"
SendAssetTask::SendAssetTask(QSharedPointer<ReceivedMessage> message, const SharedNodePointer& sendToNode, const QDir& resourcesDir) :
QRunnable(),

View file

@ -18,6 +18,8 @@
#include <NodeList.h>
#include <NLPacketList.h>
#include "ClientServerUtils.h"
UploadAssetTask::UploadAssetTask(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode,
const QDir& resourcesDir) :

View file

@ -11,8 +11,6 @@
#include "EntityScriptServer.h"
#include "EntityScriptUtils.h"
#include <AudioConstants.h>
#include <AudioInjectorManager.h>
#include <EntityScriptingInterface.h>
@ -26,6 +24,7 @@
#include <UUID.h>
#include <WebSocketServerClass.h>
#include "ClientServerUtils.h"
#include "../entities/AssignmentParentFinder.h"
int EntityScriptServer::_entitiesScriptEngineCount = 0;

View file

@ -21,6 +21,7 @@
#include <DependencyManager.h>
#include "AssetUtils.h"
#include "ClientServerUtils.h"
#include "LimitedNodeList.h"
#include "Node.h"
#include "ReceivedMessage.h"

View file

@ -19,7 +19,6 @@
#include <QtCore/QByteArray>
#include <QtCore/QUrl>
using MessageID = uint32_t;
using DataOffset = int64_t;
using AssetPath = QString;
@ -27,8 +26,6 @@ using AssetHash = QString;
using AssetMapping = std::map<AssetPath, AssetHash>;
using AssetPathList = QStringList;
const MessageID INVALID_MESSAGE_ID = 0;
const size_t SHA256_HASH_LENGTH = 32;
const size_t SHA256_HASH_HEX_LENGTH = 64;
const uint64_t MAX_UPLOAD_SIZE = 1000 * 1000 * 1000; // 1GB
@ -66,4 +63,4 @@ bool isValidFilePath(const AssetPath& path);
bool isValidPath(const AssetPath& path);
bool isValidHash(const QString& hashString);
#endif
#endif // hifi_AssetUtils_h

View file

@ -0,0 +1,21 @@
//
// ClientServerUtils.h
// libraries/networking/src
//
// Created by Ryan Huffman on 2017/01/20
// Copyright 2017 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_ClientServerUtils_h
#define hifi_ClientServerUtils_h
#include <cstdint>
using MessageID = uint32_t;
const MessageID INVALID_MESSAGE_ID = 0;
#endif // hifi_ClientServerUtils_h

View file

@ -12,6 +12,7 @@
#ifndef hifi_EntityScriptClient_h
#define hifi_EntityScriptClient_h
#include "ClientServerUtils.h"
#include "LimitedNodeList.h"
#include "ReceivedMessage.h"
#include "AssetUtils.h"
@ -20,8 +21,6 @@
#include <DependencyManager.h>
#include <unordered_map>
using MessageID = uint32_t;
using GetScriptStatusCallback = std::function<void(bool responseReceived, bool isRunning, EntityScriptStatus status, QString errorInfo)>;
class GetScriptStatusRequest : public QObject {

View file

@ -147,19 +147,22 @@ static bool hasCorrectSyntax(const QScriptProgram& program, ScriptEngine* report
return true;
}
static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine, QString& exceptionMessage = QString()) {
static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine, QString* exceptionMessage = nullptr) {
if (engine.hasUncaughtException()) {
const auto backtrace = engine.uncaughtExceptionBacktrace();
const auto exception = engine.uncaughtException().toString();
const auto line = QString::number(engine.uncaughtExceptionLineNumber());
engine.clearExceptions();
exceptionMessage = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line);
QString message = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line);
if (!backtrace.empty()) {
static const auto lineSeparator = "\n ";
exceptionMessage += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));
message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));
}
reportingEngine->scriptErrorMessage(qPrintable(message));
if (exceptionMessage) {
*exceptionMessage = message;
}
reportingEngine->scriptErrorMessage(qPrintable(exceptionMessage));
return true;
}
return false;
@ -1471,7 +1474,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
}
QString exceptionMessage;
if (hadUncaughtExceptions(sandbox, program.fileName(), this, exceptionMessage)) {
if (hadUncaughtExceptions(sandbox, program.fileName(), this, &exceptionMessage)) {
newDetails.status = ERROR_RUNNING_SCRIPT;
newDetails.errorInfo = exceptionMessage;
_entityScripts[entityID] = newDetails;