mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-24 15:56:22 +00:00
Unload plugins when killing them.
This commit is contained in:
parent
676e4893a0
commit
e0d948863e
2 changed files with 33 additions and 8 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue