-
Notifications
You must be signed in to change notification settings - Fork 56
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
introduce void*
parameter for user data in listeners
#207
base: feat/runtime-api-enforcement
Are you sure you want to change the base?
Conversation
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.
There is suggestion on how we can keep things aligned without unnecessary branching.
core/pbcc_subscribe_event_listener.c
Outdated
pbcc_status_listener_t* pbcc_status_listener_alloc_( | ||
pubnub_subscribe_status_callback_t callback, | ||
void* user_data) | ||
{ | ||
PBCC_ALLOCATE_TYPE(listener, pbcc_status_listener_t, true, NULL); | ||
listener->callback = callback; | ||
listener->user_data = user_data; | ||
|
||
return listener; | ||
} | ||
|
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.
Do we actually need this?
Can we go in other way and do the following:
- for
pubnub_subscribe_listener_type
addPBSL_LISTENER_ON_STATUS
- Modify
pbcc_event_listener_add_status_listener
andpbcc_event_listener_remove_status_listener
?
Also we will probably will need to make a change to:
pbcc_initialize_array_(&listener->global_status, NULL))
and add destructor call:
pbcc_initialize_array_(&listener->global_status, pbcc_listener_free_))
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.
Hmm, but then we're mixing two different types of API and I'm not sure about it ;o
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.
As we discussed on DM.
pbcc_listener_c
is not generic enough to be used for this purpose.
I fixed the memory leak you found in pbcc_initialize_array_(&listener->global_status, NULL))
.
Thanks for catching it.
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.
There is a small question.
void* user_data) | ||
{ | ||
PBCC_ALLOCATE_TYPE(listener, pbcc_status_listener_t, true, NULL); | ||
listener->counter = pbref_counter_alloc(); |
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 see counter, but was it used anywhere? For pbcc_listener_t
it is used with pbcc_add_listener_
and pbcc_remove_listener_
.
@@ -623,7 +698,8 @@ enum pubnub_res pbcc_remove_listener_( | |||
|
|||
if (_listener->type == listener->type && | |||
_listener->subscription_object == listener->subscription_object && | |||
_listener->callback == listener->callback) { | |||
_listener->callback == listener->callback && | |||
_listener->user_data == listener->user_data) { |
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 wondering if we should actually check _listener->user_data == listener->user_data
when removing listeners? This forces user to store more data just to remove the listener, but if subscription objects and callbacks matches, maybe it should be enough to remove the listener?
feat: introduce
void*
parameter for user data in listenersIntroduce
void*
parameter for user data in listeners to let callbacks keep context on demand.