-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Peripheral fed into discover callback losses underlying handles #331
Comments
Source of issue #311. |
I tested switching to a pass by reference for the callbacks and it had no impact on the results which makes sense since the internal objects is a |
It seems like using Safe::Adapter and Safe::Peripheral for the callbacks and variables remedies the issue. I guess the issue can be closed? I'm curious why both the Safe and normal APIs exist for C++. I think it would make a lot more sense to have the Safe API be the normal one which would minimize these sorts of issues. |
Hey @Jah-On, thanks for the report! I'll reopen the issue to make sure I do a once-over to see what can be improved. |
Calling any member function on the
Peripheral
passed into the callback does not do anything or behaves incorrectly. Here is a minimal example of it not working:With a valid
Peripheral
instance, this code should send "Hello world!" to the NUS and print out the response from the device. However, when using the callback instance, it does not do anything.The reason why this does not work is because SimpleBLE creates a clone of the Peripheral instance using the
default
constructor. Thus, the underlying back-end handles are no longer valid and the functions don't do anything.Possible solutions
Personally, I think the callbacks should use pass by reference instead of a cloned constructor. If this can't be done, then a proper cloning constructor should be implemented to ensure the back-end handles are swapped or re-validated.
I can work on this myself unless a different maintainer wants to do it.
The text was updated successfully, but these errors were encountered: