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