-
Notifications
You must be signed in to change notification settings - Fork 24
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
HTTPClient callback has no way of accessing non-global data #35
Comments
Could you please expand on this? What kind of non "static/global data" were you thinking of accessing? The "setHTTPClient" call takes a function pointer that the SDK will use to make network requests. How were you imagining that it would look? |
sure :) for example, if the callback needs to access an object that isn't created in the callback itself (such as a socket, or object) there's no way to have to callback be able to access it, unless it was global typically callbacks will have a signature with a void*
so that as a client, you can do
and then later on, inside of the Countly SDK, it would do
|
for a real world example, https://libusb.sourceforge.io/api-1.0/group__libusb__hotplug.html#ga5ab3955e2110a3099497a66256fb7fab |
typically with callbacks a
void*
is passed when setting the callback, and then when something calls the callback, they will pass it thatvoid*
. this allows users to cast thevoid*
in to whatever data they need within the callback.without this, only static/global data is accessible from within the callback, which is quite limiting.
alternatively, something like
std::function
or a templated function could be used instead, to allow us to pass a lambda for the callback and capture state.The text was updated successfully, but these errors were encountered: