Skip to content
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

Open
wants to merge 3 commits into
base: feat/runtime-api-enforcement
Choose a base branch
from

Conversation

Xavrax
Copy link
Contributor

@Xavrax Xavrax commented Feb 19, 2025

feat: introduce void* parameter for user data in listeners

Introduce void* parameter for user data in listeners to let callbacks keep context on demand.

@Xavrax Xavrax changed the base branch from master to feat/runtime-api-enforcement February 19, 2025 15:03
Copy link
Contributor

@parfeon parfeon left a 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.

Comment on lines 268 to 278
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;
}

Copy link
Contributor

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:

  1. for pubnub_subscribe_listener_type add PBSL_LISTENER_ON_STATUS
  2. Modify pbcc_event_listener_add_status_listener and pbcc_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_))

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor

@parfeon parfeon left a 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();
Copy link
Contributor

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) {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants