Commit 62d66fcd authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Remove slow socket

The two socket approach don't worked under windows and mac.
parent 8b86085a
...@@ -42,19 +42,15 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent) ...@@ -42,19 +42,15 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
m_baseStateNodeInstancePreview(new PreviewNodeInstanceServer(this)), m_baseStateNodeInstancePreview(new PreviewNodeInstanceServer(this)),
m_blockSize(0) m_blockSize(0)
{ {
m_slowSocket = new QLocalSocket(this); m_socket = new QLocalSocket(this);
m_slowSocket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered); connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream()));
m_slowSocket->waitForConnected(-1); connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
connect(m_socket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
m_fastSocket = new QLocalSocket(this); m_socket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
connect(m_fastSocket, SIGNAL(readyRead()), this, SLOT(readDataStream())); m_socket->waitForConnected(-1);
connect(m_fastSocket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
connect(m_fastSocket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
m_fastSocket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
m_fastSocket->waitForConnected(-1);
} }
void NodeInstanceClientProxy::writeSlowCommand(const QVariant &command) void NodeInstanceClientProxy::writeCommand(const QVariant &command)
{ {
QByteArray block; QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly); QDataStream out(&block, QIODevice::WriteOnly);
...@@ -63,49 +59,37 @@ void NodeInstanceClientProxy::writeSlowCommand(const QVariant &command) ...@@ -63,49 +59,37 @@ void NodeInstanceClientProxy::writeSlowCommand(const QVariant &command)
out.device()->seek(0); out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32)); out << quint32(block.size() - sizeof(quint32));
m_slowSocket->write(block); m_socket->write(block);
}
void NodeInstanceClientProxy::writeFastCommand(const QVariant &command)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << quint32(0);
out << command;
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
m_fastSocket->write(block);
} }
void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command) void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command)
{ {
writeFastCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command) void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command)
{ {
writeFastCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command) void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command)
{ {
writeSlowCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command) void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command)
{ {
writeFastCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
{ {
writeSlowCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command) void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command)
{ {
writeFastCommand(QVariant::fromValue(command)); writeCommand(QVariant::fromValue(command));
} }
void NodeInstanceClientProxy::flush() void NodeInstanceClientProxy::flush()
...@@ -114,24 +98,24 @@ void NodeInstanceClientProxy::flush() ...@@ -114,24 +98,24 @@ void NodeInstanceClientProxy::flush()
qint64 NodeInstanceClientProxy::bytesToWrite() const qint64 NodeInstanceClientProxy::bytesToWrite() const
{ {
return m_slowSocket->bytesToWrite(); return m_socket->bytesToWrite();
} }
void NodeInstanceClientProxy::readDataStream() void NodeInstanceClientProxy::readDataStream()
{ {
QList<QVariant> commandList; QList<QVariant> commandList;
while (!m_fastSocket->atEnd()) { while (!m_socket->atEnd()) {
if (m_fastSocket->bytesAvailable() < int(sizeof(quint32))) if (m_socket->bytesAvailable() < int(sizeof(quint32)))
break; break;
QDataStream in(m_fastSocket); QDataStream in(m_socket);
if (m_blockSize == 0) { if (m_blockSize == 0) {
in >> m_blockSize; in >> m_blockSize;
} }
if (m_fastSocket->bytesAvailable() < m_blockSize) if (m_socket->bytesAvailable() < m_blockSize)
break; break;
QVariant command; QVariant command;
......
...@@ -46,10 +46,10 @@ public: ...@@ -46,10 +46,10 @@ public:
qint64 bytesToWrite() const; qint64 bytesToWrite() const;
protected: protected:
void writeSlowCommand(const QVariant &command); void writeCommand(const QVariant &command);
void writeFastCommand(const QVariant &command);
void dispatchCommand(const QVariant &command); void dispatchCommand(const QVariant &command);
NodeInstanceServerInterface *nodeInstanceServer() const; NodeInstanceServerInterface *nodeInstanceServer() const;
NodeInstanceServerInterface *baseStateNodeInstancePreview() const;
void createInstances(const CreateInstancesCommand &command); void createInstances(const CreateInstancesCommand &command);
void changeFileUrl(const ChangeFileUrlCommand &command); void changeFileUrl(const ChangeFileUrlCommand &command);
...@@ -69,8 +69,7 @@ private slots: ...@@ -69,8 +69,7 @@ private slots:
void readDataStream(); void readDataStream();
private: private:
QLocalSocket *m_slowSocket; QLocalSocket *m_socket;
QLocalSocket *m_fastSocket;
NodeInstanceServerInterface *m_nodeInstanceServer; NodeInstanceServerInterface *m_nodeInstanceServer;
NodeInstanceServerInterface *m_baseStateNodeInstancePreview; NodeInstanceServerInterface *m_baseStateNodeInstancePreview;
QHash<qint32, QWeakPointer<NodeInstanceServerInterface> > m_nodeInstancePreviewVector; QHash<qint32, QWeakPointer<NodeInstanceServerInterface> > m_nodeInstancePreviewVector;
......
...@@ -41,8 +41,7 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV ...@@ -41,8 +41,7 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
: NodeInstanceServerInterface(nodeInstanceView), : NodeInstanceServerInterface(nodeInstanceView),
m_localServer(new QLocalServer(this)), m_localServer(new QLocalServer(this)),
m_nodeInstanceView(nodeInstanceView), m_nodeInstanceView(nodeInstanceView),
m_slowBlockSize(0), m_blockSize(0)
m_fastBlockSize(0)
{ {
QString socketToken(QUuid::createUuid().toString()); QString socketToken(QUuid::createUuid().toString());
...@@ -60,16 +59,9 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV ...@@ -60,16 +59,9 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
if (!m_localServer->hasPendingConnections()) if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1); m_localServer->waitForNewConnection(-1);
m_slowSocket = m_localServer->nextPendingConnection(); m_socket = m_localServer->nextPendingConnection();
Q_ASSERT(m_slowSocket); Q_ASSERT(m_socket);
connect(m_slowSocket.data(), SIGNAL(readyRead()), this, SLOT(readSlowDataStream())); connect(m_socket.data(), SIGNAL(readyRead()), this, SLOT(readDataStream()));
if (!m_localServer->hasPendingConnections())
m_localServer->waitForNewConnection(-1);
m_fastSocket = m_localServer->nextPendingConnection();
Q_ASSERT(m_fastSocket);
connect(m_fastSocket.data(), SIGNAL(readyRead()), this, SLOT(readFastDataStream()));
m_localServer->close(); m_localServer->close();
} }
...@@ -113,12 +105,12 @@ NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const ...@@ -113,12 +105,12 @@ NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const
void NodeInstanceServerProxy::setBlockUpdates(bool block) void NodeInstanceServerProxy::setBlockUpdates(bool block)
{ {
m_slowSocket->blockSignals(block); m_socket->blockSignals(block);
} }
void NodeInstanceServerProxy::writeCommand(const QVariant &command) void NodeInstanceServerProxy::writeCommand(const QVariant &command)
{ {
Q_ASSERT(m_fastSocket.data()); Q_ASSERT(m_socket.data());
QByteArray block; QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly); QDataStream out(&block, QIODevice::WriteOnly);
...@@ -127,67 +119,36 @@ void NodeInstanceServerProxy::writeCommand(const QVariant &command) ...@@ -127,67 +119,36 @@ void NodeInstanceServerProxy::writeCommand(const QVariant &command)
out.device()->seek(0); out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32)); out << quint32(block.size() - sizeof(quint32));
m_fastSocket->write(block); m_socket->write(block);
} }
void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitStatus /* exitStatus */) void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitStatus /* exitStatus */)
{ {
m_slowSocket->close(); m_socket->close();
emit processCrashed(); emit processCrashed();
} }
void NodeInstanceServerProxy::readFastDataStream() void NodeInstanceServerProxy::readDataStream()
{
QList<QVariant> commandList;
while (!m_fastSocket->atEnd()) {
if (m_fastSocket->bytesAvailable() < int(sizeof(quint32)))
break;
QDataStream in(m_fastSocket.data());
if (m_fastBlockSize == 0) {
in >> m_fastBlockSize;
}
if (m_fastSocket->bytesAvailable() < m_fastBlockSize)
break;
QVariant command;
in >> command;
m_fastBlockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok);
commandList.append(command);
}
foreach (const QVariant &command, commandList) {
dispatchCommand(command);
}
}
void NodeInstanceServerProxy::readSlowDataStream()
{ {
QList<QVariant> commandList; QList<QVariant> commandList;
while (!m_slowSocket->atEnd()) { while (!m_socket->atEnd()) {
if (m_slowSocket->bytesAvailable() < int(sizeof(quint32))) if (m_socket->bytesAvailable() < int(sizeof(quint32)))
break; break;
QDataStream in(m_slowSocket.data()); QDataStream in(m_socket.data());
if (m_slowBlockSize == 0) { if (m_blockSize == 0) {
in >> m_slowBlockSize; in >> m_blockSize;
} }
if (m_slowSocket->bytesAvailable() < m_slowBlockSize) if (m_socket->bytesAvailable() < m_blockSize)
break; break;
QVariant command; QVariant command;
in >> command; in >> command;
m_slowBlockSize = 0; m_blockSize = 0;
Q_ASSERT(in.status() == QDataStream::Ok); Q_ASSERT(in.status() == QDataStream::Ok);
......
...@@ -51,17 +51,14 @@ signals: ...@@ -51,17 +51,14 @@ signals:
private slots: private slots:
void processFinished(int exitCode, QProcess::ExitStatus exitStatus); void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
void readFastDataStream(); void readDataStream();
void readSlowDataStream();
private: private:
QWeakPointer<QLocalServer> m_localServer; QWeakPointer<QLocalServer> m_localServer;
QWeakPointer<QLocalSocket> m_slowSocket; QWeakPointer<QLocalSocket> m_socket;
QWeakPointer<QLocalSocket> m_fastSocket;
QWeakPointer<NodeInstanceView> m_nodeInstanceView; QWeakPointer<NodeInstanceView> m_nodeInstanceView;
QWeakPointer<QProcess> m_qmlPuppetProcess; QWeakPointer<QProcess> m_qmlPuppetProcess;
quint32 m_slowBlockSize; quint32 m_blockSize;
quint32 m_fastBlockSize;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner
......
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