Showing the changes to libraries/entities/src/EntityScriptServerLogClient.cpp (1 of 11 files). Show all
Unified · Split
| @@ -9,7 +9,11 @@ · 8 unmodified lines | ||
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | 11 | |
| 12 | +#include <QJsonDocument> | |
| 13 | +#include <QJsonArray> | |
| 12 | 14 | #include "EntityScriptServerLogClient.h" |
| 15 | +#include "ScriptMessage.h" | |
| 16 | +#include "ScriptEngines.h" | |
| 13 | 17 | |
| 14 | 18 | EntityScriptServerLogClient::EntityScriptServerLogClient() { |
| 15 | 19 | auto nodeList = DependencyManager::get<NodeList>(); |
| @@ -62,7 +66,59 @@ void EntityScriptServerLogClient::enableToEntityServerScriptLog(bool enable) { · 46 unmodified lines | ||
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | void EntityScriptServerLogClient::handleEntityServerScriptLogPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { |
| 65 | − emit receivedNewLogLines(QString::fromUtf8(message->readAll())); | |
| 69 | + QString messageText = QString::fromUtf8(message->readAll()); | |
| 70 | + QJsonParseError error; | |
| 71 | + QJsonDocument document = QJsonDocument::fromJson(messageText.toUtf8(), &error); | |
| 72 | + emit receivedNewLogLines(messageText); | |
| 73 | + if(document.isNull()) { | |
| 74 | + qWarning() << "EntityScriptServerLogClient::handleEntityServerScriptLogPacket: Cannot parse JSON: " << error.errorString() | |
| 75 | + << " Contents: " << messageText; | |
| 76 | + return; | |
| 77 | + } | |
| 78 | + // Iterate through contents and emit messages | |
| 79 | + if(!document.isArray()) { | |
| 80 | + qWarning() << "EntityScriptServerLogClient::handleEntityServerScriptLogPacket: JSON is not an array: " << messageText; | |
| 81 | + return; | |
| 82 | + } | |
| 83 | + | |
| 84 | + auto scriptEngines = DependencyManager::get<ScriptEngines>().data(); | |
| 85 | + | |
| 86 | + auto array = document.array(); | |
| 87 | + for (int n = 0; n < array.size(); n++) { | |
| 88 | + if (!array[n].isObject()) { | |
| 89 | + qWarning() << "EntityScriptServerLogClient::handleEntityServerScriptLogPacket: message is not an object: " << messageText; | |
| 90 | + continue; | |
| 91 | + } | |
| 92 | + ScriptMessage scriptMessage; | |
| 93 | + if (!scriptMessage.fromJson(array[n].toObject())) { | |
| 94 | + qWarning() << "EntityScriptServerLogClient::handleEntityServerScriptLogPacket: message parsing failed: " << messageText; | |
| 95 | + continue; | |
| 96 | + } | |
| 97 | + switch (scriptMessage.getSeverity()) { | |
| 98 | + case ScriptMessage::Severity::SEVERITY_INFO: | |
| 99 | + emit scriptEngines->infoEntityMessage(scriptMessage.getMessage(), scriptMessage.getFileName(), | |
| 100 | + scriptMessage.getLineNumber(), scriptMessage.getEntityID(), true); | |
| 101 | + break; | |
| 102 | + | |
| 103 | + case ScriptMessage::Severity::SEVERITY_PRINT: | |
| 104 | + emit scriptEngines->printedEntityMessage(scriptMessage.getMessage(), scriptMessage.getFileName(), | |
| 105 | + scriptMessage.getLineNumber(), scriptMessage.getEntityID(), true); | |
| 106 | + break; | |
| 107 | + | |
| 108 | + case ScriptMessage::Severity::SEVERITY_WARNING: | |
| 109 | + emit scriptEngines->warningEntityMessage(scriptMessage.getMessage(), scriptMessage.getFileName(), | |
| 110 | + scriptMessage.getLineNumber(), scriptMessage.getEntityID(), true); | |
| 111 | + break; | |
| 112 | + | |
| 113 | + case ScriptMessage::Severity::SEVERITY_ERROR: | |
| 114 | + emit scriptEngines->errorEntityMessage(scriptMessage.getMessage(), scriptMessage.getFileName(), | |
| 115 | + scriptMessage.getLineNumber(), scriptMessage.getEntityID(), true); | |
| 116 | + break; | |
| 117 | + | |
| 118 | + default: | |
| 119 | + break; | |
| 120 | + } | |
| 121 | + } | |
| 66 | 122 | } |
| 67 | 123 | |
| 68 | 124 | void EntityScriptServerLogClient::nodeActivated(SharedNodePointer activatedNode) { |