PDA

View Full Version : Custom Event or Queued Connection ?



vishwanath
22nd November 2006, 11:55
Hi,

I am working on a plugin based system. Each plugin will run in a different thread. And the thread uses pthreads ( legacy code and don't intend to chage it ). Each thread is assigned a callback fucntion of the PluginManager.

Now when the plugin wants to communicate something to the PluginManager ; it call the callback function. Now the PluginManager needs to communicate to GUI.

Currently, we are calling the GUI ( Qt ) code from the callback function itself. And it works fine (as, for now there is only a single plugin ). But when there are more that one plugins then, we need to set mutex for the callback functions. And each thread has to wait for the mutex to get released :confused: , Since the callback function calls the Qt code, each thread has to wait more than necessary.

So I was thinking of using Custom Events or Queued connection. And I am confused which method to go with. Or what are the pros and cons of each ?

What I want after the implementation is, that the callback will raise an event or signal and just leave( so that the other threads need not wait for the GUI code to get executed ). And the event handler has to be invoked later. Ya, mostly like a Event mechanism.

Could you guys please help ?

Edited:
I forgot to tell that the PluginManager is not QObject sublcass, so is Queued Connection an option ? Since only QObject subclasses can emit a signal.

wysota
22nd November 2006, 13:30
In general queued connections are implemented using events, so eventually, you'll be using the same mechanism, so pick one which is easier to use for you. Of course you'll need to make your manager inherit QObject or make a small QObject which will just act as a receiver to signals/events and call the manager's methods itself. The problem I see is that you have to be using QObjects to make that all working using the signal approach and I feel using pthreads directly can confuse the connection framework so it'll probably be safer to go with custom events.

vishwanath
22nd November 2006, 13:55
hi thanks for your suggestion.. I will go ahead with custom events