Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocalclientconnection.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <private/qqmldebugserverconnection_p.h>
5
6#include <QtCore/qplugin.h>
7#include <QtNetwork/qlocalsocket.h>
8#include <private/qqmldebugserver_p.h>
9
11
13
14
16{
18 Q_DISABLE_COPY(QLocalClientConnection)
19
20public:
22 ~QLocalClientConnection() override;
23
24 void setServer(QQmlDebugServer *server) override;
25 bool setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress) override;
26 bool setFileName(const QString &filename, bool block) override;
27
28 bool isConnected() const override;
29 void disconnect() override;
30
31 void waitForConnection() override;
32 void flush() override;
33
34private:
35 void connectionEstablished();
36 bool connectToServer();
37
38 bool m_block = false;
39 QString m_filename;
40 QLocalSocket *m_socket = nullptr;
41 QQmlDebugServer *m_debugServer = nullptr;
42};
43
45
51
56
58{
59 return m_socket && m_socket->state() == QLocalSocket::ConnectedState;
60}
61
63{
64 while (m_socket && m_socket->bytesToWrite() > 0)
65 m_socket->waitForBytesWritten();
66
67 m_socket->deleteLater();
68 m_socket = nullptr;
69}
70
71bool QLocalClientConnection::setPortRange(int portFrom, int portTo, bool block,
72 const QString &hostaddress)
73{
74 Q_UNUSED(portFrom);
75 Q_UNUSED(portTo);
76 Q_UNUSED(block);
77 Q_UNUSED(hostaddress);
78 return false;
79}
80
81bool QLocalClientConnection::setFileName(const QString &filename, bool block)
82{
83 m_filename = filename;
84 m_block = block;
85 return connectToServer();
86}
87
92
93bool QLocalClientConnection::connectToServer()
94{
95 m_socket = new QLocalSocket;
96 m_socket->setParent(this);
98 this, &QLocalClientConnection::connectionEstablished);
99 connect(m_socket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(
101 m_socket->disconnectFromServer();
102 m_socket->connectToServer(m_filename);
104
105 m_socket->connectToServer(m_filename);
106 qDebug("QML Debugger: Connecting to socket %s...", m_filename.toLatin1().constData());
107 return true;
108}
109
111{
112 if (m_socket)
113 m_socket->flush();
114}
115
116void QLocalClientConnection::connectionEstablished()
117{
118 m_debugServer->setDevice(m_socket);
119}
120
129
131{
132 return (key == QLatin1String("QLocalClientConnection") ? new QLocalClientConnection : nullptr);
133}
134
136
137#include "qlocalclientconnection.moc"
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
QQmlDebugServerConnection * create(const QString &key) override
bool isConnected() const override
void setServer(QQmlDebugServer *server) override
bool setFileName(const QString &filename, bool block) override
bool setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress) override
The QLocalSocket class provides a local socket.
void connected()
This signal is emitted after connectToServer() has been called and a connection has been successfully...
LocalSocketState state() const
Returns the state of the socket.
virtual qint64 bytesToWrite() const override
\reimp
bool waitForBytesWritten(int msecs=30000) override
\reimp
bool flush()
This function writes as much as possible from the internal write buffer to the socket,...
void disconnectFromServer()
Attempts to close the socket.
bool waitForConnected(int msecs=30000)
Waits until the socket is connected, up to msecs milliseconds.
void connectToServer(OpenMode openMode=ReadWrite)
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
void errorOccurred(QLocalSocket::LocalSocketError socketError)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
virtual void setDevice(QIODevice *socket)=0
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toLatin1() const &
Definition qstring.h:630
Combined button and popup list for selecting options.
@ QueuedConnection
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 int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
#define qDebug
[1]
Definition qlogging.h:164
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
GLuint64 key
#define QQmlDebugServerConnectionFactory_iid
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define Q_OBJECT
#define Q_PLUGIN_METADATA(x)
#define Q_INTERFACES(x)
#define Q_UNUSED(x)
view create()