54 QLowEnergyControllerPrivateWinRT();
64 QLowEnergyService::DiscoveryMode mode)
override;
67 const QLowEnergyAdvertisingData &advertisingData,
68 const QLowEnergyAdvertisingData &scanResponseData)
override;
75 const QLowEnergyHandle charHandle)
override;
76 void readDescriptor(
const QSharedPointer<QLowEnergyServicePrivate> service,
77 const QLowEnergyHandle charHandle,
78 const QLowEnergyHandle descriptorHandle)
override;
82 const QLowEnergyHandle charHandle,
83 const QByteArray &newValue, QLowEnergyService::WriteMode mode)
override;
84 void writeDescriptor(
const QSharedPointer<QLowEnergyServicePrivate> service,
85 const QLowEnergyHandle charHandle,
86 const QLowEnergyHandle descriptorHandle,
87 const QByteArray &newValue)
override;
90 QLowEnergyHandle startHandle)
override;
92 int mtu()
const override;
95 void characteristicChanged(quint16 charHandle,
const QByteArray &data);
99 void handleCharacteristicChanged(quint16 charHandle,
const QByteArray &data);
100 void handleServiceHandlerError(
const QString &error);
103 void handleConnectionError(
const char *logMessage);
105 BluetoothLEDevice mDevice =
nullptr;
106 GattSession mGattSession =
nullptr;
107 winrt::event_token mStatusChangedToken{ 0 };
108 winrt::event_token mMtuChangedToken{ 0 };
109 struct ValueChangedEntry {
110 ValueChangedEntry() {}
111 ValueChangedEntry(GattCharacteristic c,
112 winrt::event_token t)
118 GattCharacteristic characteristic =
nullptr;
119 winrt::event_token token = { 0 };
121 QList<ValueChangedEntry> mValueChangedTokens;
123 QMap<QBluetoothUuid, GattDeviceService> m_openedServices;
124 QSet<QBluetoothUuid> m_requestDetailsServiceUuids;
126 using NativeCharacteristicKey = std::pair<QBluetoothUuid,
128 QHash<NativeCharacteristicKey, GattCharacteristic> m_openedCharacteristics;
133 using NativeServiceCallback = std::function<
void(GattDeviceService)>;
134 bool getNativeService(
const QBluetoothUuid &serviceUuid, NativeServiceCallback callback);
140 using NativeCharacteristicCallback = std::function<
void(GattCharacteristic)>;
141 bool getNativeCharacteristic(
const QBluetoothUuid &serviceUuid,
142 const QBluetoothUuid &charUuid,
143 NativeCharacteristicCallback callback);
149 struct PendingCharOperations
151 quint64 generation = 0;
152 QList<NativeCharacteristicCallback> callbacks;
154 QHash<NativeCharacteristicKey, PendingCharOperations> m_pendingCharOperations;
155 quint64 m_charOperationsGeneration = 0;
157 void registerForValueChanges(
const QBluetoothUuid &serviceUuid,
const QBluetoothUuid &charUuid);
158 void unregisterFromValueChanges();
159 void onValueChange(GattCharacteristic characteristic, GattValueChangedEventArgs
const &args);
160 void onMtuChange(GattSession session, winrt::IInspectable args);
161 bool registerForMtuChanges();
162 void unregisterFromMtuChanges();
164 bool registerForStatusChanges();
165 void unregisterFromStatusChanges();
166 void onStatusChange(BluetoothLEDevice dev, winrt::IInspectable args);
168 void obtainIncludedServices(QSharedPointer<QLowEnergyServicePrivate> servicePointer,
169 GattDeviceService nativeService);
170 void onServiceDiscoveryFinished(winrt::Windows::Foundation::IAsyncOperation<GattDeviceServicesResult>
const &op,
171 winrt::AsyncStatus status);
173 void readCharacteristicHelper(
const QSharedPointer<QLowEnergyServicePrivate> service,
174 const QLowEnergyHandle charHandle,
175 GattCharacteristic characteristic);
176 void readDescriptorHelper(
const QSharedPointer<QLowEnergyServicePrivate> service,
177 const QLowEnergyHandle charHandle,
178 const QLowEnergyHandle descriptorHandle,
179 GattCharacteristic characteristic);
180 void writeCharacteristicHelper(
const QSharedPointer<QLowEnergyServicePrivate> service,
181 const QLowEnergyHandle charHandle,
const QByteArray &newValue,
182 bool writeWithResponse,
183 GattCharacteristic characteristic);
184 void writeDescriptorHelper(
const QSharedPointer<QLowEnergyServicePrivate> service,
185 const QLowEnergyHandle charHandle,
186 const QLowEnergyHandle descriptorHandle,
187 const QByteArray &newValue,
188 GattCharacteristic characteristic);
189 void discoverServiceDetailsHelper(
const QBluetoothUuid &service,
190 QLowEnergyService::DiscoveryMode mode,
191 GattDeviceService deviceService);
193 void clearAllServices();
194 void closeAndRemoveService(
const QBluetoothUuid &uuid);
196 void handleCharacteristic(
const NativeCharacteristicKey &key,
198 GattDeviceService service,
199 GattCharacteristic characteristic);
200 void removeCachedCharacteristics(
const QBluetoothUuid &serviceUuid);