-
Notifications
You must be signed in to change notification settings - Fork 3k
[BLE] Change GattServer callbacks to CallChains #13728
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
Conversation
…d onConfirmationReceived callbacks
… is consistent among other GattServer callback APIs
@AGlass0fMilk, thank you for your changes. |
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.
If we're breaking backwards compatibility I think we should converge on eventHandler model instead of callchains. If you need multiple event handers you can still have that. There's a couple classes that already do.
When we changed the gap API, we kept the callchains, deprecated them and then added the eventHandler to take their place. Maybe we could do that here (I don't actually know if it's feasible in this case).
@paul-szczepanek-arm Could you point me to the code where multiple event handlers are possible? My own feedback as a user: After using the On the same topic, I've found the BLE stack's Is there any reason we don't migrate BLE away from I recreated the deprecated (now removed?) https://github.com/EmbeddedPlanet/ep-oc-mcu/blob/master/extensions/CallChain.h Perhaps that could be useful... |
@pan- What do you think about EventHandler vs CallChains? I looked at the Multiple event handler objects is a possible solution, but it seems like it would be clunkier than just having CallChains (made of Mbed Callbacks) since Mbed already has a functor concept. I don't want to start working on moving these PRs over to the EventHandler API until we come to a conclusion. @ladislas, care to share your thoughts? |
It is all about saving memory. With EventHandler we just need a single pointer to store all the callbacks we want. Whereas with FunctionPointer it is 20 bytes per callback. On a more personal note, I find it easier to use the class based callback paradigms for Gap and SecurityManager as I was defining handlers in my classes and I had to register each of them individually. Now a single registration is enough.
What do you think ?
The reasons are backward compatibility and size of the Callback object. |
The collection of What I would like to establish is a recommended pattern to design Gatt Service classes. There would be a lot of power in being able to offer a collection of premade, interoperable Gatt services that are simple to add by just calling Right now, the examples show a few different ways that aren't consistent. Some Gatt services have a That's why I like the implementation in the PR; registering an independent callback directly from the The way event handling works now is misleading as users may not know they are replacing any previously-installed callback handlers. I don't think that's ever desired behavior unless you only have one Gatt Service in your BLE profile. One way I can see the "ChainableEventHandler" concept working is: The paradigm In the simplest case where a user is trying to reduce memory usage and only needs one service they can simply set the If the user wants to have several separate Side note: aside from additional dependencies, is there any reason to not use the standard library |
@AGlass0fMilk Thanks for the detailed comment
It will consume ~8 bytes of flash per unused function in the vtable. We observed that usually pressure is more important on the RAM front so we went ahead with the EventHandler solution.
Could you open another issue where we can discuss of the concepts ? We don't want to change the GattServer API today but we can define a framework on top of it.
@paul-szczepanek-arm This might interest you. I'm happy to accept a
The main reasons to not use |
It is a fantastic idea to create a framework on top of the existing BLE APIs. The The mbed-os GitHub overlords (@0xc0170) may prefer us discussing this in a forum thread rather than an issue 😄
I can change this PR to use a base
At least for GCC, isn't exception handling (and associated code size) excluded from compilation with the mbed-os/tools/profiles/develop.json Lines 2 to 6 in ad40b1b
mbed-os/tools/profiles/develop.json Lines 17 to 22 in ad40b1b
|
He's away this week, we can start it here 😂 . On a more serious tone the forum or the example repository might be better place since this will probably lives outside Mbed OS.
It indeed is*, but there is no way to report an allocation failure to the caller as it calls
|
Closing this PR since #13727 now supersedes this. |
Event handlers can be chained if needed. You can register an event handler and have another event handler inside it. And if you want a callback you can create a callback on top of the event handler if you so require. Then you only pay for the cost of callbacks only if you need it. So it's a class that sits on top of the module you're interested in and allows you to register callbacks for individual calls. This could be even part of BLE what basically decorates the API with the callback translation. Who's going to maintain that though. @pan- As for the example issues you mentioned I don't think the problem is the example as it shows the current API, the problem is our API is still not consistent, I can't fix that in the example. |
Summary of changes
Some of the GattServer callback functions, namely:
onUpdatesEnabled
,onUpdatesDisabled
, andonConfirmationReceived
, are implemented as simple function pointers. A subsequent call to any of these functions will override and replace the callback installed by a previous call. This is inconsistent with the precedent of behavior set by otherGattServer
callback-registering functions (eg:onDataSent
).This PR replaces the simple function pointers underlying each of these callbacks with CallChains, enabling any number of application modules to register handlers for these events.
Requires #13727 to be merged first.
Impact of changes
None
Migration actions required
None
Documentation
None
Pull request type
Test results
Reviewers
@paul-szczepanek-arm @pan-