2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2016-01-15 14:59:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:59:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:59:14 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
#include "nodeinstanceclientproxy.h"
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStringList>
|
2013-07-04 17:06:31 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QBuffer>
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
#include "nodeinstanceserverinterface.h"
|
|
|
|
|
2020-07-27 18:14:33 +02:00
|
|
|
#include "captureddatacommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "changeauxiliarycommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "changebindingscommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "changefileurlcommand.h"
|
|
|
|
#include "changeidscommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "changelanguagecommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "changenodesourcecommand.h"
|
|
|
|
#include "changepreviewimagesizecommand.h"
|
|
|
|
#include "changeselectioncommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "changestatecommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "changevaluescommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "childrenchangedcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "clearscenecommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "completecomponentcommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "componentcompletedcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "createinstancescommand.h"
|
|
|
|
#include "createscenecommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "debugoutputcommand.h"
|
|
|
|
#include "endpuppetcommand.h"
|
|
|
|
#include "imagecontainer.h"
|
|
|
|
#include "informationchangedcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "inputeventcommand.h"
|
|
|
|
#include "instancecontainer.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "pixmapchangedcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "propertyabstractcontainer.h"
|
|
|
|
#include "propertybindingcontainer.h"
|
|
|
|
#include "propertyvaluecontainer.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "puppetalivecommand.h"
|
|
|
|
#include "puppettocreatorcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "removeinstancescommand.h"
|
|
|
|
#include "removepropertiescommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "removesharedmemorycommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "reparentinstancescommand.h"
|
2020-09-03 13:48:13 +02:00
|
|
|
#include "scenecreatedcommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "statepreviewimagechangedcommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "synchronizecommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "tokencommand.h"
|
2020-04-28 11:21:03 +02:00
|
|
|
#include "update3dviewstatecommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "valueschangedcommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "view3dactioncommand.h"
|
2020-09-10 16:02:31 +03:00
|
|
|
#include "requestmodelnodepreviewimagecommand.h"
|
2021-10-12 12:07:44 +02:00
|
|
|
#include "nanotracecommand.h"
|
2022-01-28 13:34:16 +02:00
|
|
|
|
|
|
|
// Nanotrace headers are not exported to build dir at all if the feature is disabled, so
|
|
|
|
// runtime puppet build can't find them.
|
|
|
|
#if NANOTRACE_ENABLED
|
2021-10-12 12:07:44 +02:00
|
|
|
#include "nanotrace/nanotrace.h"
|
2022-01-28 13:34:16 +02:00
|
|
|
#else
|
|
|
|
#define NANOTRACE_INIT(process, thread, filepath)
|
|
|
|
#define NANOTRACE_SHUTDOWN()
|
|
|
|
#define NANOTRACE_SCOPE_ARGS(cat, name, ...)
|
|
|
|
#endif
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
2020-09-10 11:39:00 +02:00
|
|
|
void (QLocalSocket::*LocalSocketErrorFunction)(QLocalSocket::LocalSocketError)
|
2020-02-19 09:07:12 +01:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
= &QLocalSocket::error;
|
|
|
|
#else
|
|
|
|
= &QLocalSocket::errorOccurred;
|
|
|
|
#endif
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
|
2020-07-27 18:14:33 +02:00
|
|
|
: QObject(parent)
|
|
|
|
, m_inputIoDevice(nullptr)
|
|
|
|
, m_outputIoDevice(nullptr)
|
|
|
|
, m_writeCommandCounter(0)
|
|
|
|
, m_synchronizeId(-1)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-11-19 14:33:31 +01:00
|
|
|
connect(&m_puppetAliveTimer, &QTimer::timeout, this, &NodeInstanceClientProxy::sendPuppetAliveCommand);
|
2020-05-25 14:43:05 +02:00
|
|
|
m_puppetAliveTimer.setInterval(2000);
|
2014-06-18 11:17:59 +02:00
|
|
|
m_puppetAliveTimer.start();
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 14:25:59 +02:00
|
|
|
NodeInstanceClientProxy::~NodeInstanceClientProxy() = default;
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
void NodeInstanceClientProxy::initializeSocket()
|
|
|
|
{
|
2013-07-04 17:06:31 +02:00
|
|
|
QLocalSocket *localSocket = new QLocalSocket(this);
|
2015-11-19 14:33:31 +01:00
|
|
|
connect(localSocket, &QIODevice::readyRead, this, &NodeInstanceClientProxy::readDataStream);
|
2020-02-19 09:07:12 +01:00
|
|
|
connect(localSocket, LocalSocketErrorFunction,
|
2016-05-31 22:34:05 +03:00
|
|
|
QCoreApplication::instance(), &QCoreApplication::quit);
|
2015-11-19 14:33:31 +01:00
|
|
|
connect(localSocket, &QLocalSocket::disconnected, QCoreApplication::instance(), &QCoreApplication::quit);
|
2013-07-04 17:06:31 +02:00
|
|
|
localSocket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
|
|
|
|
localSocket->waitForConnected(-1);
|
|
|
|
|
|
|
|
m_inputIoDevice = localSocket;
|
|
|
|
m_outputIoDevice = localSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::initializeCapturedStream(const QString &fileName)
|
|
|
|
{
|
|
|
|
m_inputIoDevice = new QFile(fileName, this);
|
|
|
|
bool inputStreamCanBeOpened = m_inputIoDevice->open(QIODevice::ReadOnly);
|
|
|
|
if (!inputStreamCanBeOpened) {
|
|
|
|
qDebug() << "Input stream file cannot be opened: " << fileName;
|
2013-07-16 15:56:47 +02:00
|
|
|
exit(-1);
|
2013-07-04 17:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (QCoreApplication::arguments().count() == 3) {
|
|
|
|
QFileInfo inputFileInfo(fileName);
|
|
|
|
m_outputIoDevice = new QFile(inputFileInfo.path()+ "/" + inputFileInfo.baseName() + ".commandcontrolstream", this);
|
|
|
|
bool outputStreamCanBeOpened = m_outputIoDevice->open(QIODevice::WriteOnly);
|
|
|
|
if (!outputStreamCanBeOpened) {
|
|
|
|
qDebug() << "Output stream file cannot be opened";
|
2013-07-16 15:56:47 +02:00
|
|
|
exit(-1);
|
2013-07-04 17:06:31 +02:00
|
|
|
}
|
|
|
|
} else if (QCoreApplication::arguments().count() == 4) {
|
|
|
|
m_controlStream.setFileName(QCoreApplication::arguments().at(3));
|
|
|
|
bool controlStreamCanBeOpened = m_controlStream.open(QIODevice::ReadOnly);
|
|
|
|
if (!controlStreamCanBeOpened) {
|
|
|
|
qDebug() << "Control stream file cannot be opened";
|
2013-07-16 15:56:47 +02:00
|
|
|
exit(-1);
|
2013-07-04 17:06:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareCommands(const QVariant &command, const QVariant &controlCommand)
|
|
|
|
{
|
|
|
|
static const int informationChangedCommandType = QMetaType::type("InformationChangedCommand");
|
|
|
|
static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand");
|
2019-10-18 16:55:08 +02:00
|
|
|
static const int valuesModifiedCommandType = QMetaType::type("ValuesModifiedCommand");
|
2013-07-04 17:06:31 +02:00
|
|
|
static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
|
|
|
|
static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
|
|
|
|
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
|
|
|
|
static const int componentCompletedCommandType = QMetaType::type("ComponentCompletedCommand");
|
|
|
|
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
|
|
|
|
static const int tokenCommandType = QMetaType::type("TokenCommand");
|
|
|
|
static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
|
2019-10-17 13:51:57 +02:00
|
|
|
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
|
2013-07-04 17:06:31 +02:00
|
|
|
|
|
|
|
if (command.userType() == controlCommand.userType()) {
|
|
|
|
if (command.userType() == informationChangedCommandType)
|
|
|
|
return command.value<InformationChangedCommand>() == controlCommand.value<InformationChangedCommand>();
|
|
|
|
else if (command.userType() == valuesChangedCommandType)
|
|
|
|
return command.value<ValuesChangedCommand>() == controlCommand.value<ValuesChangedCommand>();
|
2019-10-18 16:55:08 +02:00
|
|
|
else if (command.userType() == valuesModifiedCommandType)
|
|
|
|
return command.value<ValuesModifiedCommand>() == controlCommand.value<ValuesModifiedCommand>();
|
|
|
|
else if (command.userType() == pixmapChangedCommandType)
|
2013-07-04 17:06:31 +02:00
|
|
|
return command.value<PixmapChangedCommand>() == controlCommand.value<PixmapChangedCommand>();
|
|
|
|
else if (command.userType() == childrenChangedCommandType)
|
|
|
|
return command.value<ChildrenChangedCommand>() == controlCommand.value<ChildrenChangedCommand>();
|
|
|
|
else if (command.userType() == statePreviewImageChangedCommandType)
|
|
|
|
return command.value<StatePreviewImageChangedCommand>() == controlCommand.value<StatePreviewImageChangedCommand>();
|
|
|
|
else if (command.userType() == componentCompletedCommandType)
|
|
|
|
return command.value<ComponentCompletedCommand>() == controlCommand.value<ComponentCompletedCommand>();
|
|
|
|
else if (command.userType() == synchronizeCommandType)
|
|
|
|
return command.value<SynchronizeCommand>() == controlCommand.value<SynchronizeCommand>();
|
|
|
|
else if (command.userType() == tokenCommandType)
|
|
|
|
return command.value<TokenCommand>() == controlCommand.value<TokenCommand>();
|
|
|
|
else if (command.userType() == debugOutputCommandType)
|
|
|
|
return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>();
|
2019-10-17 13:51:57 +02:00
|
|
|
else if (command.userType() == changeSelectionCommandType)
|
2020-07-27 18:14:33 +02:00
|
|
|
return command.value<ChangeSelectionCommand>()
|
|
|
|
== controlCommand.value<ChangeSelectionCommand>();
|
2013-07-04 17:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::writeCommand(const QVariant &command)
|
|
|
|
{
|
2013-07-04 17:06:31 +02:00
|
|
|
if (m_controlStream.isReadable()) {
|
|
|
|
static quint32 readCommandCounter = 0;
|
|
|
|
static quint32 blockSize = 0;
|
|
|
|
|
|
|
|
QVariant controlCommand = readCommandFromIOStream(&m_controlStream, &readCommandCounter, &blockSize);
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
if (!compareCommands(command, controlCommand)) {
|
|
|
|
qDebug() << "Commands differ!";
|
2013-07-16 15:56:47 +02:00
|
|
|
exit(-1);
|
2013-07-04 17:06:31 +02:00
|
|
|
}
|
|
|
|
} else if (m_outputIoDevice) {
|
2021-10-12 12:07:44 +02:00
|
|
|
#ifdef NANOTRACE_ENABLED
|
|
|
|
if (command.userType() != QMetaType::type("PuppetAliveCommand")) {
|
|
|
|
if (command.userType() == QMetaType::type("SyncNanotraceCommand")) {
|
|
|
|
SyncNanotraceCommand cmd = command.value<SyncNanotraceCommand>();
|
|
|
|
NANOTRACE_INSTANT_ARGS("Sync", "writeCommand",
|
|
|
|
{"name", cmd.name().toStdString()},
|
2022-01-26 11:52:07 +01:00
|
|
|
{"counter", int64_t(m_writeCommandCounter)});
|
2021-10-12 12:07:44 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
NANOTRACE_INSTANT_ARGS("Update", "writeCommand",
|
|
|
|
{"name", command.typeName()},
|
2022-01-26 11:52:07 +01:00
|
|
|
{"counter", int64_t(m_writeCommandCounter)});
|
2021-10-12 12:07:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-04 17:06:31 +02:00
|
|
|
QByteArray block;
|
|
|
|
QDataStream out(&block, QIODevice::WriteOnly);
|
|
|
|
out.setVersion(QDataStream::Qt_4_8);
|
|
|
|
out << quint32(0);
|
|
|
|
out << quint32(m_writeCommandCounter);
|
|
|
|
m_writeCommandCounter++;
|
|
|
|
out << command;
|
|
|
|
out.device()->seek(0);
|
|
|
|
out << quint32(block.size() - sizeof(quint32));
|
|
|
|
|
|
|
|
m_outputIoDevice->write(block);
|
|
|
|
}
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2019-10-18 16:55:08 +02:00
|
|
|
void NodeInstanceClientProxy::valuesModified(const ValuesModifiedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::token(const TokenCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:42:31 +01:00
|
|
|
void NodeInstanceClientProxy::debugOutput(const DebugOutputCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2014-06-18 11:17:59 +02:00
|
|
|
void NodeInstanceClientProxy::puppetAlive(const PuppetAliveCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2019-10-17 13:51:57 +02:00
|
|
|
void NodeInstanceClientProxy::selectionChanged(const ChangeSelectionCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2020-01-02 11:58:33 +02:00
|
|
|
void NodeInstanceClientProxy::handlePuppetToCreatorCommand(const PuppetToCreatorCommand &command)
|
2019-11-01 10:51:09 +02:00
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2020-07-27 18:14:33 +02:00
|
|
|
void NodeInstanceClientProxy::capturedData(const CapturedDataCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2020-09-03 13:48:13 +02:00
|
|
|
void NodeInstanceClientProxy::sceneCreated(const SceneCreatedCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
void NodeInstanceClientProxy::flush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::synchronizeWithClientProcess()
|
|
|
|
{
|
|
|
|
if (m_synchronizeId >= 0) {
|
|
|
|
SynchronizeCommand synchronizeCommand(m_synchronizeId);
|
|
|
|
writeCommand(QVariant::fromValue(synchronizeCommand));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 NodeInstanceClientProxy::bytesToWrite() const
|
|
|
|
{
|
2013-07-04 17:06:31 +02:00
|
|
|
return m_inputIoDevice->bytesToWrite();
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
QVariant NodeInstanceClientProxy::readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2013-07-04 17:06:31 +02:00
|
|
|
QDataStream in(ioDevice);
|
|
|
|
in.setVersion(QDataStream::Qt_4_8);
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
if (*blockSize == 0) {
|
|
|
|
in >> *blockSize;
|
|
|
|
}
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
if (ioDevice->bytesAvailable() < *blockSize)
|
|
|
|
return QVariant();
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
quint32 commandCounter;
|
|
|
|
in >> commandCounter;
|
|
|
|
bool commandLost = !((commandCounter == 0 && *readCommandCounter == 0) || (*readCommandCounter + 1 == commandCounter));
|
|
|
|
if (commandLost)
|
|
|
|
qDebug() << "client command lost: " << *readCommandCounter << commandCounter;
|
|
|
|
*readCommandCounter = commandCounter;
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
QVariant command;
|
|
|
|
in >> command;
|
|
|
|
*blockSize = 0;
|
|
|
|
|
|
|
|
if (in.status() != QDataStream::Ok) {
|
2015-01-29 17:25:56 +01:00
|
|
|
qWarning() << "Stream is not OK";
|
2013-07-04 17:06:31 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
void NodeInstanceClientProxy::inputEvent(const InputEventCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->inputEvent(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::view3DAction(const View3DActionCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->view3DAction(command);
|
|
|
|
}
|
|
|
|
|
2020-09-10 16:02:31 +03:00
|
|
|
void NodeInstanceClientProxy::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->requestModelNodePreviewImage(command);
|
|
|
|
}
|
|
|
|
|
2020-04-28 11:21:03 +02:00
|
|
|
void NodeInstanceClientProxy::changeLanguage(const ChangeLanguageCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeLanguage(command);
|
|
|
|
}
|
|
|
|
|
2020-05-07 14:13:21 +02:00
|
|
|
void NodeInstanceClientProxy::changePreviewImageSize(const ChangePreviewImageSizeCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changePreviewImageSize(command);
|
|
|
|
}
|
|
|
|
|
2021-10-12 12:07:44 +02:00
|
|
|
void NodeInstanceClientProxy::startNanotrace(const StartNanotraceCommand &command)
|
|
|
|
{
|
|
|
|
QString name = qApp->arguments().at(2);
|
|
|
|
std::string directory = command.path().toStdString();
|
|
|
|
std::string processName = name.toStdString();
|
|
|
|
std::string fullFilePath =
|
|
|
|
directory + std::string("/nanotrace_qmlpuppet_") + processName + std::string(".json");
|
|
|
|
|
|
|
|
for (size_t i=0; i<processName.length(); ++i) {
|
|
|
|
if (i==0 || processName[i]=='m')
|
|
|
|
processName[i] = std::toupper(processName[i]);
|
|
|
|
}
|
|
|
|
processName = processName + std::string("Puppet");
|
|
|
|
|
|
|
|
NANOTRACE_INIT(processName.c_str(), "MainThread", fullFilePath);
|
|
|
|
|
|
|
|
writeCommand(QVariant::fromValue(SyncNanotraceCommand(name)));
|
|
|
|
}
|
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
void NodeInstanceClientProxy::readDataStream()
|
|
|
|
{
|
|
|
|
QList<QVariant> commandList;
|
|
|
|
|
|
|
|
while (!m_inputIoDevice->atEnd()) {
|
|
|
|
if (m_inputIoDevice->bytesAvailable() < int(sizeof(quint32)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
static quint32 readCommandCounter = 0;
|
|
|
|
static quint32 blockSize = 0;
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-07-04 17:06:31 +02:00
|
|
|
QVariant command = readCommandFromIOStream(m_inputIoDevice, &readCommandCounter, &blockSize);
|
2021-10-12 12:07:44 +02:00
|
|
|
#ifdef NANOTRACE_ENABLED
|
|
|
|
if (command.userType() != QMetaType::type("EndNanotraceCommand")) {
|
|
|
|
if (command.userType() == QMetaType::type("SyncNanotraceCommand")) {
|
|
|
|
SyncNanotraceCommand cmd = command.value<SyncNanotraceCommand>();
|
|
|
|
NANOTRACE_INSTANT_ARGS("Sync", "readCommand",
|
|
|
|
{"name", cmd.name().toStdString()},
|
2022-01-26 11:52:07 +01:00
|
|
|
{"counter", int64_t(readCommandCounter)});
|
2021-10-12 12:07:44 +02:00
|
|
|
// Do not dispatch this command.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NANOTRACE_INSTANT_ARGS("Update", "readCommand",
|
|
|
|
{"name", command.typeName()},
|
2022-01-26 11:52:07 +01:00
|
|
|
{"counter", int64_t(readCommandCounter)});
|
2021-10-12 12:07:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-04 17:06:31 +02:00
|
|
|
if (command.isValid())
|
|
|
|
commandList.append(command);
|
|
|
|
else
|
|
|
|
break;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2019-07-25 16:58:50 +02:00
|
|
|
for (const QVariant &command : qAsConst(commandList))
|
2012-09-19 15:57:22 +02:00
|
|
|
dispatchCommand(command);
|
|
|
|
}
|
|
|
|
|
2014-06-18 11:17:59 +02:00
|
|
|
void NodeInstanceClientProxy::sendPuppetAliveCommand()
|
|
|
|
{
|
|
|
|
puppetAlive(PuppetAliveCommand());
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const
|
|
|
|
{
|
2020-07-27 18:14:33 +02:00
|
|
|
return m_nodeInstanceServer.get();
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2020-07-27 18:14:33 +02:00
|
|
|
void NodeInstanceClientProxy::setNodeInstanceServer(
|
|
|
|
std::unique_ptr<NodeInstanceServerInterface> nodeInstanceServer)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2020-07-27 18:14:33 +02:00
|
|
|
m_nodeInstanceServer = std::move(nodeInstanceServer);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->createInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeFileUrl(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->createScene(command);
|
|
|
|
}
|
|
|
|
|
2019-12-11 21:29:10 +02:00
|
|
|
void NodeInstanceClientProxy::update3DViewState(const Update3dViewStateCommand &command)
|
2019-11-13 11:16:55 +01:00
|
|
|
{
|
2019-12-11 21:29:10 +02:00
|
|
|
nodeInstanceServer()->update3DViewState(command);
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->clearScene(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->removeInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->removeProperties(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changePropertyBindings(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changePropertyValues(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeAuxiliaryValues(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->reparentInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeIds(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeState(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->completeComponent(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeNodeSource(const ChangeNodeSourceCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeNodeSource(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::removeSharedMemory(const RemoveSharedMemoryCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->removeSharedMemory(command);
|
|
|
|
}
|
|
|
|
void NodeInstanceClientProxy::redirectToken(const TokenCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->token(command);
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:09:33 +02:00
|
|
|
void NodeInstanceClientProxy::redirectToken(const EndPuppetCommand & /*command*/)
|
2012-09-24 14:12:55 +02:00
|
|
|
{
|
2013-07-04 17:06:31 +02:00
|
|
|
if (m_outputIoDevice && m_outputIoDevice->isOpen())
|
|
|
|
m_outputIoDevice->close();
|
|
|
|
|
|
|
|
if (m_inputIoDevice && m_inputIoDevice->isOpen())
|
|
|
|
m_inputIoDevice->close();
|
|
|
|
|
|
|
|
if (m_controlStream.isOpen())
|
|
|
|
m_controlStream.close();
|
|
|
|
|
2012-09-24 14:12:55 +02:00
|
|
|
qDebug() << "End Process: " << QCoreApplication::applicationPid();
|
|
|
|
QCoreApplication::exit();
|
|
|
|
}
|
|
|
|
|
2019-10-17 13:51:57 +02:00
|
|
|
void NodeInstanceClientProxy::changeSelection(const ChangeSelectionCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeSelection(command);
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
|
|
|
|
{
|
2021-10-12 12:07:44 +02:00
|
|
|
NANOTRACE_SCOPE_ARGS("Update", "dispatchCommand", {"name", command.typeName()});
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand");
|
2019-12-11 21:29:10 +02:00
|
|
|
static const int update3dViewStateCommand = QMetaType::type("Update3dViewStateCommand");
|
2012-09-19 15:57:22 +02:00
|
|
|
static const int changeFileUrlCommandType = QMetaType::type("ChangeFileUrlCommand");
|
|
|
|
static const int createSceneCommandType = QMetaType::type("CreateSceneCommand");
|
|
|
|
static const int clearSceneCommandType = QMetaType::type("ClearSceneCommand");
|
|
|
|
static const int removeInstancesCommandType = QMetaType::type("RemoveInstancesCommand");
|
|
|
|
static const int removePropertiesCommandType = QMetaType::type("RemovePropertiesCommand");
|
|
|
|
static const int changeBindingsCommandType = QMetaType::type("ChangeBindingsCommand");
|
|
|
|
static const int changeValuesCommandType = QMetaType::type("ChangeValuesCommand");
|
|
|
|
static const int changeAuxiliaryCommandType = QMetaType::type("ChangeAuxiliaryCommand");
|
|
|
|
static const int reparentInstancesCommandType = QMetaType::type("ReparentInstancesCommand");
|
|
|
|
static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand");
|
|
|
|
static const int changeStateCommandType = QMetaType::type("ChangeStateCommand");
|
|
|
|
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
|
|
|
|
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
|
|
|
|
static const int changeNodeSourceCommandType = QMetaType::type("ChangeNodeSourceCommand");
|
|
|
|
static const int removeSharedMemoryCommandType = QMetaType::type("RemoveSharedMemoryCommand");
|
|
|
|
static const int tokenCommandType = QMetaType::type("TokenCommand");
|
2012-09-24 14:12:55 +02:00
|
|
|
static const int endPuppetCommandType = QMetaType::type("EndPuppetCommand");
|
2019-10-17 13:51:57 +02:00
|
|
|
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
|
2020-02-11 11:33:25 +02:00
|
|
|
static const int inputEventCommandType = QMetaType::type("InputEventCommand");
|
|
|
|
static const int view3DActionCommandType = QMetaType::type("View3DActionCommand");
|
2020-09-10 16:02:31 +03:00
|
|
|
static const int requestModelNodePreviewImageCommandType = QMetaType::type("RequestModelNodePreviewImageCommand");
|
2020-04-28 11:21:03 +02:00
|
|
|
static const int changeLanguageCommand = QMetaType::type("ChangeLanguageCommand");
|
2020-05-07 14:13:21 +02:00
|
|
|
static const int changePreviewImageSizeCommand = QMetaType::type(
|
|
|
|
"ChangePreviewImageSizeCommand");
|
2021-10-12 12:07:44 +02:00
|
|
|
static const int startNanotraceCommandType = QMetaType::type("StartNanotraceCommand");
|
|
|
|
static const int endNanotraceCommandType = QMetaType::type("EndNanotraceCommand");
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-09-10 17:24:15 +02:00
|
|
|
const int commandType = command.userType();
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
if (commandType == inputEventCommandType)
|
|
|
|
inputEvent(command.value<InputEventCommand>());
|
|
|
|
else if (commandType == createInstancesCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
createInstances(command.value<CreateInstancesCommand>());
|
2019-12-11 21:29:10 +02:00
|
|
|
else if (commandType == update3dViewStateCommand)
|
|
|
|
update3DViewState(command.value<Update3dViewStateCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeFileUrlCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changeFileUrl(command.value<ChangeFileUrlCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == createSceneCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
createScene(command.value<CreateSceneCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == clearSceneCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
clearScene(command.value<ClearSceneCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == removeInstancesCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
removeInstances(command.value<RemoveInstancesCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == removePropertiesCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
removeProperties(command.value<RemovePropertiesCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeBindingsCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changePropertyBindings(command.value<ChangeBindingsCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeValuesCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changePropertyValues(command.value<ChangeValuesCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeAuxiliaryCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changeAuxiliaryValues(command.value<ChangeAuxiliaryCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == reparentInstancesCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
reparentInstances(command.value<ReparentInstancesCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeIdsCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changeIds(command.value<ChangeIdsCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeStateCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changeState(command.value<ChangeStateCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == completeComponentCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
completeComponent(command.value<CompleteComponentCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == changeNodeSourceCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
changeNodeSource(command.value<ChangeNodeSourceCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == removeSharedMemoryCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
removeSharedMemory(command.value<RemoveSharedMemoryCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == tokenCommandType)
|
2012-09-19 15:57:22 +02:00
|
|
|
redirectToken(command.value<TokenCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == endPuppetCommandType)
|
2012-09-24 14:12:55 +02:00
|
|
|
redirectToken(command.value<EndPuppetCommand>());
|
2020-02-11 11:33:25 +02:00
|
|
|
else if (commandType == view3DActionCommandType)
|
|
|
|
view3DAction(command.value<View3DActionCommand>());
|
2020-09-10 16:02:31 +03:00
|
|
|
else if (commandType == requestModelNodePreviewImageCommandType)
|
|
|
|
requestModelNodePreviewImage(command.value<RequestModelNodePreviewImageCommand>());
|
2013-09-10 17:24:15 +02:00
|
|
|
else if (commandType == synchronizeCommandType) {
|
2012-09-19 15:57:22 +02:00
|
|
|
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
|
|
|
|
m_synchronizeId = synchronizeCommand.synchronizeId();
|
2019-10-17 13:51:57 +02:00
|
|
|
} else if (commandType == changeSelectionCommandType) {
|
|
|
|
ChangeSelectionCommand changeSelectionCommand = command.value<ChangeSelectionCommand>();
|
|
|
|
changeSelection(changeSelectionCommand);
|
2020-04-28 11:21:03 +02:00
|
|
|
} else if (command.userType() == changeLanguageCommand) {
|
|
|
|
changeLanguage(command.value<ChangeLanguageCommand>());
|
2020-05-07 14:13:21 +02:00
|
|
|
} else if (command.userType() == changePreviewImageSizeCommand) {
|
|
|
|
changePreviewImageSize(command.value<ChangePreviewImageSizeCommand>());
|
2021-10-12 12:07:44 +02:00
|
|
|
} else if (command.userType() == startNanotraceCommandType) {
|
|
|
|
startNanotrace(command.value<StartNanotraceCommand>());
|
|
|
|
} else if (command.userType() == endNanotraceCommandType) {
|
|
|
|
NANOTRACE_SHUTDOWN();
|
2013-07-17 00:01:45 +03:00
|
|
|
} else {
|
2012-09-19 15:57:22 +02:00
|
|
|
Q_ASSERT(false);
|
2013-07-17 00:01:45 +03:00
|
|
|
}
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
} // namespace QmlDesigner
|