Commit f40dbe19 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Extra process for state previews

Much faster.
parent ffc241b7
......@@ -38,10 +38,15 @@ namespace QmlDesigner {
NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
: QObject(parent),
m_nodeInstanceServer(new NodeInstanceServer(this)),
m_stateNodeInstancePreview(new PreviewNodeInstanceServer(this)),
m_nodeInstanceServer(0),
m_blockSize(0)
{
if (QCoreApplication::arguments().at(2) == QLatin1String("previewmode")) {
m_nodeInstanceServer = new PreviewNodeInstanceServer(this);
} else if (QCoreApplication::arguments().at(2) == QLatin1String("editormode")) {
m_nodeInstanceServer = new NodeInstanceServer(this);
}
m_socket = new QLocalSocket(this);
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream()));
connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
......@@ -132,11 +137,6 @@ void NodeInstanceClientProxy::readDataStream()
}
}
NodeInstanceServerInterface *NodeInstanceClientProxy::stateNodeInstancePreview() const
{
return m_stateNodeInstancePreview;
}
NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const
{
return m_nodeInstanceServer;
......@@ -145,61 +145,51 @@ NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const
void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command)
{
nodeInstanceServer()->createInstances(command);
stateNodeInstancePreview()->createInstances(command);
}
void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command)
{
nodeInstanceServer()->changeFileUrl(command);
stateNodeInstancePreview()->changeFileUrl(command);
}
void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command)
{
nodeInstanceServer()->createScene(command);
stateNodeInstancePreview()->createScene(command);
}
void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command)
{
nodeInstanceServer()->clearScene(command);
stateNodeInstancePreview()->clearScene(command);
}
void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command)
{
nodeInstanceServer()->removeInstances(command);
stateNodeInstancePreview()->removeInstances(command);
}
void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command)
{
nodeInstanceServer()->removeProperties(command);
stateNodeInstancePreview()->removeProperties(command);
}
void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command)
{
nodeInstanceServer()->changePropertyBindings(command);
stateNodeInstancePreview()->changePropertyBindings(command);
}
void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command)
{
nodeInstanceServer()->changePropertyValues(command);
stateNodeInstancePreview()->changePropertyValues(command);
}
void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command)
{
nodeInstanceServer()->reparentInstances(command);
stateNodeInstancePreview()->reparentInstances(command);
}
void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command)
{
nodeInstanceServer()->changeIds(command);
stateNodeInstancePreview()->changeIds(command);
}
void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command)
......@@ -210,13 +200,11 @@ void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command)
void NodeInstanceClientProxy::addImport(const AddImportCommand &command)
{
nodeInstanceServer()->addImport(command);
stateNodeInstancePreview()->addImport(command);
}
void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command)
{
nodeInstanceServer()->completeComponent(command);
stateNodeInstancePreview()->completeComponent(command);
}
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
......
......@@ -49,7 +49,6 @@ protected:
void writeCommand(const QVariant &command);
void dispatchCommand(const QVariant &command);
NodeInstanceServerInterface *nodeInstanceServer() const;
NodeInstanceServerInterface *stateNodeInstancePreview() const;
void createInstances(const CreateInstancesCommand &command);
void changeFileUrl(const ChangeFileUrlCommand &command);
......@@ -71,7 +70,6 @@ private slots:
private:
QLocalSocket *m_socket;
NodeInstanceServerInterface *m_nodeInstanceServer;
NodeInstanceServerInterface *m_stateNodeInstancePreview;
quint32 m_blockSize;
};
......
......@@ -41,38 +41,65 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
: NodeInstanceServerInterface(nodeInstanceView),
m_localServer(new QLocalServer(this)),
m_nodeInstanceView(nodeInstanceView),
m_blockSize(0)
m_firstBlockSize(0),
m_secondBlockSize(0)
{
QString socketToken(QUuid::createUuid().toString());
m_localServer->listen(socketToken);
m_localServer->setMaxPendingConnections(1);
m_localServer->setMaxPendingConnections(2);
m_qmlPuppetEditorProcess = new QProcess(QCoreApplication::instance());
connect(m_qmlPuppetEditorProcess.data(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
m_qmlPuppetEditorProcess->setProcessChannelMode(QProcess::ForwardedChannels);
m_qmlPuppetEditorProcess->start(QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg("qmlpuppet"), QStringList() << socketToken << "editormode" << "-graphicssystem raster");
m_qmlPuppetPreviewProcess = new QProcess(QCoreApplication::instance());
connect(m_qmlPuppetPreviewProcess.data(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
m_qmlPuppetPreviewProcess->setProcessChannelMode(QProcess::ForwardedChannels);
m_qmlPuppetPreviewProcess->start(QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg("qmlpuppet"), QStringList() << socketToken << "previewmode" << "-graphicssystem raster");
m_qmlPuppetProcess = new QProcess(QCoreApplication::instance());
connect(m_qmlPuppetProcess.data(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
m_qmlPuppetProcess->setProcessChannelMode(QProcess::ForwardedChannels);
m_qmlPuppetProcess->start(QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg("qmlpuppet"), QStringList() << socketToken << "-graphicssystem raster");
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(deleteLater()));
m_qmlPuppetProcess->waitForStarted();
Q_ASSERT(m_qmlPuppetProcess->state() == QProcess::Running);
m_qmlPuppetPreviewProcess->waitForStarted();
m_qmlPuppetEditorProcess->waitForStarted();
Q_ASSERT(m_qmlPuppetEditorProcess->state() == QProcess::Running);
Q_ASSERT(m_qmlPuppetPreviewProcess->state() == QProcess::Running);
if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1);
m_firstSocket = m_localServer->nextPendingConnection();
Q_ASSERT(m_firstSocket);
connect(m_firstSocket.data(), SIGNAL(readyRead()), this, SLOT(readFirstDataStream()));
if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1);
m_socket = m_localServer->nextPendingConnection();
Q_ASSERT(m_socket);
connect(m_socket.data(), SIGNAL(readyRead()), this, SLOT(readDataStream()));
m_secondSocket = m_localServer->nextPendingConnection();
Q_ASSERT(m_secondSocket);
connect(m_secondSocket.data(), SIGNAL(readyRead()), this, SLOT(readSecondDataStream()));
m_localServer->close();
}
NodeInstanceServerProxy::~NodeInstanceServerProxy()
{
if (m_socket)
m_socket->close();
if (m_firstSocket)
m_firstSocket->close();
if (m_secondSocket)
m_secondSocket->close();
if (m_qmlPuppetProcess) {
m_qmlPuppetProcess->blockSignals(true);
m_qmlPuppetProcess->kill();
if (m_qmlPuppetEditorProcess) {
m_qmlPuppetEditorProcess->blockSignals(true);
m_qmlPuppetEditorProcess->kill();
}
if (m_qmlPuppetPreviewProcess) {
m_qmlPuppetPreviewProcess->blockSignals(true);
m_qmlPuppetPreviewProcess->kill();
}
}
......@@ -106,9 +133,9 @@ NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const
return m_nodeInstanceView.data();
}
void NodeInstanceServerProxy::writeCommand(const QVariant &command)
static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket)
{
Q_ASSERT(m_socket.data());
Q_ASSERT(socket);
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
......@@ -117,36 +144,74 @@ void NodeInstanceServerProxy::writeCommand(const QVariant &command)
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
m_socket->write(block);
socket->write(block);
}
void NodeInstanceServerProxy::writeCommand(const QVariant &command)
{
writeCommandToSocket(command, m_firstSocket.data());
writeCommandToSocket(command, m_secondSocket.data());
}
void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitStatus /* exitStatus */)
{
m_socket->close();
m_firstSocket->close();
m_secondSocket->close();
emit processCrashed();
}
void NodeInstanceServerProxy::readDataStream()
void NodeInstanceServerProxy::readFirstDataStream()
{
QList<QVariant> commandList;
while (!m_firstSocket->atEnd()) {
if (m_firstSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_firstSocket.data());
if (m_firstBlockSize == 0) {
in >> m_firstBlockSize;
}
if (m_firstSocket->bytesAvailable() < m_firstBlockSize)
break;
QVariant command;
in >> command;
m_firstBlockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok);
commandList.append(command);
}
foreach (const QVariant &command, commandList) {
dispatchCommand(command);
}
}
void NodeInstanceServerProxy::readSecondDataStream()
{
QList<QVariant> commandList;
while (!m_socket->atEnd()) {
if (m_socket->bytesAvailable() < int(sizeof(quint32)))
while (!m_secondSocket->atEnd()) {
if (m_secondSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_socket.data());
QDataStream in(m_secondSocket.data());
if (m_blockSize == 0) {
in >> m_blockSize;
if (m_secondBlockSize == 0) {
in >> m_secondBlockSize;
}
if (m_socket->bytesAvailable() < m_blockSize)
if (m_secondSocket->bytesAvailable() < m_secondBlockSize)
break;
QVariant command;
in >> command;
m_blockSize = 0;
m_secondBlockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok);
......
......@@ -49,14 +49,18 @@ signals:
private slots:
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
void readDataStream();
void readFirstDataStream();
void readSecondDataStream();
private:
QWeakPointer<QLocalServer> m_localServer;
QWeakPointer<QLocalSocket> m_socket;
QWeakPointer<QLocalSocket> m_firstSocket;
QWeakPointer<QLocalSocket> m_secondSocket;
QWeakPointer<NodeInstanceView> m_nodeInstanceView;
QWeakPointer<QProcess> m_qmlPuppetProcess;
quint32 m_blockSize;
QWeakPointer<QProcess> m_qmlPuppetEditorProcess;
QWeakPointer<QProcess> m_qmlPuppetPreviewProcess;
quint32 m_firstBlockSize;
quint32 m_secondBlockSize;
};
} // namespace QmlDesigner
......
......@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
{
QApplication application(argc, argv);
if (application.arguments().count() != 3)
if (application.arguments().count() != 4)
return -1;
QCoreApplication::setOrganizationName("Nokia");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment