QmlDesigner.NodeInstances: Track lost commands

This commit is contained in:
Marco Bubke
2011-04-19 17:13:08 +02:00
parent a0f990ca80
commit fcd6f6c8c6
4 changed files with 56 additions and 6 deletions

View File

@@ -74,6 +74,8 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
: QObject(parent), : QObject(parent),
m_nodeInstanceServer(0), m_nodeInstanceServer(0),
m_blockSize(0), m_blockSize(0),
m_writeCommandCounter(0),
m_lastReadCommandCounter(0),
m_synchronizeId(-1) m_synchronizeId(-1)
{ {
if (QCoreApplication::arguments().at(2) == QLatin1String("previewmode")) { if (QCoreApplication::arguments().at(2) == QLatin1String("previewmode")) {
@@ -94,9 +96,12 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
void NodeInstanceClientProxy::writeCommand(const QVariant &command) void NodeInstanceClientProxy::writeCommand(const QVariant &command)
{ {
static unsigned int commandCounter = 0;
QByteArray block; QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly); QDataStream out(&block, QIODevice::WriteOnly);
out << quint32(0); out << quint32(0);
out << quint32(m_writeCommandCounter);
m_writeCommandCounter++;
out << command; out << command;
out.device()->seek(0); out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32)); out << quint32(block.size() - sizeof(quint32));
@@ -168,6 +173,13 @@ void NodeInstanceClientProxy::readDataStream()
if (m_socket->bytesAvailable() < m_blockSize) if (m_socket->bytesAvailable() < m_blockSize)
break; break;
quint32 commandCounter;
in >> commandCounter;
bool commandLost = !((m_lastReadCommandCounter == 0 && commandCounter == 0) || (m_lastReadCommandCounter + 1 == commandCounter));
if (commandLost)
qDebug() << "client command lost: " << m_lastReadCommandCounter << commandCounter;
m_lastReadCommandCounter = commandCounter;
QVariant command; QVariant command;
in >> command; in >> command;
m_blockSize = 0; m_blockSize = 0;

View File

@@ -104,6 +104,8 @@ private:
QLocalSocket *m_socket; QLocalSocket *m_socket;
NodeInstanceServerInterface *m_nodeInstanceServer; NodeInstanceServerInterface *m_nodeInstanceServer;
quint32 m_blockSize; quint32 m_blockSize;
quint32 m_writeCommandCounter;
quint32 m_lastReadCommandCounter;
int m_synchronizeId; int m_synchronizeId;
}; };

View File

@@ -78,6 +78,10 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
m_firstBlockSize(0), m_firstBlockSize(0),
m_secondBlockSize(0), m_secondBlockSize(0),
m_thirdBlockSize(0), m_thirdBlockSize(0),
m_writeCommandCounter(0),
m_firstLastReadCommandCounter(0),
m_secondLastReadCommandCounter(0),
m_thirdLastReadCommandCounter(0),
m_runModus(runModus), m_runModus(runModus),
m_synchronizeId(-1) m_synchronizeId(-1)
{ {
@@ -220,12 +224,13 @@ NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const
return m_nodeInstanceView.data(); return m_nodeInstanceView.data();
} }
static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket) static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket, unsigned int commandCounter)
{ {
if(socket) { if(socket) {
QByteArray block; QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly); QDataStream out(&block, QIODevice::WriteOnly);
out << quint32(0); out << quint32(0);
out << quint32(commandCounter);
out << command; out << command;
out.device()->seek(0); out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32)); out << quint32(block.size() - sizeof(quint32));
@@ -236,16 +241,17 @@ static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket)
void NodeInstanceServerProxy::writeCommand(const QVariant &command) void NodeInstanceServerProxy::writeCommand(const QVariant &command)
{ {
writeCommandToSocket(command, m_firstSocket.data()); writeCommandToSocket(command, m_firstSocket.data(), m_writeCommandCounter);
writeCommandToSocket(command, m_secondSocket.data()); writeCommandToSocket(command, m_secondSocket.data(), m_writeCommandCounter);
writeCommandToSocket(command, m_thirdSocket.data()); writeCommandToSocket(command, m_thirdSocket.data(), m_writeCommandCounter);
m_writeCommandCounter++;
if (m_runModus == TestModus) { if (m_runModus == TestModus) {
static int synchronizeId = 0; static int synchronizeId = 0;
synchronizeId++; synchronizeId++;
SynchronizeCommand synchronizeCommand(synchronizeId); SynchronizeCommand synchronizeCommand(synchronizeId);
writeCommandToSocket(QVariant::fromValue(synchronizeCommand), m_firstSocket.data()); writeCommandToSocket(QVariant::fromValue(synchronizeCommand), m_firstSocket.data(), m_writeCommandCounter);
m_writeCommandCounter++;
while(m_firstSocket->waitForReadyRead()) { while(m_firstSocket->waitForReadyRead()) {
readFirstDataStream(); readFirstDataStream();
@@ -271,6 +277,7 @@ void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitSt
void NodeInstanceServerProxy::readFirstDataStream() void NodeInstanceServerProxy::readFirstDataStream()
{ {
static unsigned int lastCommandCounter = 0;
QList<QVariant> commandList; QList<QVariant> commandList;
while (!m_firstSocket->atEnd()) { while (!m_firstSocket->atEnd()) {
@@ -286,6 +293,14 @@ void NodeInstanceServerProxy::readFirstDataStream()
if (m_firstSocket->bytesAvailable() < m_firstBlockSize) if (m_firstSocket->bytesAvailable() < m_firstBlockSize)
break; break;
quint32 commandCounter;
in >> commandCounter;
bool commandLost = !((m_firstLastReadCommandCounter == 0 && commandCounter == 0) || (m_firstLastReadCommandCounter + 1 == commandCounter));
if (commandLost)
qDebug() << "server command lost: " << m_firstLastReadCommandCounter << commandCounter;
m_firstLastReadCommandCounter = commandCounter;
QVariant command; QVariant command;
in >> command; in >> command;
m_firstBlockSize = 0; m_firstBlockSize = 0;
@@ -300,6 +315,7 @@ void NodeInstanceServerProxy::readFirstDataStream()
void NodeInstanceServerProxy::readSecondDataStream() void NodeInstanceServerProxy::readSecondDataStream()
{ {
static unsigned int lastCommandCounter = 0;
QList<QVariant> commandList; QList<QVariant> commandList;
while (!m_secondSocket->atEnd()) { while (!m_secondSocket->atEnd()) {
@@ -315,6 +331,14 @@ void NodeInstanceServerProxy::readSecondDataStream()
if (m_secondSocket->bytesAvailable() < m_secondBlockSize) if (m_secondSocket->bytesAvailable() < m_secondBlockSize)
break; break;
quint32 commandCounter;
in >> commandCounter;
bool commandLost = !((m_secondLastReadCommandCounter == 0 && commandCounter == 0) || (m_secondLastReadCommandCounter + 1 == commandCounter));
if (commandLost)
qDebug() << "server command lost: " << m_secondLastReadCommandCounter << commandCounter;
m_secondLastReadCommandCounter = commandCounter;
QVariant command; QVariant command;
in >> command; in >> command;
m_secondBlockSize = 0; m_secondBlockSize = 0;
@@ -344,6 +368,14 @@ void NodeInstanceServerProxy::readThirdDataStream()
if (m_thirdSocket->bytesAvailable() < m_thirdBlockSize) if (m_thirdSocket->bytesAvailable() < m_thirdBlockSize)
break; break;
quint32 commandCounter;
in >> commandCounter;
bool commandLost = !((m_thirdLastReadCommandCounter == 0 && commandCounter == 0) || (m_thirdLastReadCommandCounter + 1 == commandCounter));
if (commandLost)
qDebug() << "server command lost: " << m_thirdLastReadCommandCounter << commandCounter;
m_thirdLastReadCommandCounter = commandCounter;
QVariant command; QVariant command;
in >> command; in >> command;
m_thirdBlockSize = 0; m_thirdBlockSize = 0;

View File

@@ -97,6 +97,10 @@ private:
quint32 m_firstBlockSize; quint32 m_firstBlockSize;
quint32 m_secondBlockSize; quint32 m_secondBlockSize;
quint32 m_thirdBlockSize; quint32 m_thirdBlockSize;
quint32 m_writeCommandCounter;
quint32 m_firstLastReadCommandCounter;
quint32 m_secondLastReadCommandCounter;
quint32 m_thirdLastReadCommandCounter;
RunModus m_runModus; RunModus m_runModus;
int m_synchronizeId; int m_synchronizeId;
}; };