I have signals "make" and "send" registered in core class in main thread. I call call_make()
from user class in same thread. call_make()
will do some work and fetch some data from worker thread and after return it will emit signal "make".
This is code of user class
struct my_struct{
int cur_make_id;
int cur_send_id; //there may be many id's if multiple signals
}
void on_send_cb(core, gpointer data){
my_struct *user_data = (my_struct *) data;
printf("cure_make_id %d", user_data->cur_make_id); \\ this prints "4" everytime
printf("cure_send_id %d", user_data->cur_send_id); \\ this prints "2" everytime
}
void on_make_cb(core, gpointer data){
my_struct *user_data = (my_struct *) data;
printf("cure_make_id %d", user_data->cur_make_id); \\ this prints "4" everytime
for(int index=0;index<3;index++){
call_send();
user_data->cur_send_id = index;
g_signal_connect(core, "send", G_CALLBACK(on_send_cb), user_data );
}
}
void function(){
my_struct *user_data = g_malloc0(sizeof(my_struct));
for(int index=0;index<5;index++){
call_make();
user_data->cur_make_id = index;
g_signal_connect(core, "make", G_CALLBACK(on_make_cb), user_data );
}
}
I get wrong cur_make_id and cur_send_id for all signals (getting last index of for loop)
I know signal_emit and connect delayed and for loop moved forward. I want to know how can I share this user_data to callback so that I can know that this callback is for which index?
(for simplicity I made these call_make()
api's, I can't change arguments of api's)
core
? Does this code compiles? – David Raniericore
is class from where this signal emits. Yes code compiles I get signals as well. I just want to know how to shareuser_data
. I can't share full code – Its me