2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-07-27 18:14:33 +02:00
|
|
|
|
|
|
|
|
#include "testconnectionmanager.h"
|
|
|
|
|
#include "synchronizecommand.h"
|
|
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
2022-09-15 11:33:28 +02:00
|
|
|
#include <QVariant>
|
2020-07-27 18:14:33 +02:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
TestConnectionManager::TestConnectionManager()
|
|
|
|
|
{
|
2020-10-20 07:38:54 +02:00
|
|
|
connections().emplace_back("Editor", "editormode");
|
2020-07-27 18:14:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConnectionManager::writeCommand(const QVariant &command)
|
|
|
|
|
{
|
2020-10-20 07:38:54 +02:00
|
|
|
ConnectionManager::writeCommand(command);
|
2020-07-27 18:14:33 +02:00
|
|
|
|
2020-10-20 07:38:54 +02:00
|
|
|
writeCommandCounter()++;
|
2020-07-27 18:14:33 +02:00
|
|
|
|
|
|
|
|
static int synchronizeId = 0;
|
|
|
|
|
synchronizeId++;
|
|
|
|
|
SynchronizeCommand synchronizeCommand(synchronizeId);
|
|
|
|
|
|
2020-10-20 07:38:54 +02:00
|
|
|
QLocalSocket *socket = connections().front().socket.get();
|
2020-07-27 18:14:33 +02:00
|
|
|
|
2020-10-20 07:38:54 +02:00
|
|
|
writeCommandToIODevice(QVariant::fromValue(synchronizeCommand), socket, writeCommandCounter());
|
|
|
|
|
writeCommandCounter()++;
|
2020-07-27 18:14:33 +02:00
|
|
|
|
|
|
|
|
while (socket->waitForReadyRead(100)) {
|
2020-10-20 07:38:54 +02:00
|
|
|
readDataStream(connections().front());
|
2020-07-27 18:14:33 +02:00
|
|
|
if (m_synchronizeId == synchronizeId)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConnectionManager::dispatchCommand(const QVariant &command, Connection &connection)
|
|
|
|
|
{
|
2024-05-23 17:13:58 +02:00
|
|
|
static const int synchronizeCommandType = QMetaType::fromName("SynchronizeCommand").id();
|
2020-07-27 18:14:33 +02:00
|
|
|
|
2023-06-07 13:03:11 +02:00
|
|
|
if (command.typeId() == synchronizeCommandType) {
|
2020-07-27 18:14:33 +02:00
|
|
|
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
|
|
|
|
|
m_synchronizeId = synchronizeCommand.synchronizeId();
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManager::dispatchCommand(command, connection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|