| 1 | // Copyright (C) 2022 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 BLUEZ_PERIPHERAL_CONNECTION_MANAGER_P_H | 
| 5 | #define BLUEZ_PERIPHERAL_CONNECTION_MANAGER_P_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 <QtBluetooth/QBluetoothAddress> | 
| 19 | #include <QtBluetooth/QBluetoothUuid> | 
| 20 | #include <QtCore/QObject> | 
| 21 |  | 
| 22 | QT_BEGIN_NAMESPACE | 
| 23 |  | 
| 24 | class QBluetoothLocalDevice; | 
| 25 |  | 
| 26 | /* | 
| 27 |     QtBluezPeripheralConnectionManager determines | 
| 28 |     - when remote Gatt client(s) connect and disconnect | 
| 29 |     - the remote device details (name, address, mtu) | 
| 30 |  | 
| 31 |     'Connected' state is assumed when first client reads a characteristic. | 
| 32 |     'Disconnected' state is assumed when all such clients have disconnected. | 
| 33 | */ | 
| 34 |  | 
| 35 | class QtBluezPeripheralConnectionManager : public QObject | 
| 36 | { | 
| 37 |     Q_OBJECT | 
| 38 | public: | 
| 39 |     QtBluezPeripheralConnectionManager(const QBluetoothAddress& localAddress, | 
| 40 |                                        QObject* parent = nullptr); | 
| 41 |     void reset(); | 
| 42 |     void disconnectDevices(); | 
| 43 |  | 
| 44 | public slots: | 
| 45 |     void remoteDeviceAccessEvent(const QString& remoteDeviceObjectPath, quint16 mtu); | 
| 46 |  | 
| 47 | signals: | 
| 48 |     void connectivityStateChanged(bool connected); | 
| 49 |     void remoteDeviceChanged(const QBluetoothAddress& address, const QString& name, quint16 mtu); | 
| 50 |  | 
| 51 | private slots: | 
| 52 |     void remoteDeviceDisconnected(const QBluetoothAddress& address); | 
| 53 |  | 
| 54 | private: | 
| 55 |     struct RemoteDeviceDetails { | 
| 56 |         QBluetoothAddress address; | 
| 57 |         QString name; | 
| 58 |         quint16 mtu; | 
| 59 |     }; | 
| 60 |     bool m_connected{false}; | 
| 61 |     QString m_hostAdapterPath; | 
| 62 |     QMap<QString, RemoteDeviceDetails> m_clients; | 
| 63 |     QBluetoothLocalDevice* m_localDevice; | 
| 64 | }; | 
| 65 |  | 
| 66 | QT_END_NAMESPACE | 
| 67 |  | 
| 68 | #endif | 
| 69 |  |