xbmc/xbmc — pull request #2846 by Montellese (2013-06-08 10:15:05+00:00)
Title: language agnostic script invocation

I started working on this over a year ago when I tried to allow python scripts for webinterfaces. The problem I ran into was that each http request already runs in its own thread and starting another thread for the python script execution through XBPython added approximately 2-3s delay in execution time. So I started to look into a way to be able to execute python scripts without going through the whole XBPython monster and without spawning another thread which resulted in an overall execution time of 50-100ms (which is a lot faster than 2-3s).

I finally found the time to more or less finish that work (not the python integration into webinterfaces) but then I thought I could just as well extend the whole idea to provide interfaces and a language agnostic manager which could be used to start any kind of script in case we ever get additional language support apart from python.

This PR introduces CScriptInvocationManager which has an Execute() and a Stop() method plus some registration/unregistration methods to register implementations of the ILanguageInvocationHandler interface. The ILanguageInvocationHandler basically is a factory to provide an instance of a specific ILanguageInvoker interface which contains the implementation to run a script of a specific language. Once everything is set up there are two ways to start a script:
* Use CScriptInvocationManager::Execute() which will try to find the proper ILanguageInvocationHander and ILanguageInvoker pair that is capable of handling the specified file (based on its extension) and spawns a CLanguageInvocationThread which will then execute the ILanguageInvoker implementation.
* Use CScriptInvocationManager::GetLanguageInvoker() to get the proper ILanguageInvoker implementation which then allows to execute the script using that invoker in any context i.e. also without any additional thread if necessary.

In case of the existing python language I have implemented CPythonInvoker (which implements ILanguageInvoker) based on XBPyThread but without the threading logic. Furthermore I have adjusted XBPython to implement the ILanguageInvocationHandler interface and registered it with the CScriptInvocationManager to handle any script files with the "*.py" extension.

I'm not a heavy addon user (youtube, trailers, version check, artwork downloader, next aired etc) so I'm certain that I only covered a small part of the possible python script scenarios in my tests. Therefore I'd be grateful if some of the python developers (like @ronie, @amet, @MartijnKaijser, ...) could give this a shot for their scripts and report back if they ran into any problems.
For the whole CPythonInvoker implementation etc I'd love to get feedback from @jimfcarroll, @cptspiff, @jmarshallnz and/or whoever else knows their way around the python integration.