Commit 47939dae authored by Jan Möbius's avatar Jan Möbius

Parallel plugin preload

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8791 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6b9c621c
......@@ -812,7 +812,7 @@ private slots:
int toolboxindex_;
/// Function for loading Plugins
void loadPlugin(QString filename, bool silent);
void loadPlugin(QString filename, bool silent, QObject* _plugin = 0 );
/// Load all plugins from default plugin directory and from INI-File
void loadPlugins();
......
......@@ -96,6 +96,50 @@
#include <ACG/QtWidgets/QtFileDialog.hh>
#include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh"
class PreloadThread : public QThread
{
public:
/** \brief Preload thread constructor
*
* This constructor initializes the preloading thread.
* @param _fileName Filename of the Plugin to be loaded.
*/
PreloadThread(QString _fileName):
filename_(_fileName) {
}
public:
/** \brief get an instance of the loaded plugin
*
* This function returns an instance of the loaded plugin or 0 if something went wrong.
* This mehod has to be called from the main thread as the plugins have to stay in the
* core thread of the application.
*/
QObject* getInstance() { return loader_.instance(); }
/** \brief function to get the filename used in this preloader */
QString filename() { return filename_; }
/// If an error occured, this function will return the error message
QString getError() { return loader_.errorString(); }
/** \brief preload function
*
* This function is used in the thread to preload a plugin. The name is given in the constructor.
*/
void run() {
loader_.setFileName( filename_ );
loader_.load();
}
private:
QString filename_;
QPluginLoader loader_;
};
//== IMPLEMENTATION ==========================================================
......@@ -182,16 +226,45 @@ void Core::loadPlugins()
emit log(LOGOUT,"================================================================================");
// Try to load each file as a plugin
QTime time;
time.start();
std::vector< PreloadThread* > loaderThreads;
// Try to load each file as a plugin in a separate thread (only load them in seperate thread. Instance will be created in main thread)
for ( int i = 0 ; i < pluginlist.size() ; ++i) {
// create loader thread
PreloadThread* load = new PreloadThread(pluginlist[i]);
// remember loader thread
loaderThreads.push_back(load);
// start loader thread
load->start();
}
// Check each thread for a valid plugin
for ( uint i = 0 ; i < loaderThreads.size() ; ++i) {
if ( OpenFlipper::Options::gui() && OpenFlipperSettings().value("Core/Gui/splash",true).toBool() ) {
splashMessage_ = tr("Loading Plugin %1/%2").arg(i).arg(pluginlist.size()) ;
splashMessage_ = tr("Loading Plugin %1/%2").arg(i).arg(loaderThreads.size()) ;
splash_->showMessage( splashMessage_ , Qt::AlignBottom | Qt::AlignLeft , Qt::white);
QApplication::processEvents();
}
loadPlugin(pluginlist[i],true);
loaderThreads[i]->wait();
if ( loaderThreads[i]->getInstance() != 0 ) {
loadPlugin(loaderThreads[i]->filename(),true,loaderThreads[i]->getInstance());
} else {
emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( loaderThreads[i]->filename() ) );
emit log(LOGERR,tr("Error was : ") + loaderThreads[i]->getError() );
emit log(LOGOUT,"================================================================================");
}
delete loaderThreads[i];
}
splashMessage_ = "";
......@@ -330,8 +403,9 @@ void Core::unloadPlugin(QString name){
/** @brief Load a Plugin with given filename
* @param filename complete path + filename of the plugin
* @param silent if 'true': user isn't asked what to do if a plugin is already loaded
* @param _plugin You can provide a preloaded plugin here. If this is 0 the filename will be used to load the plugin.
*/
void Core::loadPlugin(QString filename, bool silent){
void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){
// Only load .dll under windows
if ( OpenFlipper::Options::isWindows() ) {
......@@ -347,12 +421,26 @@ void Core::loadPlugin(QString filename, bool silent){
return;
}
// Try to open the file
// This will be the reference to our plugin
QObject *plugin = 0;
// Try to open the file if we did not get a plugin,
// Otherwise use the supplied plugin pointer
if ( _plugin == 0 ) {
QPluginLoader loader( filename );
QObject *plugin = loader.instance();
plugin = loader.instance();
if ( !plugin) {
emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( filename ) );
emit log(LOGERR,tr("Error was : ") + loader.errorString() );
emit log(LOGOUT,"================================================================================");
}
} else {
plugin = _plugin;
}
// Check if a plugin has been loaded
if (plugin) {
PluginInfo info;
QString supported;
......@@ -503,7 +591,6 @@ void Core::loadPlugin(QString filename, bool silent){
emit log (LOGERR,tr("Signal objectPropertiesChanged(int) is deprecated. " ));
emit log (LOGERR,tr("The signal will be automatically emitted by the object that has been changed and the core will deliver it to the plugins!. "));
emit log (LOGERR,tr("Please remove this signal from your plugins!. "));
// connect(plugin,SIGNAL(objectPropertiesChanged(int)),this,SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection);
}
if ( checkSlot( plugin , "slotViewChanged()" ) )
......@@ -717,12 +804,6 @@ void Core::loadPlugin(QString filename, bool silent){
if ( checkSignal(plugin,"registerKey(int,Qt::KeyboardModifiers,QString,bool)") )
connect(plugin,SIGNAL( registerKey(int, Qt::KeyboardModifiers, QString, bool) ),
coreWidget_,SLOT(slotRegisterKey(int, Qt::KeyboardModifiers, QString, bool)) );
// if ( checkSlot( plugin , "slotKeyEvent(QKeyEvent*)" ) )
// connect(coreWidget_,SIGNAL(PluginKeyEvent(QKeyEvent* )), plugin,SLOT(slotKeyEvent(QKeyEvent*)));
//
// if ( checkSlot( plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) )
// connect(coreWidget_,SIGNAL(PluginKeyReleaseEvent(QKeyEvent* )), plugin,SLOT(slotKeyReleaseEvent(QKeyEvent*)));
}
//Check if the plugin supports Mouse-Interface
......@@ -1218,12 +1299,5 @@ void Core::loadPlugin(QString filename, bool silent){
}
emit log(LOGOUT,"================================================================================");
} else {
emit log(LOGERR,tr("Unable to load Plugin :\t %1").arg( filename ) );
emit log(LOGERR,tr("Error was : ") + loader.errorString() );
emit log(LOGOUT,"================================================================================");
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment