mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
Add log window to the ESS log
This commit is contained in:
parent
2962dd6dc2
commit
191121888c
11 changed files with 203 additions and 77 deletions
|
@ -185,12 +185,20 @@ void EntityScriptServer::handleEntityServerScriptLogPacket(QSharedPointer<Receiv
|
|||
if (senderNode->getCanRez() || senderNode->getCanRezTmp()) {
|
||||
bool enable = false;
|
||||
message->readPrimitive(&enable);
|
||||
qInfo() << "======== Got log packet:" << enable;
|
||||
|
||||
auto senderUUID = senderNode->getUUID();
|
||||
auto it = _logListeners.find(senderUUID);
|
||||
|
||||
if (enable) {
|
||||
_logListeners.insert(senderNode->getUUID());
|
||||
if (it == std::end(_logListeners)) {
|
||||
_logListeners.insert(senderUUID);
|
||||
qInfo() << "Node" << senderUUID << "subscribed to log stream";
|
||||
}
|
||||
} else {
|
||||
_logListeners.erase(senderNode->getUUID());
|
||||
if (it != std::end(_logListeners)) {
|
||||
_logListeners.erase(it);
|
||||
qInfo() << "Node" << senderUUID << "unsubscribed from log stream";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,9 +298,67 @@ void EntityScriptServer::run() {
|
|||
connect(tree, &EntityTree::entityServerScriptChanging, this, &EntityScriptServer::entityServerScriptChanging, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void EntityScriptServer::cleanupOldKilledListeners() {
|
||||
auto threshold = usecTimestampNow() - 5 * USECS_PER_SECOND;
|
||||
using ValueType = std::pair<QUuid, quint64>;
|
||||
auto it = std::remove_if(std::begin(_killedListeners), std::end(_killedListeners), [&](ValueType value) {
|
||||
return value.second < threshold;
|
||||
});
|
||||
_killedListeners.erase(it, std::end(_killedListeners));
|
||||
}
|
||||
|
||||
void EntityScriptServer::nodeActivated(SharedNodePointer activatedNode) {
|
||||
if (activatedNode->getType() == NodeType::AudioMixer) {
|
||||
negotiateAudioFormat();
|
||||
switch (activatedNode->getType()) {
|
||||
case NodeType::AudioMixer:
|
||||
negotiateAudioFormat();
|
||||
break;
|
||||
case NodeType::Agent: {
|
||||
auto activatedNodeUUID = activatedNode->getUUID();
|
||||
using ValueType = std::pair<QUuid, quint64>;
|
||||
auto it = std::find_if(std::begin(_killedListeners), std::end(_killedListeners), [&](ValueType value) {
|
||||
return value.first == activatedNodeUUID;
|
||||
});
|
||||
if (it != std::end(_killedListeners)) {
|
||||
_killedListeners.erase(it);
|
||||
_logListeners.insert(activatedNodeUUID);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityScriptServer::nodeKilled(SharedNodePointer killedNode) {
|
||||
switch (killedNode->getType()) {
|
||||
case NodeType::EntityServer: {
|
||||
if (!_shuttingDown) {
|
||||
if (_entitiesScriptEngine) {
|
||||
_entitiesScriptEngine->unloadAllEntityScripts();
|
||||
_entitiesScriptEngine->stop();
|
||||
}
|
||||
|
||||
resetEntitiesScriptEngine();
|
||||
|
||||
_entityViewer.clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NodeType::Agent: {
|
||||
cleanupOldKilledListeners();
|
||||
|
||||
auto killedNodeUUID = killedNode->getUUID();
|
||||
auto it = _logListeners.find(killedNodeUUID);
|
||||
if (it != std::end(_logListeners)) {
|
||||
_logListeners.erase(killedNodeUUID);
|
||||
_killedListeners.emplace_back(killedNodeUUID, usecTimestampNow());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -433,31 +499,6 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const
|
|||
}
|
||||
}
|
||||
|
||||
void EntityScriptServer::nodeKilled(SharedNodePointer killedNode) {
|
||||
switch (killedNode->getType()) {
|
||||
case NodeType::EntityServer: {
|
||||
if (!_shuttingDown) {
|
||||
if (_entitiesScriptEngine) {
|
||||
_entitiesScriptEngine->unloadAllEntityScripts();
|
||||
_entitiesScriptEngine->stop();
|
||||
}
|
||||
|
||||
resetEntitiesScriptEngine();
|
||||
|
||||
_entityViewer.clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NodeType::Agent: {
|
||||
_logListeners.erase(killedNode->getUUID());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityScriptServer::sendStatsPacket() {
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define hifi_EntityScriptServer_h
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUuid>
|
||||
|
@ -69,6 +70,8 @@ private:
|
|||
void entityServerScriptChanging(const EntityItemID& entityID, const bool reload);
|
||||
void checkAndCallPreload(const EntityItemID& entityID, const bool reload = false);
|
||||
|
||||
void cleanupOldKilledListeners();
|
||||
|
||||
bool _shuttingDown { false };
|
||||
|
||||
static int _entitiesScriptEngineCount;
|
||||
|
@ -80,6 +83,7 @@ private:
|
|||
int _entityPPSPerScript { DEFAULT_ENTITY_PPS_PER_SCRIPT };
|
||||
|
||||
std::set<QUuid> _logListeners;
|
||||
std::vector<std::pair<QUuid, quint64>> _killedListeners;
|
||||
|
||||
QString _selectedCodecName;
|
||||
CodecPluginPointer _codec;
|
||||
|
|
|
@ -6284,6 +6284,17 @@ void Application::toggleLogDialog() {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::toggleEntityScriptServerLogDialog() {
|
||||
if (! _entityScriptServerLogDialog) {
|
||||
_entityScriptServerLogDialog = new EntityScriptServerLogDialog(nullptr);
|
||||
}
|
||||
|
||||
if (_entityScriptServerLogDialog->isVisible()) {
|
||||
_entityScriptServerLogDialog->hide();
|
||||
} else {
|
||||
_entityScriptServerLogDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio) {
|
||||
postLambdaEvent([notify, includeAnimated, aspectRatio, this] {
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "scripting/DialogsManagerScriptingInterface.h"
|
||||
#include "ui/ApplicationOverlay.h"
|
||||
#include "ui/BandwidthDialog.h"
|
||||
#include "ui/EntityScriptServerLogDialog.h"
|
||||
#include "ui/LodToolsDialog.h"
|
||||
#include "ui/LogDialog.h"
|
||||
#include "ui/OctreeStatsDialog.h"
|
||||
|
@ -314,6 +315,7 @@ public slots:
|
|||
Q_INVOKABLE void loadDialog();
|
||||
Q_INVOKABLE void loadScriptURLDialog() const;
|
||||
void toggleLogDialog();
|
||||
void toggleEntityScriptServerLogDialog();
|
||||
void toggleRunningScriptsWidget() const;
|
||||
Q_INVOKABLE void showAssetServerWidget(QString filePath = "");
|
||||
|
||||
|
@ -566,6 +568,7 @@ private:
|
|||
NodeToOctreeSceneStats _octreeServerSceneStats;
|
||||
ControllerScriptingInterface* _controllerScriptingInterface{ nullptr };
|
||||
QPointer<LogDialog> _logDialog;
|
||||
QPointer<EntityScriptServerLogDialog> _entityScriptServerLogDialog;
|
||||
|
||||
FileLogger* _logger;
|
||||
|
||||
|
|
|
@ -702,7 +702,16 @@ Menu::Menu() {
|
|||
|
||||
// Developer > Log...
|
||||
addActionToQMenuAndActionHash(developerMenu, MenuOption::Log, Qt::CTRL | Qt::SHIFT | Qt::Key_L,
|
||||
qApp, SLOT(toggleLogDialog()));
|
||||
qApp, SLOT(toggleLogDialog()));
|
||||
auto essLogAction = addActionToQMenuAndActionHash(developerMenu, MenuOption::EntityScriptServerLog, 0,
|
||||
qApp, SLOT(toggleEntityScriptServerLogDialog()));
|
||||
auto shouldEnableLog = [essLogAction] {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
essLogAction->setEnabled(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp());
|
||||
};
|
||||
QObject::connect(nodeList.data(), &NodeList::canRezChanged, essLogAction, shouldEnableLog);
|
||||
QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, essLogAction, shouldEnableLog);
|
||||
shouldEnableLog();
|
||||
|
||||
action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)...");
|
||||
connect(action, &QAction::triggered, [] {
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace MenuOption {
|
|||
const QString EchoServerAudio = "Echo Server Audio";
|
||||
const QString EnableCharacterController = "Enable avatar collisions";
|
||||
const QString EnableInverseKinematics = "Enable Inverse Kinematics";
|
||||
const QString EntityScriptServerLog = "Entity Script Server Log";
|
||||
const QString ExpandMyAvatarSimulateTiming = "Expand /myAvatar/simulation";
|
||||
const QString ExpandMyAvatarTiming = "Expand /myAvatar";
|
||||
const QString ExpandOtherAvatarTiming = "Expand /otherAvatar";
|
||||
|
|
|
@ -95,10 +95,8 @@ void BaseLogDialog::resizeEvent(QResizeEvent* event) {
|
|||
}
|
||||
|
||||
void BaseLogDialog::appendLogLine(QString logLine) {
|
||||
if (isVisible()) {
|
||||
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
||||
_logTextBox->appendPlainText(logLine.trimmed());
|
||||
}
|
||||
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
||||
_logTextBox->appendPlainText(logLine.trimmed());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,17 +107,14 @@ void BaseLogDialog::handleSearchButton() {
|
|||
void BaseLogDialog::handleSearchTextChanged(QString searchText) {
|
||||
_searchTerm = searchText;
|
||||
_highlighter->keyword = searchText;
|
||||
showLogData();
|
||||
_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
void BaseLogDialog::showLogData() {
|
||||
_logTextBox->clear();
|
||||
_logTextBox->insertPlainText(getCurrentLog());
|
||||
_logTextBox->setPlainText(getCurrentLog());
|
||||
_logTextBox->ensureCursorVisible();
|
||||
}
|
||||
|
||||
|
||||
|
||||
KeywordHighlighter::KeywordHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
|
||||
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
||||
}
|
||||
|
|
58
interface/src/ui/EntityScriptServerLogDialog.cpp
Normal file
58
interface/src/ui/EntityScriptServerLogDialog.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// EntityScriptServerLogDialog.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Clement Brisset on 1/31/17.
|
||||
// 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
|
||||
//
|
||||
|
||||
#include "EntityScriptServerLogDialog.h"
|
||||
|
||||
EntityScriptServerLogDialog::EntityScriptServerLogDialog(QWidget* parent) : BaseLogDialog(parent) {
|
||||
setWindowTitle("Entity Script Server Log");
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket");
|
||||
|
||||
auto shouldEnableLog = [this] {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
enableToEntityServerScriptLog(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp());
|
||||
};
|
||||
QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, shouldEnableLog);
|
||||
QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, this, shouldEnableLog);
|
||||
shouldEnableLog();
|
||||
}
|
||||
|
||||
EntityScriptServerLogDialog::~EntityScriptServerLogDialog() {
|
||||
enableToEntityServerScriptLog(false);
|
||||
}
|
||||
|
||||
void EntityScriptServerLogDialog::enableToEntityServerScriptLog(bool enable) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
if (auto node = nodeList->soloNodeOfType(NodeType::EntityScriptServer)) {
|
||||
auto packet = NLPacket::create(PacketType::EntityServerScriptLog, sizeof(bool), true);
|
||||
packet->writePrimitive(enable);
|
||||
nodeList->sendPacket(std::move(packet), *node);
|
||||
|
||||
if (_subscribed != enable) {
|
||||
if (enable) {
|
||||
appendLogLine("====================== Subscribded to the Entity Script Server's log ======================");
|
||||
} else {
|
||||
appendLogLine("==================== Unsubscribded from the Entity Script Server's log ====================");
|
||||
}
|
||||
}
|
||||
_subscribed = enable;
|
||||
} else {
|
||||
qWarning() << "Entity Script Server not found";
|
||||
}
|
||||
}
|
||||
|
||||
void EntityScriptServerLogDialog::handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
||||
auto lines = QString::fromUtf8(message->readAll());
|
||||
QMetaObject::invokeMethod(this, "appendLogLine", Q_ARG(QString, lines));
|
||||
}
|
37
interface/src/ui/EntityScriptServerLogDialog.h
Normal file
37
interface/src/ui/EntityScriptServerLogDialog.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// EntityScriptServerLogDialog.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Clement Brisset on 1/31/17.
|
||||
// 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_EntityScriptServerLogDialog_h
|
||||
#define hifi_EntityScriptServerLogDialog_h
|
||||
|
||||
#include "BaseLogDialog.h"
|
||||
|
||||
#include <NodeList.h>
|
||||
|
||||
class EntityScriptServerLogDialog : public BaseLogDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EntityScriptServerLogDialog(QWidget* parent = nullptr);
|
||||
~EntityScriptServerLogDialog();
|
||||
|
||||
protected:
|
||||
QString getCurrentLog() override { return QString(); };
|
||||
|
||||
private slots:
|
||||
void enableToEntityServerScriptLog(bool enable);
|
||||
void handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
|
||||
private:
|
||||
bool _subscribed { false };
|
||||
};
|
||||
|
||||
#endif // hifi_EntityScriptServerLogDialog_h
|
|
@ -28,8 +28,7 @@ LogDialog::LogDialog(QWidget* parent, AbstractLoggerInterface* logger) : BaseLog
|
|||
_extraDebuggingBox->setCheckState(Qt::Checked);
|
||||
}
|
||||
_extraDebuggingBox->show();
|
||||
//connect(_extraDebuggingBox, SIGNAL(stateChanged(int)), SLOT(handleExtraDebuggingCheckbox(int)));
|
||||
connect(_extraDebuggingBox, &QCheckBox::stateChanged, this, &LogDialog::enableToEntityServerScriptLog);
|
||||
connect(_extraDebuggingBox, SIGNAL(stateChanged(int)), SLOT(handleExtraDebuggingCheckbox(int)));
|
||||
|
||||
_revealLogButton = new QPushButton("Reveal log file", this);
|
||||
// set object name for css styling
|
||||
|
@ -37,9 +36,7 @@ LogDialog::LogDialog(QWidget* parent, AbstractLoggerInterface* logger) : BaseLog
|
|||
_revealLogButton->show();
|
||||
connect(_revealLogButton, SIGNAL(clicked()), SLOT(handleRevealButton()));
|
||||
|
||||
//connect(_logger, SIGNAL(logReceived(QString)), this, SLOT(appendLogLine(QString)), Qt::QueuedConnection);
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerListener(PacketType::EntityServerScriptLog, this, "handleEntityServerScriptLogPacket");
|
||||
connect(_logger, SIGNAL(logReceived(QString)), this, SLOT(appendLogLine(QString)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void LogDialog::resizeEvent(QResizeEvent* event) {
|
||||
|
@ -54,35 +51,10 @@ void LogDialog::handleRevealButton() {
|
|||
_logger->locateLog();
|
||||
}
|
||||
|
||||
void LogDialog::handleExtraDebuggingCheckbox(const int state) {
|
||||
void LogDialog::handleExtraDebuggingCheckbox(int state) {
|
||||
_logger->setExtraDebugging(state != 0);
|
||||
}
|
||||
|
||||
QString LogDialog::getCurrentLog() {
|
||||
return _logger->getLogData();
|
||||
}
|
||||
|
||||
void LogDialog::enableToEntityServerScriptLog(bool enable) {
|
||||
qDebug() << Q_FUNC_INFO << enable;
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
if (auto node = nodeList->soloNodeOfType(NodeType::EntityScriptServer)) {
|
||||
auto packet = NLPacket::create(PacketType::EntityServerScriptLog, sizeof(bool), true);
|
||||
packet->writePrimitive(enable);
|
||||
nodeList->sendPacket(std::move(packet), *node);
|
||||
|
||||
if (enable) {
|
||||
appendLogLine("====================== Subscribded to the Entity Script Server's log ======================");
|
||||
} else {
|
||||
appendLogLine("==================== Unsubscribded from the Entity Script Server's log ====================");
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Entity Script Server not found";
|
||||
}
|
||||
}
|
||||
|
||||
void LogDialog::handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
||||
auto lines = QString::fromUtf8(message->readAll());
|
||||
QMetaObject::invokeMethod(this, "appendLogLine", Q_ARG(QString, lines));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
#include "BaseLogDialog.h"
|
||||
|
||||
#include <NodeList.h>
|
||||
|
||||
class QCheckBox;
|
||||
class QPushButton;
|
||||
class QResizeEvent;
|
||||
|
@ -29,10 +27,7 @@ public:
|
|||
|
||||
private slots:
|
||||
void handleRevealButton();
|
||||
void handleExtraDebuggingCheckbox(const int);
|
||||
|
||||
void enableToEntityServerScriptLog(bool enable);
|
||||
void handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
void handleExtraDebuggingCheckbox(int);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
|
Loading…
Reference in a new issue