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 | class OrgBluezProfileManager1Interface; |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QLocalSocket; |
30 | class OrgBluezProfile1ContextInterface; |
31 | |
32 | class QBluetoothSocketPrivateBluezDBus final: public QBluetoothSocketBasePrivate |
33 | { |
34 | Q_OBJECT |
35 | |
36 | public: |
37 | QBluetoothSocketPrivateBluezDBus(); |
38 | ~QBluetoothSocketPrivateBluezDBus() override; |
39 | |
40 | void connectToServiceHelper(const QBluetoothAddress &address, |
41 | quint16 port, |
42 | QIODevice::OpenMode openMode) override; |
43 | void connectToServiceHelper(const QBluetoothAddress &address, |
44 | const QBluetoothUuid &uuid, |
45 | QIODevice::OpenMode openMode); |
46 | |
47 | void connectToService(const QBluetoothServiceInfo &service, |
48 | QIODevice::OpenMode openMode) override; |
49 | void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, |
50 | QIODevice::OpenMode openMode) override; |
51 | void connectToService(const QBluetoothAddress &address, quint16 port, |
52 | QIODevice::OpenMode openMode) override; |
53 | |
54 | bool ensureNativeSocket(QBluetoothServiceInfo::Protocol type) override; |
55 | |
56 | QString localName() const override; |
57 | QBluetoothAddress localAddress() const override; |
58 | quint16 localPort() const override; |
59 | |
60 | QString peerName() const override; |
61 | QBluetoothAddress peerAddress() const override; |
62 | quint16 peerPort() const override; |
63 | |
64 | void abort() override; |
65 | void close() override; |
66 | |
67 | qint64 writeData(const char *data, qint64 maxSize) override; |
68 | qint64 readData(char *data, qint64 maxSize) override; |
69 | |
70 | bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, |
71 | QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState, |
72 | QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override; |
73 | |
74 | qint64 bytesAvailable() const override; |
75 | bool canReadLine() const override; |
76 | qint64 bytesToWrite() const override; |
77 | |
78 | public slots: |
79 | void connectToServiceReplyHandler(QDBusPendingCallWatcher *); |
80 | |
81 | private: |
82 | void remoteConnected(const QDBusUnixFileDescriptor &fd); |
83 | void socketStateChanged(QLocalSocket::LocalSocketState newState); |
84 | |
85 | void clearSocket(); |
86 | |
87 | private: |
88 | OrgBluezProfileManager1Interface *profileManager = nullptr; |
89 | OrgBluezProfile1ContextInterface *profileContext = nullptr; |
90 | QString remoteDevicePath; |
91 | QString profileUuid; |
92 | QString profilePath; |
93 | QLocalSocket *localSocket = nullptr; |
94 | }; |
95 | |
96 | QT_END_NAMESPACE |
97 | |
98 | #endif // QBLUETOOTHSOCKET_BLUEZDBUS_H |
99 | |