| 1 | // Copyright (C) 2021 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 QLOWENERGYSERVICEPRIVATE_P_H |
| 5 | #define QLOWENERGYSERVICEPRIVATE_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 <QtCore/QObject> |
| 19 | #include <QtCore/QPointer> |
| 20 | #include <QtBluetooth/qbluetooth.h> |
| 21 | #include <QtBluetooth/QLowEnergyService> |
| 22 | #include <QtBluetooth/QLowEnergyCharacteristic> |
| 23 | #include <QtCore/private/qglobal_p.h> |
| 24 | |
| 25 | #if defined(QT_ANDROID_BLUETOOTH) |
| 26 | #include <QtCore/QJniObject> |
| 27 | #endif |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | class QLowEnergyControllerPrivate; |
| 32 | |
| 33 | class QLowEnergyServicePrivate : public QObject |
| 34 | { |
| 35 | Q_OBJECT |
| 36 | public: |
| 37 | explicit QLowEnergyServicePrivate(QObject *parent = nullptr); |
| 38 | ~QLowEnergyServicePrivate(); |
| 39 | |
| 40 | struct DescData { |
| 41 | QByteArray value; |
| 42 | QBluetoothUuid uuid; |
| 43 | }; |
| 44 | |
| 45 | struct CharData { |
| 46 | QLowEnergyHandle valueHandle; |
| 47 | QBluetoothUuid uuid; |
| 48 | QLowEnergyCharacteristic::PropertyTypes properties; |
| 49 | QByteArray value; |
| 50 | QHash<QLowEnergyHandle, DescData> descriptorList; |
| 51 | }; |
| 52 | |
| 53 | enum GattAttributeTypes { |
| 54 | PrimaryService = 0x2800, |
| 55 | SecondaryService = 0x2801, |
| 56 | IncludeAttribute = 0x2802, |
| 57 | Characteristic = 0x2803 |
| 58 | }; |
| 59 | |
| 60 | void setController(QLowEnergyControllerPrivate* control); |
| 61 | void setError(QLowEnergyService::ServiceError newError); |
| 62 | void setState(QLowEnergyService::ServiceState newState); |
| 63 | |
| 64 | signals: |
| 65 | void stateChanged(QLowEnergyService::ServiceState newState); |
| 66 | void errorOccurred(QLowEnergyService::ServiceError error); |
| 67 | void characteristicChanged(const QLowEnergyCharacteristic &characteristic, |
| 68 | const QByteArray &newValue); |
| 69 | void characteristicRead(const QLowEnergyCharacteristic &info, |
| 70 | const QByteArray &value); |
| 71 | void characteristicWritten(const QLowEnergyCharacteristic &characteristic, |
| 72 | const QByteArray &newValue); |
| 73 | void descriptorRead(const QLowEnergyDescriptor &info, |
| 74 | const QByteArray &value); |
| 75 | void descriptorWritten(const QLowEnergyDescriptor &descriptor, |
| 76 | const QByteArray &newValue); |
| 77 | |
| 78 | public: |
| 79 | QLowEnergyHandle startHandle = 0; |
| 80 | QLowEnergyHandle endHandle = 0; |
| 81 | |
| 82 | QBluetoothUuid uuid; |
| 83 | QList<QBluetoothUuid> includedServices; |
| 84 | QLowEnergyService::ServiceTypes type = QLowEnergyService::PrimaryService; |
| 85 | QLowEnergyService::ServiceState state = QLowEnergyService::InvalidService; |
| 86 | QLowEnergyService::ServiceError lastError = QLowEnergyService::NoError; |
| 87 | QLowEnergyService::DiscoveryMode mode = QLowEnergyService::FullDiscovery; |
| 88 | |
| 89 | QHash<QLowEnergyHandle, CharData> characteristicList; |
| 90 | |
| 91 | QPointer<QLowEnergyControllerPrivate> controller; |
| 92 | |
| 93 | #if defined(QT_ANDROID_BLUETOOTH) |
| 94 | // reference to the BluetoothGattService object |
| 95 | QJniObject androidService; |
| 96 | #endif |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | typedef QHash<QLowEnergyHandle, QLowEnergyServicePrivate::CharData> CharacteristicDataMap; |
| 101 | typedef QHash<QLowEnergyHandle, QLowEnergyServicePrivate::DescData> DescriptorDataMap; |
| 102 | |
| 103 | QT_END_NAMESPACE |
| 104 | |
| 105 | QT_DECL_METATYPE_EXTERN_TAGGED(QSharedPointer<QLowEnergyServicePrivate>, |
| 106 | QSharedPointer_QLowEnergyServicePrivate, |
| 107 | /* not exported */) |
| 108 | |
| 109 | #endif // QLOWENERGYSERVICEPRIVATE_P_H |
| 110 | |