mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-05 23:09:02 +00:00
Unload plugins when killing them.
This commit is contained in:
parent
bfe1805927
commit
bf16d2addf
2 changed files with 33 additions and 8 deletions
|
@ -84,6 +84,13 @@ PluginSpec::PluginSpec()
|
|||
#else
|
||||
# error "You must define the lib suffix for your platform"
|
||||
#endif
|
||||
loader = NULL;
|
||||
}
|
||||
|
||||
PluginSpec::~PluginSpec()
|
||||
{
|
||||
delete loader;
|
||||
loader = NULL;
|
||||
}
|
||||
|
||||
QString PluginSpec::name() const
|
||||
|
@ -292,6 +299,8 @@ bool PluginSpec::isEnabled() const
|
|||
|
||||
bool PluginSpec::loadLibrary()
|
||||
{
|
||||
nlassert( loader == NULL );
|
||||
|
||||
if (m_hasError)
|
||||
return false;
|
||||
if (m_state != State::Resolved)
|
||||
|
@ -301,14 +310,16 @@ bool PluginSpec::loadLibrary()
|
|||
return reportError(QCoreApplication::translate("PluginSpec", "Loading the library failed because state != Resolved"));
|
||||
}
|
||||
|
||||
QPluginLoader loader(m_filePath);
|
||||
if (!loader.load())
|
||||
return reportError(loader.errorString());
|
||||
loader = new QPluginLoader( m_filePath );
|
||||
if (!loader->load())
|
||||
return reportError(loader->errorString());
|
||||
|
||||
IPlugin *pluginObject = qobject_cast<IPlugin *>(loader.instance());
|
||||
IPlugin *pluginObject = qobject_cast<IPlugin *>(loader->instance());
|
||||
if (!pluginObject)
|
||||
{
|
||||
loader.unload();
|
||||
loader->unload();
|
||||
delete loader;
|
||||
loader = NULL;
|
||||
return reportError(QCoreApplication::translate("PluginSpec", "Plugin is not valid (does not derive from IPlugin)"));
|
||||
}
|
||||
|
||||
|
@ -412,8 +423,17 @@ void PluginSpec::kill()
|
|||
{
|
||||
if (!m_plugin)
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,15 @@
|
|||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QXmlStreamReader>
|
||||
|
||||
class QPluginLoader;
|
||||
|
||||
namespace ExtensionSystem
|
||||
{
|
||||
|
||||
class PluginSpec: public IPluginSpec
|
||||
{
|
||||
public:
|
||||
~PluginSpec();
|
||||
virtual QString name() const;
|
||||
virtual QString version() const;
|
||||
virtual QString vendor() const;
|
||||
|
@ -54,7 +57,7 @@ public:
|
|||
|
||||
private:
|
||||
PluginSpec();
|
||||
|
||||
|
||||
bool setFileName(const QString &fileName);
|
||||
bool setSpecFileName(const QString &specFileName);
|
||||
bool readSpec();
|
||||
|
@ -96,6 +99,8 @@ private:
|
|||
IPluginManager *m_pluginManager;
|
||||
QList<PluginSpec *> m_dependencySpecs;
|
||||
|
||||
QPluginLoader *loader;
|
||||
|
||||
friend class PluginManager;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue