PDA

View Full Version : How to use QPluginLoader to load plugin as a service so the main app won't crash?



markg85
21st December 2009, 16:19
Hi,

It seems to be a new hype those days to load plugins as a service which prevents the app loading the plugin to crash if a plugin fails. A nice example of this is google chrome. One tab can crash but others stay alive.

Now i'm wondering if it's possible with QPluginLoader to load and use a plugin as a service so the main app won't crash if the plugin does..?

I did search for this but i don't quite know how that technique is called..

Anyway, is there an howto about this stuff somewhere?

Thanx,
Mark

sngskunk
21st December 2009, 19:53
Take a look at the QtPlugins section of the Qt Documentation, what you are looking for is in the Low Level API section.

Hope that helps.

http://doc.qt.nokia.com/4.6/plugins-howto.html

markg85
22nd December 2009, 15:26
Take a look at the QtPlugins section of the Qt Documentation, what you are looking for is in the Low Level API section.

Hope that helps.

http://doc.qt.nokia.com/4.6/plugins-howto.html

I read the text there but couldn't quite figure out where the part is that causes plugins to be loaded as a service.. A howto or more detailed article on this subject would be very welcome.

ChrisW67
23rd December 2009, 07:17
You might have to explain what you mean by "as a service". You can choose to load or not load a plugin dynamically, is that what you are after? Alternatively, are you after a way to 'sandbox' a plugin so that no matter what crashing it does the remainder of the program stays running?

Qt plugins are, once loaded, essentially directly executed code. Google Chrome is more a collection of coupled processes using some sort of RPC that I think you'd have to code yourself in Qt. http://blog.chromium.org/2008/09/multi-process-architecture.html

wysota
23rd December 2009, 09:36
It seems to be a new hype those days to load plugins as a service which prevents the app loading the plugin to crash if a plugin fails.

One application is not a trend. And Chrome's tabs are not plugins by any means, at least not in the widespread meaning of that word - it's rather a master-slave architecture.

markg85
23rd December 2009, 16:52
You might have to explain what you mean by "as a service". You can choose to load or not load a plugin dynamically, is that what you are after? Alternatively, are you after a way to 'sandbox' a plugin so that no matter what crashing it does the remainder of the program stays running?


That is exactly what i want! How do you call something like that (might ease searching for it a bit ^_^)



Qt plugins are, once loaded, essentially directly executed code. Google Chrome is more a collection of coupled processes using some sort of RPC that I think you'd have to code yourself in Qt. http://blog.chromium.org/2008/09/multi-process-architecture.html


Google Chrome was just an example where one tab can crash without crashing the app. It's not a plugin.. i know.


One application is not a trend. And Chrome's tabs are not plugins by any means, at least not in the widespread meaning of that word - it's rather a master-slave architecture.

So this type of things are called a master-slave architecture? so in my case that would be a plugin master-slave architecture?

And just to clear it up. (sorry for not doing so in my first post) What i want to do is make an application. That application itself is the "plugin core". Then i want to have the ability to add plugins to that application that add functionallity to the main application. Lets take a music player as an example.

For a music player this would be the main app:
- Core plugin engine

Then to play music it requires plugins:
- Plugin to play mp3 files
- Plugin to play mms streams
- Plugin to show a gui
etcetera...

Now when you play a MMS stream and for whatever reason the mp3 plugin crashes it should just crash and leave the program working but just without that plugin.

I can make the plugin structure (i already have that) but all i'm looking into now is the possibility of letting a plugin crash without crashing the application or other plugins

Hope that helps to clear it up. Will put it in my first post as well.
edit:// oh, can't edit my first post anymore..

d_stranz
27th December 2009, 01:51
If you don't (or can't) implement a client/server (or master/slave, or whatever you want to call this type of distributed application), then I would suggest that you carefully wrap all calls from the plugin into your driver app with try/catch clauses so you can trap any execution faults that occur in the plugin and handle them appropriately.

I don't know if there is anything you can do to protect your app from memory corruption caused by the plugin; if it's going to overwrite your app's memory, you're hosed.

wysota
27th December 2009, 10:37
So this type of things are called a master-slave architecture? so in my case that would be a plugin master-slave architecture?
Your "plugin core" is a master that communicates with the other processes that do slave work on its behalf. It's a very complex architecture when talking about processes. I suggest you avoid it and use regular plugins that can crash your app. Implement them properly and they will not crash.

markg85
27th December 2009, 15:57
Your "plugin core" is a master that communicates with the other processes that do slave work on its behalf. It's a very complex architecture when talking about processes. I suggest you avoid it and use regular plugins that can crash your app. Implement them properly and they will not crash.

^_^ i think i will just do that.
I was only curious how such things could be done but i guess for the moment it's better to chech every single thing that comes from a plugin (which has to be done always anyways) and just get that working the way i want. Perhaps this can be done sometime in the future. As it stands now it's to complex for me to "just" do.

Thanx to all for the reply's.