Commit a66727ed authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Cleanup all loaded plugin instances when the PluginManager is deleted. In...

Cleanup all loaded plugin instances when the PluginManager is deleted. In contrast to the previous implementation this should deal with multiple MarbleWidget instances correctly.
Move the duplicated plugin loading code into a common template method. Rename RenderPlugin::pluginInstance to RenderPlugin::newInstance for consistency.
Delete plugin loader if the loaded plugin is not a valid Marble plugin.
Increase RenderPlugin interface version. Note that you need to have cmake recreate the .moc files now to have the plugins loaded after a rebuild.

svn path=/trunk/KDE/kdeedu/marble/; revision=1181707
parent 4a39e0ab
2010-08-19 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
* The medhod measureTool() has been moved from MarbleMap to MarbleModel.
You can continue accessing the measure tool from MarbleMap using MarbleMapp::model()->measureTool().
* The method measureTool() has been moved from MarbleMap to MarbleModel.
You can continue accessing the measure tool from MarbleMap using MarbleMap::model()->measureTool().
* The method ViewParams *viewParams() has been removed from MarbleMap in favor of ViewportParams *viewport().
Setting and getting the MapQuality can now be done using MarbleMap::setMapQuality() and MarbleMap::mapQuality().
......@@ -21,3 +21,8 @@
* Remove MarbleMap::goHome().
Use MarbleMap::flyTo(home), where home is the home position.
2010-10-01 Dennis Nienhüser <earthwings@gentoo.org>
* RenderPlugin::pluginInstance() has been renamed RenderPlugin::newInstance to be consistent with other plugin types.
You only need to change your code if you're not using the MARBLE_PLUGIN macro in custom RenderPlugins.
......@@ -47,17 +47,26 @@ class PluginManagerPrivate
QMap<QPluginLoader*, NetworkPlugin *> m_networkPluginTemplates;
QMap<QPluginLoader*, PositionProviderPlugin *> m_positionProviderPluginTemplates;
QMap<QPluginLoader*, RunnerPlugin *> m_runnerPlugins;
private:
void cleanup( const QList<QPluginLoader*> loaders );
};
PluginManagerPrivate::~PluginManagerPrivate()
{
QMap<QPluginLoader*, RunnerPlugin *>::const_iterator i = m_runnerPlugins.constBegin();
for ( ; i != m_runnerPlugins.constEnd(); ++i ) {
i.key()->unload();
delete i.key();
}
cleanup( m_renderPluginTemplates.keys() );
cleanup( m_networkPluginTemplates.keys() );
cleanup( m_positionProviderPluginTemplates.keys() );
cleanup( m_runnerPlugins.keys() );
}
/** @todo: unload other plugin types as well */
void PluginManagerPrivate::cleanup( const QList<QPluginLoader*> loaders )
{
foreach( QPluginLoader* loader, loaders ) {
loader->unload();
delete loader;
}
}
PluginManager::PluginManager( QObject *parent )
......@@ -68,14 +77,6 @@ PluginManager::PluginManager( QObject *parent )
PluginManager::~PluginManager()
{
// The plugin instances returned by QPluginLoader are shared by all QPluginLoaders.
// If more than one MarbleWidget is used, deleting them here leads to dangling
// pointers and double deletions in the other PluginManagers.
// TODO: According to QPluginLoader::unload deletion happens automatically on application
// termination, but it should be checked that this really is the case (and remove this TODO)
// qDeleteAll( d->m_renderPluginTemplates );
// qDeleteAll( d->m_networkPluginTemplates );
// qDeleteAll( d->m_positionProviderPluginTemplates );
delete d;
}
......@@ -91,53 +92,39 @@ QList<AbstractFloatItem *> PluginManager::createFloatItems() const
AbstractFloatItem * const floatItem = qobject_cast<AbstractFloatItem *>(*i);
if ( floatItem ) {
floatItemList.append( qobject_cast<AbstractFloatItem *>( floatItem->
pluginInstance() ));
newInstance() ));
}
}
return floatItemList;
}
QList<RenderPlugin *> PluginManager::createRenderPlugins() const
template<class T>
QList<T*> createPlugins( PluginManagerPrivate* d, const QMap<QPluginLoader*, T*> &loaders )
{
QList<RenderPlugin *> result;
QList<T*> result;
d->loadPlugins();
QMap<QPluginLoader*, RenderPlugin *>::const_iterator i = d->m_renderPluginTemplates.constBegin();
QMap<QPluginLoader*, RenderPlugin *>::const_iterator const end = d->m_renderPluginTemplates.constEnd();
typename QMap<QPluginLoader*, T*>::const_iterator i = loaders.constBegin();
typename QMap<QPluginLoader*, T*>::const_iterator const end = loaders.constEnd();
for (; i != end; ++i) {
result.append( (*i)->pluginInstance() );
result.append( (*i)->newInstance() );
}
return result;
}
QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
QList<RenderPlugin *> PluginManager::createRenderPlugins() const
{
QList<NetworkPlugin *> result;
d->loadPlugins();
return createPlugins( d, d->m_renderPluginTemplates );
}
QMap<QPluginLoader*, NetworkPlugin *>::const_iterator pos = d->m_networkPluginTemplates.constBegin();
QMap<QPluginLoader*, NetworkPlugin *>::const_iterator const end = d->m_networkPluginTemplates.constEnd();
for (; pos != end; ++pos ) {
result.append( (*pos)->newInstance() );
}
return result;
QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
{
return createPlugins( d, d->m_networkPluginTemplates );
}
QList<PositionProviderPlugin *> PluginManager::createPositionProviderPlugins() const
{
QList<PositionProviderPlugin *> result;
d->loadPlugins();
QMap<QPluginLoader*, PositionProviderPlugin *>::const_iterator pos = d->m_positionProviderPluginTemplates.constBegin();
QMap<QPluginLoader*, PositionProviderPlugin *>::const_iterator const end = d->m_positionProviderPluginTemplates.constEnd();
for (; pos != end; ++pos ) {
result.append( (*pos)->newInstance() );
}
return result;
return createPlugins( d, d->m_positionProviderPluginTemplates );
}
QList<RunnerPlugin *> PluginManager::runnerPlugins() const
......@@ -208,6 +195,7 @@ void PluginManagerPrivate::loadPlugins()
if ( !isPlugin ) {
mDebug() << "Plugin failure:" << fileName << "is a plugin, but it does not implement the "
<< "right interfaces or it was compiled against an old version of Marble. Ignoring it.";
delete loader;
}
} else {
mDebug() << "Plugin failure:" << fileName << "is not a valid Marble Plugin:"
......
......@@ -158,7 +158,7 @@ class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
};
#define MARBLE_PLUGIN(T) public:\
virtual RenderPlugin* pluginInstance() { return new T(); };
virtual RenderPlugin* newInstance() { return new T(); };
}
#endif
......@@ -35,7 +35,7 @@ class RenderPluginInterface: public PluginInterface, public LayerInterface
/**
* @brief Returns a new object of the plugin
*/
virtual RenderPlugin * pluginInstance() = 0;
virtual RenderPlugin * newInstance() = 0;
/**
* @brief Returns the name(s) of the backend that the plugin can render
......@@ -69,6 +69,6 @@ class RenderPluginInterface: public PluginInterface, public LayerInterface
}
Q_DECLARE_INTERFACE( Marble::RenderPluginInterface, "org.kde.Marble.RenderPluginInterface/1.06" )
Q_DECLARE_INTERFACE( Marble::RenderPluginInterface, "org.kde.Marble.RenderPluginInterface/1.07" )
#endif
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