| 1 | // Copyright (C) 2018 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 | #ifndef QBLUETOOTHSOCKET_BLUEZDBUS_H |
| 5 | #define QBLUETOOTHSOCKET_BLUEZDBUS_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qbluetoothsocketbase_p.h" |
| 19 | |
| 20 | #include <QtDBus/qdbusunixfiledescriptor.h> |
| 21 | |
| 22 | #include <QtNetwork/qlocalsocket.h> |
| 23 | #include <QDBusPendingCallWatcher> |
| 24 | |
| 25 | namespace QtBluetoothPrivate { |
| 26 | |
| 27 | class OrgBluezProfileManager1Interface; |
| 28 | |
| 29 | } // namespace QtBluetoothPrivate |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | class QLocalSocket; |
| 34 | class OrgBluezProfile1ContextInterface; |
| 35 | |
| 36 | class QBluetoothSocketPrivateBluezDBus final: public QBluetoothSocketBasePrivate |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | |
| 40 | public: |
| 41 | QBluetoothSocketPrivateBluezDBus(); |
| 42 | ~QBluetoothSocketPrivateBluezDBus() override; |
| 43 | |
| 44 | void connectToServiceHelper(const QBluetoothAddress &address, |
| 45 | quint16 port, |
| 46 | QIODevice::OpenMode openMode) override; |
| 47 | void connectToServiceHelper(const QBluetoothAddress &address, |
| 48 | const QBluetoothUuid &uuid, |
| 49 | QIODevice::OpenMode openMode); |
| 50 | |
| 51 | void connectToService(const QBluetoothServiceInfo &service, |
| 52 | QIODevice::OpenMode openMode) override; |
| 53 | void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, |
| 54 | QIODevice::OpenMode openMode) override; |
| 55 | void connectToService(const QBluetoothAddress &address, quint16 port, |
| 56 | QIODevice::OpenMode openMode) override; |
| 57 | |
| 58 | bool ensureNativeSocket(QBluetoothServiceInfo::Protocol type) override; |
| 59 | |
| 60 | QString localName() const override; |
| 61 | QBluetoothAddress localAddress() const override; |
| 62 | quint16 localPort() const override; |
| 63 | |
| 64 | QString peerName() const override; |
| 65 | QBluetoothAddress peerAddress() const override; |
| 66 | quint16 peerPort() const override; |
| 67 | |
| 68 | void abort() override; |
| 69 | void close() override; |
| 70 | |
| 71 | qint64 writeData(const char *data, qint64 maxSize) override; |
| 72 | qint64 readData(char *data, qint64 maxSize) override; |
| 73 | |
| 74 | bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, |
| 75 | QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState, |
| 76 | QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override; |
| 77 | |
| 78 | qint64 bytesAvailable() const override; |
| 79 | bool canReadLine() const override; |
| 80 | qint64 bytesToWrite() const override; |
| 81 | |
| 82 | public slots: |
| 83 | void connectToServiceReplyHandler(QDBusPendingCallWatcher *); |
| 84 | |
| 85 | private: |
| 86 | void remoteConnected(const QDBusUnixFileDescriptor &fd); |
| 87 | void socketStateChanged(QLocalSocket::LocalSocketState newState); |
| 88 | |
| 89 | void clearSocket(); |
| 90 | |
| 91 | private: |
| 92 | QtBluetoothPrivate::OrgBluezProfileManager1Interface *profileManager = nullptr; |
| 93 | OrgBluezProfile1ContextInterface *profileContext = nullptr; |
| 94 | QString remoteDevicePath; |
| 95 | QString profileUuid; |
| 96 | QString profilePath; |
| 97 | QLocalSocket *localSocket = nullptr; |
| 98 | }; |
| 99 | |
| 100 | QT_END_NAMESPACE |
| 101 | |
| 102 | #endif // QBLUETOOTHSOCKET_BLUEZDBUS_H |
| 103 | |