Skip to content

BLE: Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor #13729

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

Merged
merged 5 commits into from
Oct 13, 2020

Conversation

AGlass0fMilk
Copy link
Member

@AGlass0fMilk AGlass0fMilk commented Oct 6, 2020

Summary of changes

See #13581 for information on issue.

Resolves #13581 by allowing the GattServer to pass a pointer to an implicitly-created CCCD. This GattAttribute is dynamically allocated (using new) and ownership is transferred to the relevant GattCharacteristic, which takes care of deleteing the GattAttribute in its destructor.

I tried to make GattServer a friend class of GattCharacteristic so GattCharacteristic::_setImplicitCCCD could be private, but I wasn't able to get it to compile due to all the weird namespacing stuff going on with ble::GattServer and ble::impl::GattServer -- it boggled my mind so I just made this a public "internal" function.

Impact of changes

GattCharacteristic::getDescriptor and GattCharacteristic::getDescriptorCount now behave as expected when a GattCharacteristic has an implicitly-created CCCD (ie: the GattCharacteristic has indicate and/or notify as one of its properties).

Migration actions required

None

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@pan- @paul-szczepanek-arm


@AGlass0fMilk AGlass0fMilk changed the title Enabled getting an implicitly-created CCCD through GattCharacteristic::getDescriptor Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor Oct 6, 2020
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Oct 6, 2020
@ciarmcom
Copy link
Member

ciarmcom commented Oct 6, 2020

@AGlass0fMilk, thank you for your changes.
@pan- @paul-szczepanek-arm @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested review from pan-, paul-szczepanek-arm and a team October 6, 2020 23:30
@AGlass0fMilk AGlass0fMilk changed the title Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor [BLE] Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor Oct 6, 2020
Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR. Thanks @AGlass0fMilk .

I tried to make GattServer a friend class of GattCharacteristic so GattCharacteristic::_setImplicitCCCD could be private, but I wasn't able to get it to compile due to all the weird namespacing stuff going on with ble::GattServer and ble::impl::GattServer -- it boggled my mind so I just made this a public "internal" function.

In C++, friendship is not inherited. The solution is to:

  • Forward declare ble::GattServer in GattCharacteristic.h
  • Mark it friend in GattCharacteristic (friend ble::GattCharacteristic)
  • Add a protected function in ble::GattServer that can be used by child to add the CCCD. setCharacteristicImplicitCCCD(GattCharacteristic&, GattAttribute*)

@AGlass0fMilk
Copy link
Member Author

Good PR. Thanks @AGlass0fMilk .

I tried to make GattServer a friend class of GattCharacteristic so GattCharacteristic::_setImplicitCCCD could be private, but I wasn't able to get it to compile due to all the weird namespacing stuff going on with ble::GattServer and ble::impl::GattServer -- it boggled my mind so I just made this a public "internal" function.

In C++, friendship is not inherited. The solution is to:

* Forward declare `ble::GattServer` in `GattCharacteristic.h`

* Mark it friend in `GattCharacteristic` (`friend ble::GattCharacteristic`)

* Add a protected function in `ble::GattServer` that can be used by child to add the CCCD. `setCharacteristicImplicitCCCD(GattCharacteristic&, GattAttribute*)`

It turns out that ble::impl::GattServer is not actually a child class of ble::GattServer. So I simply had to forward declare ble::impl::GattServer and then declare it as a friend in the GattCharacteristic declaration.

My problems stemmed from me trying to forward declare only impl::GattServer... does not name a type 🙄

I moved the forward declaration outside of the GattCharacteristic class body, similar to what I saw in GattServer.h and it compiles fine now. A much cleaner implementation 👍

Let me know if anything else needs to be addressed.

pan-
pan- previously approved these changes Oct 9, 2020
Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I request a minor change in the allocation of the CCCD attribute. After that it is good to go.

@mergify mergify bot added needs: CI and removed needs: review labels Oct 9, 2020
@mergify mergify bot dismissed pan-’s stale review October 9, 2020 13:47

Pull request has been modified.

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 13, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Oct 13, 2020

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-ARM ✔️
jenkins-ci/mbed-os-ci_build-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_dynamic-memory-usage ✔️
jenkins-ci/mbed-os-ci_cloud-client-pytest ✔️

@0xc0170 0xc0170 changed the title [BLE] Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor BLE: Enable getting an implicitly-created CCCD through GattCharacteristic::getDescriptor Oct 13, 2020
@0xc0170 0xc0170 merged commit 35f97f4 into ARMmbed:master Oct 13, 2020
@mbedmain mbedmain added release-version: 6.4.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BLE: Intrinsically created descriptors (ie: CCCD) not accessible thru GattCharacteristic::getDescriptor()
8 participants