weliem / bluez_inc

A C library for Bluez (BLE) that hides all DBus communication. It doesn't get easier than this. This library can also be used in C++.
MIT License
84 stars 19 forks source link

Add Device into characteristic callbacks? #40

Closed bojennett closed 4 months ago

bojennett commented 4 months ago

On iOS, the peripheral delegate callbacks (didUpdateNotificationStateFor, didUpdateValueFor, didWriteValueFor, didUpdateValueFor) contain the peripheral object. Same for Android on the BluetoothGattCallback (onCharacteristicChanged, onDescriptorWrite, onCharacteristicWrite, onCharacteristicRead).

It's nice having this device object in the callbacks, that way you don't have to keep your own reference around to it. As an example, after getting something back that you read, or receiving a specific notification status, you might want to disconnect because you have everything you need. Having the device object right there in the callback makes that easy as opposed to having to hold it yourself in your code and then free it after. I agree that you can have your own callbacks for each device when you set them on connection so you can "know" who is who, but you still need to hold onto that reference.

weliem commented 4 months ago

Makes total sense! I did that already with several other callbacks but indeed not with the characteristic ones...not sure why I didn't

weliem commented 4 months ago

Fixed by d214565f00e4c91c7ba7bca34f7c9e8a303576ba