KWayland::Client::ConnectionThread

#include <connection_thread.h>

Inheritance diagram for KWayland::Client::ConnectionThread:

Signals

void connected ()
 
void connectionDied ()
 
void errorOccurred ()
 
void eventsRead ()
 
void failed ()
 

Public Slots

void flush ()
 
void initConnection ()
 

Public Member Functions

 ConnectionThread (QObject *parent=nullptr)
 
wl_display * display ()
 
int errorCode () const
 
bool hasError () const
 
void roundtrip ()
 
void setSocketFd (int fd)
 
void setSocketName (const QString &socketName)
 
QString socketName () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QVector< ConnectionThread * > connections ()
 
static ConnectionThreadfromApplication (QObject *parent=nullptr)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

 ConnectionThread (wl_display *display, QObject *parent)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Creates and manages the connection to a Wayland server.

The purpose of this class is to create the connection to a Wayland server and to manage it. As the name suggests it's intended to move instances of this class into a dedicated thread. This also means that this class doesn't inherit QThread. In order to use it in a threaded way one needs to create a QThread and move the object there:

ConnectionThread *connection = new ConnectionThread;
connection->moveToThread(thread);
thread->start();

To finalize the initialization of the connection one needs to call ::initConnection. This starts an asynchronous connection initialization. In case the initialization succeeds the signal ::connected will be emitted, otherwise ::failed will be emitted:

connect(connection, &ConnectionThread::connected, [connection] {
qDebug() << "Successfully connected to Wayland server at socket:" << connection->socketName();
});
connect(connection, &ConnectionThread::failed, [connection] {
qDebug() << "Failed to connect to Wayland server at socket:" << connection->socketName();
});
connection->initConnection();

This class is also responsible for dispatching events. Whenever new data is available on the Wayland socket, it will be dispatched and the signal ::eventsRead is emitted. This allows further event queues in other threads to also dispatch their events.

Furthermore this class flushes the Wayland connection whenever the QAbstractEventDispatcher is about to block.

To disconnect the connection to the Wayland server one should delete the instance of this class and quit the dedicated thread:

connection->deleteLater();
thread->quit();
thread->wait();

In addition the ConnectionThread provides integration with QtWayland QPA plugin. For that it provides a static factory method:

The semantics of the ConnectionThread are slightly changed if it's integrated with QtWayland. The ConnectionThread does not hold the connection, does not emit connected or released signals (one can safely assume that the connection is valid when integrating with the Qt application), does not dispatch events. Given that the use case of the ConnectionThread is rather limited to a convenient API around wl_display to allow easily setup an own Registry in a QtWayland powered application. Also moving the ConnectionThread to a different thread is not necessarily recommended in that case as QtWayland holds it's connection in an own thread anyway.

Definition at line 107 of file connection_thread.h.

Member Function Documentation

void KWayland::Client::ConnectionThread::connected ( )
signal

Emitted once a connection to a Wayland server is established.

Normally emitted after invoking initConnection(), but might also be emitted after re-connecting to another server.

void KWayland::Client::ConnectionThread::connectionDied ( )
signal

Emitted if the Wayland server connection dies.

If the socket reappears, it is tried to reconnect.

QVector< ConnectionThread * > KWayland::Client::ConnectionThread::connections ( )
static
Returns
all connections created in this application
Since
5.37

Definition at line 289 of file connection_thread.cpp.

wl_display * KWayland::Client::ConnectionThread::display ( )

The display this ConnectionThread is connected to.

As long as there is no connection this method returns null.

See also
initConnection

Definition at line 242 of file connection_thread.cpp.

int KWayland::Client::ConnectionThread::errorCode ( ) const
Returns
the error code of the last occurred error or 0 if the connection doesn't have an error
See also
hasError
errorOccurred
Since
5.23

Definition at line 284 of file connection_thread.cpp.

void KWayland::Client::ConnectionThread::errorOccurred ( )
signal

The Wayland connection experienced a fatal error.

The ConnectionThread is no longer valid, no requests may be sent. This has the same effects as connectionDied.

See also
hasError
errorCode
Since
5.23
void KWayland::Client::ConnectionThread::eventsRead ( )
signal

Emitted whenever new events are ready to be read.

void KWayland::Client::ConnectionThread::failed ( )
signal

Emitted if connecting to a Wayland server failed.

void KWayland::Client::ConnectionThread::flush ( )
slot

Explicitly flush the Wayland display.

Since
5.3

Definition at line 252 of file connection_thread.cpp.

ConnectionThread * KWayland::Client::ConnectionThread::fromApplication ( QObject parent = nullptr)
static

Creates a ConnectionThread for the used QGuiApplication.

This is an integration feature for QtWayland. On non-wayland platforms this method returns nullptr.

The returned ConnectionThread will be fully setup, which means it manages a wl_display. There is no need to initConnection and the connected or failed signals won't be emitted. When the created ConnectionThread gets destroyed the managed wl_display won't be disconnected as that's managed by Qt.

The returned ConnectionThread is not able to detect (protocol) error. The signal errorOccurred won't be emitted, hasError will return false, even if the actual connection held by QtWayland is on error. The behavior of QtWayland is to exit the application on error.

Since
5.4

Definition at line 199 of file connection_thread.cpp.

bool KWayland::Client::ConnectionThread::hasError ( ) const
Returns
whether the Wayland connection experienced an error
See also
errorCode
errorOccurred
Since
5.23

Definition at line 279 of file connection_thread.cpp.

void KWayland::Client::ConnectionThread::initConnection ( )
slot

Initializes the connection in an asynchronous way.

In case the connection gets established the signal ::connected will be emitted, on failure the signal ::failed will be emitted.

See also
connected
failed

Definition at line 214 of file connection_thread.cpp.

void KWayland::Client::ConnectionThread::roundtrip ( )

Trigger a blocking roundtrip to the Wayland server.

Ensures that all events are processed before returning to the event loop.

Since
5.4

Definition at line 260 of file connection_thread.cpp.

void KWayland::Client::ConnectionThread::setSocketFd ( int  fd)

Sets the socket fd to connect to.

Only applies if called before calling initConnection. If this method is invoked, the connection will be created on the file descriptor and not on the socket name passed through setSocketName or through the default environment variable WAYLAND_DISPLAY.

See also
setSocketName

Definition at line 233 of file connection_thread.cpp.

void KWayland::Client::ConnectionThread::setSocketName ( const QString socketName)

Sets the socketName to connect to.

Only applies if called before calling initConnection. The default socket name is derived from environment variable WAYLAND_DISPLAY and if not set is hard coded to "wayland-0".

The socket name will be ignored if a file descriptor has been set through setSocketFd.

See also
setSocketFd

Definition at line 224 of file connection_thread.cpp.

QString KWayland::Client::ConnectionThread::socketName ( ) const
Returns
the name of the socket it connects to.

Definition at line 247 of file connection_thread.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 13 2020 22:50:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.