BT API support for C++

x_arrange
Posts: 13
Joined: Sat May 20, 2017 10:32 am

BT API support for C++

Postby x_arrange » Mon Aug 26, 2024 6:36 pm

Hi,

Dear IDF authors, this problem exists like since forever.

I wan't to write simple app on C++ but GAP/GATTS API doesn't support it. :cry:
I'm talking about event handlers.

Why esp_event_handler_register has custom arg parameter while neither esp_ble_gap_register_callback nor esp_ble_gatts_register_callback don't?

It's not so hard to add parameter and later call callback handler with it.
Please, add it in future releases

ESP_Sprite
Posts: 9761
Joined: Thu Nov 26, 2015 4:08 am

Re: BT API support for C++

Postby ESP_Sprite » Tue Aug 27, 2024 12:11 am

I agree that it's good practice to have some user pointer in callbacks in general terms, but is it really an issue here? Those callbacks you mention are system-wide (as in: you don't set the callbacks on an object or connection or whatever) so if the callback were to take a user pointer, that pointer would be exactly the same every time the callback would be called. In that case, the user pointer doesn't really add anything: you might as well use a global variable, and that saves the BT code from shuttling around the user pointer.

x_arrange
Posts: 13
Joined: Sat May 20, 2017 10:32 am

Re: BT API support for C++

Postby x_arrange » Sat Oct 05, 2024 3:41 pm

Generally you may be right. But using C++ code adds so much to readability and clearness fo code.
I want to wrap all BT function into a class where callback will be static member with class pointer passed to it as user parameter
as it can be easily done to all other APIs of ESP32.

Sadly, many years it remains as is

ESP_Sprite
Posts: 9761
Joined: Thu Nov 26, 2015 4:08 am

Re: BT API support for C++

Postby ESP_Sprite » Sun Oct 06, 2024 6:32 am

My point is, as there is only one BT subsystem, you may just as well implement your BT C++ class as a singleton. There's no need for a callback parameter that way.

Who is online

Users browsing this forum: No registered users and 103 guests