| 
									
										
										
										
											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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "propertyabstractcontainer.h"
 | 
					
						
							|  |  |  | #include "propertyvaluecontainer.h"
 | 
					
						
							|  |  |  | #include "propertybindingcontainer.h"
 | 
					
						
							|  |  |  | #include "instancecontainer.h"
 | 
					
						
							|  |  |  | #include "createinstancescommand.h"
 | 
					
						
							|  |  |  | #include "createscenecommand.h"
 | 
					
						
							|  |  |  | #include "changevaluescommand.h"
 | 
					
						
							|  |  |  | #include "changebindingscommand.h"
 | 
					
						
							|  |  |  | #include "changeauxiliarycommand.h"
 | 
					
						
							|  |  |  | #include "changefileurlcommand.h"
 | 
					
						
							|  |  |  | #include "removeinstancescommand.h"
 | 
					
						
							|  |  |  | #include "clearscenecommand.h"
 | 
					
						
							|  |  |  | #include "removepropertiescommand.h"
 | 
					
						
							|  |  |  | #include "reparentinstancescommand.h"
 | 
					
						
							|  |  |  | #include "changeidscommand.h"
 | 
					
						
							|  |  |  | #include "changestatecommand.h"
 | 
					
						
							|  |  |  | #include "completecomponentcommand.h"
 | 
					
						
							|  |  |  | #include "synchronizecommand.h"
 | 
					
						
							|  |  |  | #include "removesharedmemorycommand.h"
 | 
					
						
							|  |  |  | #include "tokencommand.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "informationchangedcommand.h"
 | 
					
						
							|  |  |  | #include "pixmapchangedcommand.h"
 | 
					
						
							|  |  |  | #include "valueschangedcommand.h"
 | 
					
						
							|  |  |  | #include "childrenchangedcommand.h"
 | 
					
						
							|  |  |  | #include "imagecontainer.h"
 | 
					
						
							|  |  |  | #include "statepreviewimagechangedcommand.h"
 | 
					
						
							|  |  |  | #include "componentcompletedcommand.h"
 | 
					
						
							|  |  |  | #include "changenodesourcecommand.h"
 | 
					
						
							| 
									
										
										
										
											2012-09-24 14:12:55 +02:00
										 |  |  | #include "endpuppetcommand.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-05 16:42:31 +01:00
										 |  |  | #include "debugoutputcommand.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-18 11:17:59 +02:00
										 |  |  | #include "puppetalivecommand.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-17 13:51:57 +02:00
										 |  |  | #include "changeselectioncommand.h"
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent) | 
					
						
							|  |  |  |     : QObject(parent), | 
					
						
							| 
									
										
										
										
											2019-07-31 17:21:41 +02:00
										 |  |  |       m_inputIoDevice(nullptr), | 
					
						
							|  |  |  |       m_outputIoDevice(nullptr), | 
					
						
							|  |  |  |       m_nodeInstanceServer(nullptr), | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |       m_writeCommandCounter(0), | 
					
						
							|  |  |  |       m_synchronizeId(-1) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-19 14:33:31 +01:00
										 |  |  |     connect(&m_puppetAliveTimer, &QTimer::timeout, this, &NodeInstanceClientProxy::sendPuppetAliveCommand); | 
					
						
							| 
									
										
										
										
											2017-03-01 15:06:33 +01:00
										 |  |  |     m_puppetAliveTimer.setInterval(1000); | 
					
						
							| 
									
										
										
										
											2014-06-18 11:17:59 +02:00
										 |  |  |     m_puppetAliveTimer.start(); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2019-02-26 09:40:49 +01:00
										 |  |  |     connect(localSocket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error), | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							|  |  |  |     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>(); | 
					
						
							| 
									
										
										
										
											2013-07-16 17:00:07 +02:00
										 |  |  |          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) | 
					
						
							|  |  |  |             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) { | 
					
						
							|  |  |  |         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)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         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 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_nodeInstanceServer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NodeInstanceClientProxy::setNodeInstanceServer(NodeInstanceServerInterface *nodeInstanceServer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_nodeInstanceServer = nodeInstanceServer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand"); | 
					
						
							|  |  |  |     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"); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 17:24:15 +02:00
										 |  |  |     const int commandType = command.userType(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (commandType == createInstancesCommandType) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         createInstances(command.value<CreateInstancesCommand>()); | 
					
						
							| 
									
										
										
										
											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>()); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											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
 |