Unload plugins when killing them.

This commit is contained in:
dfighter1985 2014-06-18 01:15:39 +02:00
parent bfe1805927
commit bf16d2addf
2 changed files with 33 additions and 8 deletions

View file

@ -84,6 +84,13 @@ PluginSpec::PluginSpec()
#else #else
# error "You must define the lib suffix for your platform" # error "You must define the lib suffix for your platform"
#endif #endif
loader = NULL;
}
PluginSpec::~PluginSpec()
{
delete loader;
loader = NULL;
} }
QString PluginSpec::name() const QString PluginSpec::name() const
@ -292,6 +299,8 @@ bool PluginSpec::isEnabled() const
bool PluginSpec::loadLibrary() bool PluginSpec::loadLibrary()
{ {
nlassert( loader == NULL );
if (m_hasError) if (m_hasError)
return false; return false;
if (m_state != State::Resolved) if (m_state != State::Resolved)
@ -301,14 +310,16 @@ bool PluginSpec::loadLibrary()
return reportError(QCoreApplication::translate("PluginSpec", "Loading the library failed because state != Resolved")); return reportError(QCoreApplication::translate("PluginSpec", "Loading the library failed because state != Resolved"));
} }
QPluginLoader loader(m_filePath); loader = new QPluginLoader( m_filePath );
if (!loader.load()) if (!loader->load())
return reportError(loader.errorString()); return reportError(loader->errorString());
IPlugin *pluginObject = qobject_cast<IPlugin *>(loader.instance()); IPlugin *pluginObject = qobject_cast<IPlugin *>(loader->instance());
if (!pluginObject) if (!pluginObject)
{ {
loader.unload(); loader->unload();
delete loader;
loader = NULL;
return reportError(QCoreApplication::translate("PluginSpec", "Plugin is not valid (does not derive from IPlugin)")); return reportError(QCoreApplication::translate("PluginSpec", "Plugin is not valid (does not derive from IPlugin)"));
} }
@ -412,8 +423,17 @@ void PluginSpec::kill()
{ {
if (!m_plugin) if (!m_plugin)
return; return;
delete m_plugin;
m_plugin = 0; bool b = loader->unload();
if( !b )
{
nlinfo( "Plugin %s couldn't be unloaded.", this->m_name.toAscii().data() );
}
//delete m_plugin;
m_plugin = NULL;
delete loader;
loader = NULL;
m_state = State::Deleted; m_state = State::Deleted;
} }

View file

@ -25,12 +25,15 @@
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QXmlStreamReader> #include <QtCore/QXmlStreamReader>
class QPluginLoader;
namespace ExtensionSystem namespace ExtensionSystem
{ {
class PluginSpec: public IPluginSpec class PluginSpec: public IPluginSpec
{ {
public: public:
~PluginSpec();
virtual QString name() const; virtual QString name() const;
virtual QString version() const; virtual QString version() const;
virtual QString vendor() const; virtual QString vendor() const;
@ -54,7 +57,7 @@ public:
private: private:
PluginSpec(); PluginSpec();
bool setFileName(const QString &fileName); bool setFileName(const QString &fileName);
bool setSpecFileName(const QString &specFileName); bool setSpecFileName(const QString &specFileName);
bool readSpec(); bool readSpec();
@ -96,6 +99,8 @@ private:
IPluginManager *m_pluginManager; IPluginManager *m_pluginManager;
QList<PluginSpec *> m_dependencySpecs; QList<PluginSpec *> m_dependencySpecs;
QPluginLoader *loader;
friend class PluginManager; friend class PluginManager;
}; };