7#include <private/qpacketprotocol_p.h>
8#include <private/qpacket_p.h>
9#include <private/qobject_p.h>
11#include <QtCore/qeventloop.h>
12#include <QtCore/qtimer.h>
13#include <QtCore/QHash>
14#include <QtCore/qdatastream.h>
15#include <QtNetwork/qlocalserver.h>
16#include <QtNetwork/qlocalsocket.h>
17#include <QtNetwork/qtcpsocket.h>
58 if (!
q->isConnected())
67void QQmlDebugConnection::socketConnected()
70 QPacket pack(
d->currentDataStreamVersion);
73 d->protocol->send(pack.data());
77void QQmlDebugConnection::socketDisconnected()
84void QQmlDebugConnection::protocolReadyRead()
88 QPacket pack(
d->currentDataStreamVersion,
d->protocol->read());
93 bool validHello =
false;
105 pack >> pluginVersions;
107 const int pluginNamesSize = pluginNames.size();
108 const int pluginVersionsSize = pluginVersions.size();
109 for (
int i = 0;
i < pluginNamesSize; ++
i) {
110 float pluginVersion = 1.0;
111 if (
i < pluginVersionsSize)
112 pluginVersion = pluginVersions.at(
i);
113 d->serverPlugins.insert(pluginNames.at(
i), pluginVersion);
116 pack >>
d->currentDataStreamVersion;
123 qWarning(
"QQmlDebugConnection: Invalid hello message");
131 for (;
iter !=
d->plugins.end(); ++
iter) {
133 if (
d->serverPlugins.contains(
iter.key()))
138 d->handshakeTimer.stop();
139 d->handshakeEventLoop.quit();
142 while (
d->protocol->packetsAvailable()) {
143 QPacket pack(
d->currentDataStreamVersion,
d->protocol->read());
154 d->serverPlugins.clear();
160 pack >> pluginVersions;
162 const int pluginNamesSize = pluginNames.size();
163 const int pluginVersionsSize = pluginVersions.size();
164 for (
int i = 0;
i < pluginNamesSize; ++
i) {
165 float pluginVersion = 1.0;
166 if (
i < pluginVersionsSize)
167 pluginVersion = pluginVersions.at(
i);
168 d->serverPlugins.insert(pluginNames.at(
i), pluginVersion);
172 for (;
iter !=
d->plugins.end(); ++
iter) {
175 if (
d->serverPlugins.contains(pluginName))
178 if (oldServerPlugins.
contains(pluginName)
179 !=
d->serverPlugins.contains(pluginName)) {
184 qWarning() <<
"QQmlDebugConnection: Unknown control message id" << op;
188 if (
iter ==
d->plugins.end()) {
191 if (!
d->removedPlugins.contains(
name)) {
192 qWarning() <<
"QQmlDebugConnection: Message received for missing plugin"
198 while (!pack.atEnd()) {
207void QQmlDebugConnection::handshakeTimeout()
211 qWarning() <<
"QQmlDebugConnection: Did not get handshake answer in time";
212 d->handshakeEventLoop.quit();
234 return d->currentDataStreamVersion;
240 d->maximumDataStreamVersion = maximumVersion;
252 return !
d->gotHello &&
d->device;
268 d->device->deleteLater();
276 auto socket = qobject_cast<QAbstractSocket*>(
d->device);
278 if (!
d->server || (!
d->server->hasPendingConnections() &&
279 !
d->server->waitForNewConnection(msecs)))
285 d->handshakeTimer.start();
286 d->handshakeEventLoop.exec();
293 return d->plugins.value(
name,
nullptr);
299 if (
d->plugins.contains(
name))
301 d->removedPlugins.removeAll(
name);
303 d->advertisePlugins();
310 if (!
d->plugins.contains(
name))
312 d->plugins.remove(
name);
313 d->removedPlugins.append(
name);
314 d->advertisePlugins();
321 return d->serverPlugins.value(serviceName, -1);
330 QPacket pack(
d->currentDataStreamVersion);
332 d->protocol->send(pack.
data());
340 if (
auto socket = qobject_cast<QAbstractSocket *>(
device))
342 else if (
auto socket = qobject_cast<QLocalSocket *>(
device))
368 d->server->deleteLater();
402void QQmlDebugConnection::newConnection()
426 q, &QQmlDebugConnection::protocolReadyRead);
431#include <qqmldebugconnection.moc>
433#include "moc_qqmldebugconnection_p.cpp"
void socketStateChanged(QAbstractSocket::SocketState)
LocalSocketSignalTranslator(QLocalSocket *parent)
void onError(QLocalSocket::LocalSocketError error)
void onStateChanged(QLocalSocket::LocalSocketState state)
void socketError(QAbstractSocket::SocketError)
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
bool flush()
This function writes as much as possible from the internal write buffer to the underlying network soc...
void stateChanged(QAbstractSocket::SocketState)
This signal is emitted whenever QAbstractSocket's state changes.
void errorOccurred(QAbstractSocket::SocketError)
void connected()
This signal is emitted after connectToHost() has been called and a connection has been successfully e...
virtual bool waitForConnected(int msecs=30000)
Waits until the socket is connected, up to msecs milliseconds.
SocketError
This enum describes the socket errors that can occur.
virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
Attempts to make a connection to hostName on the given port.
void disconnected()
This signal is emitted when the socket has been disconnected.
@ Qt_DefaultCompiledVersion
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
\inmodule QtCore \reentrant
The QLocalServer class provides a local socket based server.
void newConnection()
This signal is emitted every time a new connection is available.
The QLocalSocket class provides a local socket.
void disconnected()
This signal is emitted when the socket has been disconnected.
LocalSocketState
This enum describes the different states in which a socket can be.
void stateChanged(QLocalSocket::LocalSocketState socketState)
This signal is emitted whenever QLocalSocket's state changes.
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
void errorOccurred(QLocalSocket::LocalSocketError socketError)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QPacketProtocol class encapsulates communicating discrete packets across fragmented IO channels,...
void send(const QByteArray &data)
Transmit the packet.
void readyRead()
Emitted whenever a new packet is received.
The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol.
const QByteArray & data() const
Returns a reference to the raw packet data.
virtual void messageReceived(const QByteArray &message)
QEventLoop handshakeEventLoop
QPacketProtocol * protocol
int maximumDataStreamVersion
QHash< QString, float > serverPlugins
QStringList removedPlugins
QHash< QString, QQmlDebugClient * > plugins
int currentDataStreamVersion
QQmlDebugConnectionPrivate()
bool isConnecting() const
QQmlDebugConnection(QObject *parent=nullptr)
bool addClient(const QString &name, QQmlDebugClient *client)
void socketError(QAbstractSocket::SocketError socketError)
void setMaximumDataStreamVersion(int maximumVersion)
bool sendMessage(const QString &name, const QByteArray &message)
bool removeClient(const QString &name)
QQmlDebugClient * client(const QString &name) const
float serviceVersion(const QString &serviceName) const
void socketStateChanged(QAbstractSocket::SocketState socketState)
int currentDataStreamVersion() const
bool waitForConnected(int msecs=30000)
void startLocalServer(const QString &fileName)
void connectToHost(const QString &hostName, quint16 port)
\macro QT_RESTRICTED_CAST_FROM_ASCII
The QTcpSocket class provides a TCP socket.
void setSingleShot(bool singleShot)
void setInterval(int msec)
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
DBusConnection const char DBusError * error
GLuint GLsizei const GLchar * message
GLdouble GLdouble GLdouble GLdouble q
static const QString serverId
static QT_BEGIN_NAMESPACE const int protocolVersion
static const QString clientId
QT_BEGIN_NAMESPACE const int protocolVersion
QLatin1StringView QLatin1String
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent