forked from qt-creator/qt-creator
ExtensionSystem: Remove per-plugin object pools
Remove now-unused IPlugin::addAutoReleasedObject and IPlugin::
{add,remove}Object convenience functions that were only forwarding
to the global pool.
Adjust all related tests.
All previous users of these convenience functions are gone, and we do
not want to encourage the use of object pool anymore.
Plugins that wish to share objects to implement weak dependencies
can use the global object pool via ExtensionSystem::PluginManager::
{add,remove}Object directly.
Change-Id: Ic668ad5504af76963f6d4c69ae160438efc70db5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -61,21 +61,18 @@
|
|||||||
\li All plugin libraries are loaded in \e{root-to-leaf} order of the
|
\li All plugin libraries are loaded in \e{root-to-leaf} order of the
|
||||||
dependency tree.
|
dependency tree.
|
||||||
\li All plugins' initialize functions are called in \e{root-to-leaf} order
|
\li All plugins' initialize functions are called in \e{root-to-leaf} order
|
||||||
of the dependency tree. This is a good place to put
|
of the dependency tree. This is a good time to create objects
|
||||||
objects in the plugin manager's object pool.
|
needed by other plugins and register them via appropriate core functions
|
||||||
|
or, if a weak dependency is neceessary to be implemented, to put
|
||||||
|
them into the global object pool.
|
||||||
\li All plugins' extensionsInitialized functions are called in \e{leaf-to-root}
|
\li All plugins' extensionsInitialized functions are called in \e{leaf-to-root}
|
||||||
order of the dependency tree. At this point, plugins can
|
order of the dependency tree. At this point, plugins can
|
||||||
be sure that all plugins that depend on this plugin have
|
be sure that all plugins that depend on this plugin have
|
||||||
been initialized completely (implying that they have put
|
been initialized completely and objects these plugins wish to
|
||||||
objects in the object pool, if they want that during the
|
share have been registered or are available in the global object pool.
|
||||||
initialization sequence).
|
|
||||||
\endlist
|
\endlist
|
||||||
If library loading or initialization of a plugin fails, all plugins
|
If library loading or initialization of a plugin fails, all plugins
|
||||||
that depend on that plugin also fail.
|
that depend on that plugin also fail.
|
||||||
|
|
||||||
Plugins have access to the plugin manager
|
|
||||||
(and its object pool) via the PluginManager::instance()
|
|
||||||
function.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -102,8 +99,8 @@
|
|||||||
|
|
||||||
In this function, the plugin can assume that plugins that depend on
|
In this function, the plugin can assume that plugins that depend on
|
||||||
this plugin are fully 'up and running'. It is a good place to
|
this plugin are fully 'up and running'. It is a good place to
|
||||||
look in the plugin manager's object pool for objects that have
|
look in the global object pool for objects that have been provided
|
||||||
been provided by dependent plugins.
|
by weakly dependent plugins.
|
||||||
|
|
||||||
\sa initialize()
|
\sa initialize()
|
||||||
\sa delayedInitialize()
|
\sa delayedInitialize()
|
||||||
@@ -191,12 +188,8 @@ IPlugin::IPlugin()
|
|||||||
*/
|
*/
|
||||||
IPlugin::~IPlugin()
|
IPlugin::~IPlugin()
|
||||||
{
|
{
|
||||||
foreach (QObject *obj, d->addedObjectsInReverseOrder)
|
|
||||||
PluginManager::removeObject(obj);
|
|
||||||
qDeleteAll(d->addedObjectsInReverseOrder);
|
|
||||||
d->addedObjectsInReverseOrder.clear();
|
|
||||||
delete d;
|
delete d;
|
||||||
d = 0;
|
d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -222,40 +215,3 @@ PluginSpec *IPlugin::pluginSpec() const
|
|||||||
{
|
{
|
||||||
return d->pluginSpec;
|
return d->pluginSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\fn void IPlugin::addObject(QObject *obj)
|
|
||||||
Convenience function that registers \a obj in the plugin manager's
|
|
||||||
plugin pool by just calling PluginManager::addObject().
|
|
||||||
*/
|
|
||||||
void IPlugin::addObject(QObject *obj)
|
|
||||||
{
|
|
||||||
PluginManager::addObject(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\fn void IPlugin::addAutoReleasedObject(QObject *obj)
|
|
||||||
Convenience function for registering \a obj in the plugin manager's
|
|
||||||
plugin pool. Usually, registered objects must be removed from
|
|
||||||
the object pool and deleted by hand.
|
|
||||||
Objects added to the pool via addAutoReleasedObject are automatically
|
|
||||||
removed and deleted in reverse order of registration when
|
|
||||||
the IPlugin instance is destroyed.
|
|
||||||
\sa PluginManager::addObject()
|
|
||||||
*/
|
|
||||||
void IPlugin::addAutoReleasedObject(QObject *obj)
|
|
||||||
{
|
|
||||||
d->addedObjectsInReverseOrder.prepend(obj);
|
|
||||||
PluginManager::addObject(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\fn void IPlugin::removeObject(QObject *obj)
|
|
||||||
Convenience function that unregisters \a obj from the plugin manager's
|
|
||||||
plugin pool by just calling PluginManager::removeObject().
|
|
||||||
*/
|
|
||||||
void IPlugin::removeObject(QObject *obj)
|
|
||||||
{
|
|
||||||
PluginManager::removeObject(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ public:
|
|||||||
|
|
||||||
PluginSpec *pluginSpec() const;
|
PluginSpec *pluginSpec() const;
|
||||||
|
|
||||||
void addObject(QObject *obj);
|
|
||||||
void addAutoReleasedObject(QObject *obj);
|
|
||||||
void removeObject(QObject *obj);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void asynchronousShutdownFinished();
|
void asynchronousShutdownFinished();
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,8 @@
|
|||||||
|
|
||||||
#include "iplugin.h"
|
#include "iplugin.h"
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace ExtensionSystem {
|
namespace ExtensionSystem {
|
||||||
|
|
||||||
class PluginManager;
|
|
||||||
class PluginSpec;
|
class PluginSpec;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -40,8 +37,6 @@ class IPluginPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PluginSpec *pluginSpec;
|
PluginSpec *pluginSpec;
|
||||||
|
|
||||||
QList<QObject *> addedObjectsInReverseOrder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -25,15 +25,8 @@
|
|||||||
|
|
||||||
#include "plugin1.h"
|
#include "plugin1.h"
|
||||||
|
|
||||||
#include <qplugin.h>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
using namespace Plugin1;
|
using namespace Plugin1;
|
||||||
|
|
||||||
MyPlugin1::MyPlugin1()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyPlugin1::initialize(const QStringList &arguments, QString *errorString)
|
bool MyPlugin1::initialize(const QStringList &arguments, QString *errorString)
|
||||||
{
|
{
|
||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
#if defined(PLUGIN1_LIBRARY)
|
#if defined(PLUGIN1_LIBRARY)
|
||||||
# define PLUGIN1_EXPORT Q_DECL_EXPORT
|
# define PLUGIN1_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
@@ -44,10 +41,10 @@ class PLUGIN1_EXPORT MyPlugin1 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin1();
|
MyPlugin1() = default;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin1
|
} // namespace Plugin1
|
||||||
|
|||||||
@@ -25,14 +25,8 @@
|
|||||||
|
|
||||||
#include "plugin2.h"
|
#include "plugin2.h"
|
||||||
|
|
||||||
#include <qplugin.h>
|
|
||||||
|
|
||||||
using namespace Plugin2;
|
using namespace Plugin2;
|
||||||
|
|
||||||
MyPlugin2::MyPlugin2()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyPlugin2::initialize(const QStringList &, QString *)
|
bool MyPlugin2::initialize(const QStringList &, QString *)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
#if defined(PLUGIN2_LIBRARY)
|
#if defined(PLUGIN2_LIBRARY)
|
||||||
# define PLUGIN2_EXPORT Q_DECL_EXPORT
|
# define PLUGIN2_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
@@ -44,10 +41,10 @@ class PLUGIN2_EXPORT MyPlugin2 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin2();
|
MyPlugin2() = default;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Plugin2
|
} // Plugin2
|
||||||
|
|||||||
@@ -27,22 +27,20 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <qplugin.h>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin1;
|
using namespace Plugin1;
|
||||||
|
|
||||||
MyPlugin1::MyPlugin1()
|
MyPlugin1::~MyPlugin1()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin1::initialize(const QStringList & /*arguments*/, QString *errorString)
|
bool MyPlugin1::initialize(const QStringList & /*arguments*/, QString *errorString)
|
||||||
{
|
{
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject;
|
object1 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin1"));
|
object1->setObjectName(QLatin1String("MyPlugin1"));
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
bool found2 = false;
|
bool found2 = false;
|
||||||
bool found3 = false;
|
bool found3 = false;
|
||||||
@@ -70,8 +68,8 @@ void MyPlugin1::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject;
|
object2 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin1_running"));
|
object2->setObjectName(QLatin1String("MyPlugin1_running"));
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
#if defined(PLUGIN1_LIBRARY)
|
#if defined(PLUGIN1_LIBRARY)
|
||||||
# define PLUGIN1_EXPORT Q_DECL_EXPORT
|
# define PLUGIN1_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
@@ -44,13 +41,16 @@ class PLUGIN1_EXPORT MyPlugin1 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin1();
|
MyPlugin1() = default;
|
||||||
|
~MyPlugin1() final;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin1
|
} // namespace Plugin1
|
||||||
|
|||||||
@@ -27,22 +27,20 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <qplugin.h>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin2;
|
using namespace Plugin2;
|
||||||
|
|
||||||
MyPlugin2::MyPlugin2()
|
MyPlugin2::~MyPlugin2()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin2::initialize(const QStringList &, QString *)
|
bool MyPlugin2::initialize(const QStringList &, QString *)
|
||||||
{
|
{
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject;
|
object1 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin2"));
|
object1->setObjectName("MyPlugin2");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -52,8 +50,8 @@ void MyPlugin2::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject;
|
object2 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin2_running"));
|
object2->setObjectName("MyPlugin2_running");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
#if defined(PLUGIN2_LIBRARY)
|
#if defined(PLUGIN2_LIBRARY)
|
||||||
# define PLUGIN2_EXPORT Q_DECL_EXPORT
|
# define PLUGIN2_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
@@ -44,13 +41,16 @@ class PLUGIN2_EXPORT MyPlugin2 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin2();
|
MyPlugin2() = default;
|
||||||
|
~MyPlugin2() final;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin2
|
} // namespace Plugin2
|
||||||
|
|||||||
@@ -27,22 +27,20 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <qplugin.h>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin3;
|
using namespace Plugin3;
|
||||||
|
|
||||||
MyPlugin3::MyPlugin3()
|
MyPlugin3::~MyPlugin3()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin3::initialize(const QStringList & /*arguments*/, QString *errorString)
|
bool MyPlugin3::initialize(const QStringList & /*arguments*/, QString *errorString)
|
||||||
{
|
{
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject;
|
object1 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin3"));
|
object1->setObjectName(QLatin1String("MyPlugin3"));
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
bool found2 = false;
|
bool found2 = false;
|
||||||
foreach (QObject *object, ExtensionSystem::PluginManager::allObjects()) {
|
foreach (QObject *object, ExtensionSystem::PluginManager::allObjects()) {
|
||||||
@@ -61,7 +59,7 @@ void MyPlugin3::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject;
|
object2 = new QObject(this);
|
||||||
obj->setObjectName(QLatin1String("MyPlugin3_running"));
|
object2->setObjectName(QLatin1String("MyPlugin3_running"));
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
#if defined(PLUGIN3_LIBRARY)
|
#if defined(PLUGIN3_LIBRARY)
|
||||||
# define PLUGIN3_EXPORT Q_DECL_EXPORT
|
# define PLUGIN3_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
@@ -44,13 +41,16 @@ class PLUGIN3_EXPORT MyPlugin3 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin3.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin3.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin3();
|
MyPlugin3() = default;
|
||||||
|
~MyPlugin3() final;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin3
|
} // namespace Plugin3
|
||||||
|
|||||||
@@ -27,21 +27,20 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin1;
|
using namespace Plugin1;
|
||||||
|
|
||||||
MyPlugin1::MyPlugin1()
|
MyPlugin1::~MyPlugin1()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin1::initialize(const QStringList & /*arguments*/, QString *errorString)
|
bool MyPlugin1::initialize(const QStringList & /*arguments*/, QString *errorString)
|
||||||
{
|
{
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject(this);
|
object1 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin1");
|
object1->setObjectName("MyPlugin1");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
bool found2 = false;
|
bool found2 = false;
|
||||||
bool found3 = false;
|
bool found3 = false;
|
||||||
@@ -69,7 +68,7 @@ void MyPlugin1::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject(this);
|
object2 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin1_running");
|
object2->setObjectName("MyPlugin1_running");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace Plugin1 {
|
namespace Plugin1 {
|
||||||
|
|
||||||
class MyPlugin1 : public ExtensionSystem::IPlugin
|
class MyPlugin1 : public ExtensionSystem::IPlugin
|
||||||
@@ -38,13 +35,16 @@ class MyPlugin1 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin1.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin1();
|
MyPlugin1() = default;
|
||||||
|
~MyPlugin1() final;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin1
|
} // namespace Plugin1
|
||||||
|
|||||||
@@ -27,22 +27,21 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin2;
|
using namespace Plugin2;
|
||||||
|
|
||||||
MyPlugin2::MyPlugin2()
|
MyPlugin2::~MyPlugin2()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin2::initialize(const QStringList & /*arguments*/, QString *errorString)
|
bool MyPlugin2::initialize(const QStringList & /*arguments*/, QString *errorString)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorString)
|
Q_UNUSED(errorString)
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject(this);
|
object1 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin2");
|
object1->setObjectName("MyPlugin2");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ void MyPlugin2::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject(this);
|
object2 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin2_running");
|
object2->setObjectName("MyPlugin2_running");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace Plugin2 {
|
namespace Plugin2 {
|
||||||
|
|
||||||
class MyPlugin2 : public ExtensionSystem::IPlugin
|
class MyPlugin2 : public ExtensionSystem::IPlugin
|
||||||
@@ -38,13 +35,16 @@ class MyPlugin2 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin2.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin2();
|
MyPlugin2() = default;
|
||||||
|
~MyPlugin2() final;
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin2
|
} // namespace Plugin2
|
||||||
|
|||||||
@@ -27,24 +27,23 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
using namespace Plugin3;
|
using namespace Plugin3;
|
||||||
|
|
||||||
MyPlugin3::MyPlugin3()
|
MyPlugin3::~MyPlugin3()
|
||||||
: initializeCalled(false)
|
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object1);
|
||||||
|
ExtensionSystem::PluginManager::removeObject(object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyPlugin3::initialize(const QStringList & /*arguments*/, QString *errorString)
|
bool MyPlugin3::initialize(const QStringList & /*arguments*/, QString *errorString)
|
||||||
{
|
{
|
||||||
initializeCalled = true;
|
initializeCalled = true;
|
||||||
QObject *obj = new QObject(this);
|
object1 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin3");
|
object1->setObjectName("MyPlugin3");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object1);
|
||||||
|
|
||||||
bool found2 = false;
|
bool found2 = false;
|
||||||
foreach (QObject *object, ExtensionSystem::PluginManager::instance()->allObjects()) {
|
foreach (QObject *object, ExtensionSystem::PluginManager::allObjects()) {
|
||||||
if (object->objectName() == "MyPlugin2")
|
if (object->objectName() == "MyPlugin2")
|
||||||
found2 = true;
|
found2 = true;
|
||||||
}
|
}
|
||||||
@@ -60,7 +59,7 @@ void MyPlugin3::extensionsInitialized()
|
|||||||
if (!initializeCalled)
|
if (!initializeCalled)
|
||||||
return;
|
return;
|
||||||
// don't do this at home, it's just done here for the test
|
// don't do this at home, it's just done here for the test
|
||||||
QObject *obj = new QObject(this);
|
object2 = new QObject(this);
|
||||||
obj->setObjectName("MyPlugin3_running");
|
object2->setObjectName("MyPlugin3_running");
|
||||||
addAutoReleasedObject(obj);
|
ExtensionSystem::PluginManager::addObject(object2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace Plugin3 {
|
namespace Plugin3 {
|
||||||
|
|
||||||
class MyPlugin3 : public ExtensionSystem::IPlugin
|
class MyPlugin3 : public ExtensionSystem::IPlugin
|
||||||
@@ -38,13 +35,16 @@ class MyPlugin3 : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin3.json")
|
Q_PLUGIN_METADATA(IID "plugin" FILE "plugin3.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyPlugin3();
|
MyPlugin3() = default;
|
||||||
|
~MyPlugin3();
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorString);
|
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||||
void extensionsInitialized();
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeCalled;
|
bool initializeCalled = false;
|
||||||
|
QObject *object1 = nullptr;
|
||||||
|
QObject *object2 = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plugin3
|
} // namespace Plugin3
|
||||||
|
|||||||
Reference in New Issue
Block a user