-
Notifications
You must be signed in to change notification settings - Fork 3k
BLE: Fix GattServer callbacks not being copied to GattServer instance of the service #14084
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
BLE: Fix GattServer callbacks not being copied to GattServer instance of the service #14084
Conversation
@@ -941,7 +964,8 @@ ble_error_t GattServer::reset(ble::GattServer* server) | |||
currentHandle = 0; | |||
cccd_cnt = 0; | |||
|
|||
_auth_char_count = 0; | |||
_auth_callbacks_count = 0; | |||
_auth_callbacks = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory is freed elsewhere (line 954)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite the nitpicking on class/pointer to bool auto conversion in if/while statements, it LGTM.
GattCharacteristic *auth_char = getInstance().get_auth_char(handle); | ||
if (auth_char && auth_char->isReadAuthorizationEnabled()) { | ||
char_auth_callback *auth_cb = getInstance().get_auth_callback(handle); | ||
if (auth_cb && auth_cb->read_cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a bit fan of pointer to bool coersion.
I'd prefer a
if (auth_cb && auth_cb->read_cb) { | |
if ((auth_cb != NULL) && (auth_cb->read_cb != NULL)) { |
GattAuthCallbackReply_t ret = auth_char->authorizeRead(&read_auth_params); | ||
if (ret != AUTH_CALLBACK_REPLY_SUCCESS) { | ||
return ret & 0xFF; | ||
auth_cb->read_cb.call(&read_auth_params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what FunctionPointerWithContext
does, but the test above followed by this by-value access to the member is a bit confusing.
@paul-szczepanek-arm, thank you for your changes. |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
There's something wrong with CI, the failed test is complaining about errors in mbed tools? |
This fixes the issue #14108. This PR needs to be rebased to the latest master. |
3ddab77
to
5e99ea8
Compare
thanks, rebased |
Ci restarted |
Jenkins CI Test : ❌ FAILEDBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Build failing because of unrelated issue causing link error on ARM: |
Hi, @paul-szczepanek-arm |
That was the socket defaulting to tls and is already fixed. |
CI restarted |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
When adding services to GattServer, they are allocated new memory and any changes made to original characteristics will not take effect after adding them - all operations must be performed on the GattServer version. This is correct behaviour.
At the same time we are requesting the user keeps hold of the old characteristics, wasting space for no reason. This is because gattserver makes references to the original characteristics. There is no need for this.
This PR copies the values being used through reference (authorisation callbacks) and updates the docs to remove the requirement to keep the characteristics after adding. The behaviour does not change and existing code will run the same way but it is now allowed to free the characteristics used to build the service and thus free up memory.
Impact of changes
Migration actions required
Documentation
none
Pull request type
Test results
Reviewers
@ithinuel