Answer the question
In order to leave comments, you need to log in
How to call a method in C from a third-party thread that should be executed from the main thread?
Good day, friends!
I am writing a plugin for Pidgin. In it, I create a third-party thread, listen to the port there, and when a command is received, I send a message to the user. So in order to send a message you need to create create
PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, buddy);
PurpleAccount *acc = FindNeededAccount(buddy);
if(acc == NULL) {
printf("acc == NULL");
return;
}
PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acc, buddy);
purple_conv_im_send(PURPLE_CONV_IM(conv), message);
Answer the question
In order to leave comments, you need to log in
In the thread that is listening to the port, we put the received data in a queue (not forgetting about blocking). In the main thread, we check the queue (again, with a lock) and if something new has arrived, we call the desired function. Most likely, the eventloop of libpurple itself is spinning in the main thread, so you will have to check, for example, by a timer .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question