Commit 96e83f3e authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

don't create new NetworkPlugin instances in PluginManager, just return the factory objects

* avoids having to delete all unused plugin instances
* allows for accessing plugin metadata w/o having to create + destroy new instances
parent 9e73cf09
......@@ -86,12 +86,11 @@ HttpJob *HttpDownloadManager::Private::createJob( const QUrl& sourceUrl,
const QString &id )
{
if ( !m_networkPlugin ) {
QList<NetworkPlugin *> networkPlugins = m_pluginManager->createNetworkPlugins();
QList<const NetworkPlugin *> networkPlugins = m_pluginManager->networkPlugins();
if ( !networkPlugins.isEmpty() ) {
// FIXME: not just take the first plugin, but use some configuration setting
// take the first plugin and delete the rest
m_networkPlugin = networkPlugins.takeFirst();
qDeleteAll( networkPlugins );
// take the first plugin
m_networkPlugin = networkPlugins.first()->newInstance();
}
else {
m_downloadEnabled = false;
......
......@@ -64,30 +64,16 @@ PluginManager::~PluginManager()
delete d;
}
template<class T>
QList<T*> createPlugins( const QList<const T*> &factories )
{
QList<T*> result;
foreach ( const T *factory, factories ) {
T *instance = factory->newInstance();
Q_ASSERT( instance && "Plugin returned null when requesting a new instance." );
result.append( instance );
}
return result;
}
QList<const RenderPlugin *> PluginManager::renderPlugins() const
{
d->loadPlugins();
return d->m_renderPluginTemplates;
}
QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
QList<const NetworkPlugin *> PluginManager::networkPlugins() const
{
d->loadPlugins();
return createPlugins( d->m_networkPluginTemplates );
return d->m_networkPluginTemplates;
}
QList<const PositionProviderPlugin *> PluginManager::positionProviderPlugins() const
......
......@@ -56,10 +56,13 @@ class MARBLE_EXPORT PluginManager
QList<const RenderPlugin *> renderPlugins() const;
/**
* This methods creates a new set of plugins and transfers ownership
* of them to the client.
* @brief Returns all available NetworkPlugins.
*
* Ownership of the items remains in PluginManager.
* In order to use the NetworkPlugins, first create new instances using
* NetworkPlugin::newInstance().
*/
QList<NetworkPlugin *> createNetworkPlugins() const;
QList<const NetworkPlugin *> networkPlugins() const;
/**
* @brief Returns all available PositionProviderPlugins.
......
......@@ -33,7 +33,7 @@ void PluginManagerTest::loadPlugins()
PluginManager pm;
const int renderPlugins = pm.renderPlugins().size();
const int networkPlugins = pm.createNetworkPlugins().size();
const int networkPlugins = pm.networkPlugins().size();
const int positionPlugins = pm.positionProviderPlugins().size();
const int runnerPlugins = pm.runnerPlugins().size();
......
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