16#include <QtBluetooth/qbluetoothdeviceinfo.h> 
   17#include <QtBluetooth/qbluetoothserviceinfo.h> 
   19#include <QtCore/qloggingcategory.h> 
   20#include <QtCore/qrandom.h> 
   22#include <QtNetwork/qlocalsocket.h> 
   83    reply.waitForFinished();
 
   94                                           ifaceIter != ifaceList.
constEnd(); ++ifaceIter) {
 
   96                if (
path.path().indexOf(adapterPath) != 0)
 
  101                if (
device.adapter().path() != adapterPath)
 
  105                if (btAddress.isNull() || btAddress != 
address)
 
  118        QIODevice::OpenMode openMode)
 
  123    bool success = 
false;
 
  126    if (profileContext) {
 
  127        qCDebug(QT_BT_BLUEZ) << 
"Profile context still active. close socket first.";
 
  135            this, &QBluetoothSocketPrivateBluezDBus::remoteConnected);
 
  137    for (
i = 0; 
i < 10 && !success; 
i++) {
 
  141        profilePath = u
"/qt/btsocket/%1%2/%3"_s.
 
  152        qCWarning(QT_BT_BLUEZ) << 
"Cannot export serial client profile on DBus";
 
  154        delete profileContext;
 
  155        profileContext = 
nullptr;
 
  157        errorString = QBluetoothSocket::tr(
"Cannot export profile on DBus");
 
  172    qCDebug(QT_BT_BLUEZ) << 
"Registering client profile on" << profilePath << 
"with options:";
 
  173    qCDebug(QT_BT_BLUEZ) << profileOptions;
 
  178    reply.waitForFinished();
 
  179    if (
reply.isError()) {
 
  180        qCWarning(QT_BT_BLUEZ) << 
"Client profile registration failed:" 
  184        errorString = QBluetoothSocket::tr(
"Cannot register profile on DBus");
 
  190    if (remoteDevicePath.
isEmpty()) {
 
  192                               << 
"Try device discovery first";
 
  195        errorString = QBluetoothSocket::tr(
"Cannot find remote device");
 
  217    if (
reply.isError()) {
 
  218        qCWarning(QT_BT_BLUEZ) << 
"Cannot connect to profile/service.";
 
  222        errorString = QBluetoothSocket::tr(
"Cannot connect to remote profile");
 
  234    targetService = service.serviceUuid();
 
  235    if (targetService.
isNull()) {
 
  241    if (targetService.
isNull()) {
 
  242        qCWarning(QT_BT_BLUEZ) << 
"Cannot find appropriate serviceUuid" 
  243                               << 
"or SerialPort service class uuid";
 
  244        errorString = QBluetoothSocket::tr(
"Missing serviceUuid or Serial Port service class uuid");
 
  262        qCWarning(QT_BT_BLUEZ) << 
"Invalid address to remote address passed.";
 
  263        errorString = QBluetoothSocket::tr(
"Invalid Bluetooth address passed to connectToService()");
 
  269        qCWarning(QT_BT_BLUEZ) << 
"Cannot find appropriate serviceUuid" 
  270                               << 
"or SerialPort service class uuid";
 
  271        errorString = QBluetoothSocket::tr(
"Missing serviceUuid or Serial Port service class uuid");
 
  277        qCWarning(QT_BT_BLUEZ) << 
"QBluetoothSocketPrivateBluezDBus::connectToService called on busy socket";
 
  278        errorString = QBluetoothSocket::tr(
"Trying to connect while connection is in progress");
 
  284        qCWarning(QT_BT_BLUEZ) << 
"QBluetoothSocketPrivateBluezDBus::connectToService cannot " 
  285                                  "connect with 'UnknownProtocol' (type provided by given service)";
 
  286        errorString = QBluetoothSocket::tr(
"Socket type not supported");
 
  292        errorString = QBluetoothSocket::tr(
"Socket type not supported");
 
  308    errorString = 
tr(
"Connecting to port is not supported via Bluez DBus");
 
  310    qCWarning(QT_BT_BLUEZ) << 
"Connecting to port is not supported (Uuid required)";
 
  316        localSocket->
close();
 
  324        emit q->readChannelFinished();
 
  358    if (descriptor == -1)
 
  363        socklen_t addrLength = 
sizeof(
addr);
 
  365        if (::getsockname(descriptor, 
reinterpret_cast<sockaddr *
>(&
addr), &addrLength) == 0)
 
  366            return (
addr.rc_channel);
 
  369        socklen_t addrLength = 
sizeof(
addr);
 
  371        if (::getsockname(descriptor, 
reinterpret_cast<sockaddr *
>(&
addr), &addrLength) == 0)
 
  380    if (remoteDevicePath.
isEmpty())
 
  390    if (remoteDevicePath.
isEmpty())
 
  404    if (descriptor == -1)
 
  409        socklen_t addrLength = 
sizeof(
addr);
 
  411        if (::getpeername(descriptor, 
reinterpret_cast<sockaddr *
>(&
addr), &addrLength) == 0)
 
  412            return addr.rc_channel;
 
  415        socklen_t addrLength = 
sizeof(
addr);
 
  417        if (::getpeername(descriptor, 
reinterpret_cast<sockaddr *
>(&
addr), &addrLength) == 0)
 
  432        errorString = QBluetoothSocket::tr(
"Cannot write while not connected");
 
  438        return localSocket->
write(
data, maxSize);
 
  451        errorString = QBluetoothSocket::tr(
"Cannot read while not connected");
 
  457        return localSocket->
read(
data, maxSize);
 
  505    int descriptor = ::dup(
fd.fileDescriptor());
 
  509    if (!success || !localSocket->
isValid()) {
 
  512        localSocket = 
nullptr;
 
  517                this, &QBluetoothSocketPrivateBluezDBus::socketStateChanged);
 
  538        emit q->readChannelFinished();
 
  547void QBluetoothSocketPrivateBluezDBus::clearSocket()
 
  554    qCDebug(QT_BT_BLUEZ) << 
"Clearing profile called for" << profilePath;
 
  557        localSocket->
close();
 
  559        localSocket = 
nullptr;
 
  567        auto reply = 
device.DisconnectProfile(profileUuid);
 
  568        reply.waitForFinished();
 
  569        if (
reply.isError()) {
 
  570            qCWarning(QT_BT_BLUEZ) << 
"Disconnect profile failed:" 
  576    reply.waitForFinished();
 
  582    if (profileContext) {
 
  583        delete profileContext;
 
  584        profileContext = 
nullptr;
 
  587    remoteDevicePath.
clear();
 
  593#include "moc_qbluetoothsocket_bluezdbus_p.cpp" 
QString sanitizeNameForDBus(const QString &text)
 
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok=nullptr)
 
IOBluetoothDevice * device
 
void newConnection(const QDBusUnixFileDescriptor &fd)
 
QDBusPendingReply UnregisterProfile(const QDBusObjectPath &profile)
 
QDBusPendingReply RegisterProfile(const QDBusObjectPath &profile, const QString &UUID, const QVariantMap &options)
 
Protocol
This enum describes the socket protocol used by the service.
 
QBluetoothSocket::OpenMode openMode
 
QBluetoothServiceInfo::Protocol socketType
 
QBluetoothSocket::SocketState state
 
quint16 peerPort() const override
 
qint64 readData(char *data, qint64 maxSize) override
 
qint64 bytesAvailable() const override
 
~QBluetoothSocketPrivateBluezDBus() override
 
quint16 localPort() const override
 
bool canReadLine() const override
 
void connectToService(const QBluetoothServiceInfo &service, QIODevice::OpenMode openMode) override
 
void connectToServiceHelper(const QBluetoothAddress &address, quint16 port, QIODevice::OpenMode openMode) override
 
QBluetoothAddress peerAddress() const override
 
qint64 bytesToWrite() const override
 
QString peerName() const override
 
QBluetoothAddress localAddress() const override
 
qint64 writeData(const char *data, qint64 maxSize) override
 
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, QBluetoothSocket::SocketState socketState=QBluetoothSocket::SocketState::ConnectedState, QBluetoothSocket::OpenMode openMode=QBluetoothSocket::ReadWrite) override
 
void connectToServiceReplyHandler(QDBusPendingCallWatcher *)
 
bool ensureNativeSocket(QBluetoothServiceInfo::Protocol type) override
 
QString localName() const override
 
SocketState
This enum describes the state of the Bluetooth socket.
 
@ UnsupportedProtocolError
 
static qint64 applicationPid() Q_DECL_CONST_FUNCTION
 
QString applicationName
the name of this application
 
static QDBusConnection systemBus()
Returns a QDBusConnection object opened with the system bus.
 
void unregisterObject(const QString &path, UnregisterMode mode=UnregisterNode)
Unregisters an object that was registered with the registerObject() at the object path given by path ...
 
bool registerObject(const QString &path, QObject *object, RegisterOptions options=ExportAdaptors)
Registers the object object at path path and returns true if the registration was successful.
 
void finished(QDBusPendingCallWatcher *self=nullptr)
This signal is emitted when the pending call has finished and its reply is available.
 
void readyRead()
This signal is emitted once every time new data is available for reading from the device's current re...
 
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device's current write ch...
 
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
 
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
 
The QLocalSocket class provides a local socket.
 
bool setSocketDescriptor(qintptr socketDescriptor, LocalSocketState socketState=ConnectedState, OpenMode openMode=ReadWrite)
Initializes QLocalSocket with the native socket descriptor socketDescriptor.
 
virtual qint64 bytesToWrite() const override
\reimp
 
virtual bool canReadLine() const override
\reimp
 
LocalSocketState
This enum describes the different states in which a socket can be.
 
bool isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.
 
qintptr socketDescriptor() const
Returns the native socket descriptor of the QLocalSocket object if this is available; otherwise retur...
 
virtual void close() override
Closes the I/O device for the socket and calls disconnectFromServer() to close the socket's connectio...
 
virtual qint64 bytesAvailable() const override
\reimp
 
void stateChanged(QLocalSocket::LocalSocketState socketState)
This signal is emitted whenever QLocalSocket's state changes.
 
iterator insert(const Key &key, const T &value)
 
const_iterator constBegin() const
 
const_iterator constEnd() const
 
NetworkError error() const
Returns the error that was found during the processing of this request.
 
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
 
void deleteLater()
\threadsafe
 
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
 
\macro QT_RESTRICTED_CAST_FROM_ASCII
 
void clear()
Clears the contents of the string and makes it null.
 
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
 
QString toString(StringFormat mode=WithBraces) const
 
bool isNull() const noexcept
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false...
 
QSet< QString >::iterator it
 
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
 
Combined button and popup list for selecting options.
 
static QString findRemoteDevicePath(const QBluetoothAddress &address)
 
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
 
#define qCWarning(category,...)
 
#define qCDebug(category,...)
 
#define Q_DECLARE_LOGGING_CATEGORY(name)
 
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
 
GLuint GLuint64EXT address
 
GLdouble GLdouble GLdouble GLdouble q
 
GLsizei const GLchar *const  * path
 
#define QStringLiteral(str)
 
QFutureWatcher< int > watcher
 
QNetworkAccessManager manager