Commit 9effa2ec authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Refactoring for dtkObjectManager handling.

parent 4813e76b
......@@ -7,3 +7,4 @@
%Include dtkCorePluginManager.sip
%Include dtkCoreLayerManager.sip
%Include dtkArray.sip
%Include dtkObjectManager.sip
class dtkObjectManager : public QObject
{
%TypeHeaderCode
#include <dtkCore/dtkObjectManager.h>
#include <QtCore>
%End
public:
static dtkObjectManager *instance();
public:
int count();
public slots:
void add(const QVariant&);
void add(const QVariant&, const QString&);
bool del(const QVariant&);
public:
QVariant value(const QString&) const;
QStringList keys() const;
private:
dtkObjectManager();
~dtkObjectManager();
};
......@@ -37,7 +37,10 @@ set(${PROJECT_NAME}_HEADERS
dtkCorePluginBase.h
dtkCorePluginFactory
dtkCorePluginFactory.h
dtkCorePluginFactory_p.h
dtkCorePluginFactory.tpp
dtkCorePluginFactoryRecorder
dtkCorePluginFactoryRecorder.h
dtkCorePluginFactoryTemplate
dtkCorePluginFactoryTemplate.h
dtkCorePluginManager
......@@ -68,7 +71,9 @@ set(${PROJECT_NAME}_SOURCES
dtkCoreSettings.cpp
dtkArrayData.cpp
dtkCoreLayerManager.cpp
dtkCorePluginFactory_p.cpp
dtkCorePluginFactory.cpp
dtkCorePluginFactoryRecorder.cpp
dtkCorePluginManagerHandler.cpp
dtkCorePluginManagerRecorder.cpp
dtkObjectManager.cpp)
......@@ -104,7 +109,8 @@ if(DTK_BUILD_WRAPPERS)
sip${PROJECT_NAME}dtkArray2400.cpp
sip${PROJECT_NAME}dtkArray3800.cpp
sip${PROJECT_NAME}dtkCoreLayerManager.cpp
sip${PROJECT_NAME}dtkCorePluginManagerBase.cpp)
sip${PROJECT_NAME}dtkCorePluginManagerBase.cpp
sip${PROJECT_NAME}dtkObjectManager.cpp)
dtk_wrap_sip(${PROJECT_NAME} ${PROJECT_NAME}_SOURCES_WRAP dtkCore ${CMAKE_SOURCE_DIR}/sip/dtkCore/dtkCoremod.sip "${${PROJECT_NAME}_SIP_WRAPPERS}" ${${PROJECT_NAME}_WRAP_DEPENDS})
endif(SIP_FOUND)
......
......@@ -7,6 +7,7 @@
#include "dtkCoreLayerManager.h"
#include "dtkCorePlugin.h"
#include "dtkCorePluginFactory.h"
#include "dtkCorePluginFactoryRecorder.h"
#include "dtkCorePluginFactoryTemplate.h"
#include "dtkCorePluginManager.h"
#include "dtkCorePluginManagerHandler.h"
......
......@@ -17,6 +17,7 @@
#include <QtCore>
#include "dtkCorePluginManager.h"
#include "dtkCorePluginFactory.h"
// /////////////////////////////////////////////////////////////////
// dtkCoreLayerManagerPrivate implementation
......@@ -28,7 +29,10 @@ public:
bool verbose_loading;
bool auto_loading;
dtkObjectManager *object_manager;
QHash<QString, dtkCorePluginManagerBase *> plugin_managers;
QHash<QString, dtkCorePluginFactoryBase *> plugin_factories;
};
// /////////////////////////////////////////////////////////////////
......@@ -39,6 +43,7 @@ dtkCoreLayerManager::dtkCoreLayerManager(void) : d(new dtkCoreLayerManagerPrivat
{
d->verbose_loading = false;
d->auto_loading = true;
d->object_manager = nullptr;
}
dtkCoreLayerManager::~dtkCoreLayerManager(void)
......@@ -52,6 +57,11 @@ void dtkCoreLayerManager::record(const QString& plugin_manager_name, dtkCorePlug
d->plugin_managers[plugin_manager_name] = plugin_manager;
}
void dtkCoreLayerManager::record(const QString& plugin_factory_name, dtkCorePluginFactoryBase *plugin_factory)
{
d->plugin_factories[plugin_factory_name] = plugin_factory;
}
void dtkCoreLayerManager::initialize(void)
{
this->initialize(QString());
......@@ -62,6 +72,11 @@ void dtkCoreLayerManager::initialize(const QString& path)
for (auto pm : d->plugin_managers) {
pm->initialize(path);
}
if (d->object_manager) {
for (auto pf : d->plugin_factories) {
pf->connect(d->object_manager);
}
}
}
void dtkCoreLayerManager::uninitialize(void)
......@@ -69,6 +84,11 @@ void dtkCoreLayerManager::uninitialize(void)
for (auto pm : d->plugin_managers) {
pm->uninitialize();
}
if (d->object_manager) {
for (auto pf : d->plugin_factories) {
pf->disconnect(d->object_manager);
}
}
}
void dtkCoreLayerManager::setVerboseLoading(bool value)
......@@ -97,5 +117,15 @@ bool dtkCoreLayerManager::autoLoading(void) const
return d->auto_loading;
}
void dtkCoreLayerManager::setObjectManager(dtkObjectManager * manager)
{
d->object_manager = manager;
}
dtkObjectManager *dtkCoreLayerManager::objectManager(void) const
{
return d->object_manager;
}
//
// dtkCoreLayerManager.cpp ends here
......@@ -20,7 +20,8 @@
class QString;
class dtkCorePluginManagerBase;
class dtkCoreLayerManagerPrivate;
class dtkCorePluginFactoryBase;
class dtkObjectManager;
// /////////////////////////////////////////////////////////////////
// dtkCoreLayerManager interface
......@@ -34,6 +35,7 @@ public:
public:
void record(const QString& plugin_manager_name, dtkCorePluginManagerBase *plugin_manager);
void record(const QString& plugin_factory_name, dtkCorePluginFactoryBase *plugin_factory);
void initialize(void);
void initialize(const QString& path);
......@@ -46,8 +48,11 @@ public:
void setAutoLoading(bool value);
bool autoLoading(void) const;
void setObjectManager(dtkObjectManager *manager);
dtkObjectManager *objectManager(void) const;
private:
dtkCoreLayerManagerPrivate *d;
class dtkCoreLayerManagerPrivate *d;
};
//
......
......@@ -113,7 +113,8 @@
\
namespace _private \
{ \
dtkCorePluginManagerRecorder recorder(&LayerName::manager(), &pluginManager(), #type); \
dtkCorePluginManagerRecorder mrecorder(&LayerName::manager(), &pluginManager(), #type); \
dtkCorePluginFactoryRecorder frecorder(&LayerName::manager(), &pluginFactory(), #type); \
} \
}
......
......@@ -4,36 +4,6 @@
* Created: jeu. avril 3 08:44:47 2014 (+0200)
*/
#include "dtkCorePluginFactory.h"
#include "dtkObjectManager.h"
#include <QtCore>
/*!
\class dtkCorePluginFactoryPrivate
\inmodule dtkCore
\brief The dtkCorePluginFactoryPrivate class add signals to register object to object manager.
*/
/*! \fn void dtkCorePluginFactoryPrivate::touch(int type, void *t)
Emits signal created(QVariant).
The QVariant is defined by the QMetaType \a type and the address of the object \a t.
*/
void dtkCorePluginFactoryPrivate::touch(const QVariant &v) const
{
emit created(v);
}
/*! \fn void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager)
Enables connection to \a manager.
*/
void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager) const
{
QObject::connect(this, SIGNAL(created(const QVariant&)), manager, SLOT(add(const QVariant&)));
}
/*!
\class dtkCorePluginFactory
\inmodule dtkCore
......
......@@ -14,40 +14,31 @@
#pragma once
#include <QtCore>
#include <QtDebug>
#include <dtkCoreExport.h>
class dtkObjectManager;
#include <QtCore>
// ///////////////////////////////////////////////////////////////////
//
// dtkCorePluginFactoryBase
// ///////////////////////////////////////////////////////////////////
class DTKCORE_EXPORT dtkCorePluginFactoryPrivate : public QObject
{
Q_OBJECT
signals:
void created(const QVariant&) const;
public:
void touch(const QVariant&) const;
class dtkObjectManager;
class DTKCORE_EXPORT dtkCorePluginFactoryBase : public QObject
{
public:
void connect(dtkObjectManager *manager) const;
virtual void connect(dtkObjectManager *manager) const = 0;
virtual void disconnect(dtkObjectManager *manager) const = 0;
};
#include "dtkCorePluginBase.h"
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginFactory
// ///////////////////////////////////////////////////////////////////
class dtkCorePluginBase;
template <typename T> class dtkCorePluginTuner;
template <typename T> class dtkCorePluginFactory : public QObject
template <typename T> class dtkCorePluginFactory : public dtkCorePluginFactoryBase
{
public:
dtkCorePluginFactory(void);
......@@ -70,15 +61,16 @@ public:
QStringList keys(void) const;
public:
void connect(dtkObjectManager *manager) const;
void connect(dtkObjectManager *manager) const override;
void disconnect(dtkObjectManager *manager) const override;
private:
QHash<QString, creator> creators;
QHash<QString, dtkCorePluginBase*> creators_plugins;
QHash<QString, dtkCorePluginBase *> creators_plugins;
QHash<QString, tunerCreator> tuner_creators;
private:
dtkCorePluginFactoryPrivate *m_d;
class dtkCorePluginFactoryPrivate *m_d;
};
// ///////////////////////////////////////////////////////////////////
......
......@@ -17,16 +17,18 @@
#include <dtkLog>
#include <dtkMeta>
#include "dtkCorePluginFactory_p.h"
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginFactory implementation
// ///////////////////////////////////////////////////////////////////
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void) : m_d(new dtkCorePluginFactoryPrivate)
template <typename T> inline dtkCorePluginFactory<T>::dtkCorePluginFactory(void) : m_d(new dtkCorePluginFactoryPrivate)
{
}
template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
template <typename T> inline dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
{
delete m_d;
}
......@@ -35,7 +37,7 @@ template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
// Type creator registration
// /////////////////////////////////////////////////////////////////
template <typename T> void dtkCorePluginFactory<T>::record(const QString& key, creator func)
template <typename T> inline void dtkCorePluginFactory<T>::record(const QString& key, creator func)
{
if (this->creators.contains(key)) {
dtkTrace() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
......@@ -45,7 +47,7 @@ template <typename T> void dtkCorePluginFactory<T>::record(const QString& key, c
this->creators.insert(key, func);
}
template <typename T> void dtkCorePluginFactory<T>::recordPlugin(const QString& key, dtkCorePluginBase *plugin)
template <typename T> inline void dtkCorePluginFactory<T>::recordPlugin(const QString& key, dtkCorePluginBase *plugin)
{
if (this->creators_plugins.contains(key)) {
qDebug() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
......@@ -55,7 +57,7 @@ template <typename T> void dtkCorePluginFactory<T>::recordPlugin(const QString&
this->creators_plugins.insert(key, plugin);
}
template <typename T> void dtkCorePluginFactory<T>::recordTuner(const QString& key, tunerCreator func)
template <typename T> inline void dtkCorePluginFactory<T>::recordTuner(const QString& key, tunerCreator func)
{
if (this->tuner_creators.contains(key)) {
qDebug() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
......@@ -69,7 +71,7 @@ template <typename T> void dtkCorePluginFactory<T>::recordTuner(const QString& k
// Type creator invokation
// /////////////////////////////////////////////////////////////////
template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key) const
template <typename T> inline T *dtkCorePluginFactory<T>::create(const QString& key) const
{
T *obj = nullptr;
if (this->creators.contains(key)) {
......@@ -86,7 +88,7 @@ template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key) con
return obj;
}
template <typename T> dtkCorePluginTuner<T> *dtkCorePluginFactory<T>::createTuner(const QString& key) const
template <typename T> inline dtkCorePluginTuner<T> *dtkCorePluginFactory<T>::createTuner(const QString& key) const
{
if (!this->tuner_creators.contains(key))
return NULL;
......@@ -99,7 +101,7 @@ template <typename T> dtkCorePluginTuner<T> *dtkCorePluginFactory<T>::createTune
// Type creator inspection
// /////////////////////////////////////////////////////////////////
template <typename T> QStringList dtkCorePluginFactory<T>::keys(void) const
template <typename T> inline QStringList dtkCorePluginFactory<T>::keys(void) const
{
QStringList lkeys = this->creators.keys() ;
lkeys << this->creators_plugins.keys();
......@@ -110,10 +112,15 @@ template <typename T> QStringList dtkCorePluginFactory<T>::keys(void) const
//
// ///////////////////////////////////////////////////////////////////
template <typename T> void dtkCorePluginFactory<T>::connect(dtkObjectManager *manager) const
template <typename T> inline void dtkCorePluginFactory<T>::connect(dtkObjectManager *manager) const
{
m_d->connect(manager);
}
template <typename T> inline void dtkCorePluginFactory<T>::disconnect(dtkObjectManager *manager) const
{
m_d->disconnect(manager);
}
//
// dtkCorePluginFactory_t.h ends here
#include "dtkCorePluginFactoryRecorder.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkCorePluginFactoryRecorder.h"
#include "dtkCoreLayerManager.h"
// /////////////////////////////////////////////////////////////////
// dtkCorePluginFactoryRecorder implementation
// /////////////////////////////////////////////////////////////////
dtkCorePluginFactoryRecorder::dtkCorePluginFactoryRecorder(dtkCoreLayerManager *layer_manager, dtkCorePluginFactoryBase *plugin_factory, const QString& plugin_name)
{
layer_manager->record(plugin_name, plugin_factory);
}
//
// dtkCorePluginFactoryRecorder.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkCoreExport.h>
class QString;
class dtkCoreLayerManager;
class dtkCorePluginFactoryBase;
// /////////////////////////////////////////////////////////////////
// dtkCorePluginFactoryRecorder interface
// /////////////////////////////////////////////////////////////////
class DTKCORE_EXPORT dtkCorePluginFactoryRecorder
{
public:
explicit dtkCorePluginFactoryRecorder(dtkCoreLayerManager *layer_manager, dtkCorePluginFactoryBase *plugin_factory, const QString& plugin_name);
~dtkCorePluginFactoryRecorder(void) = default;
};
//
// dtkCorePluginFactoryRecorder.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkCorePluginFactory_p.h"
#include "dtkObjectManager.h"
/*!
\class dtkCorePluginFactoryPrivate
\inmodule dtkCore
\brief The dtkCorePluginFactoryPrivate class add signals to register object to object manager.
*/
/*! \fn void dtkCorePluginFactoryPrivate::touch(int type, void *t)
Emits signal created(QVariant).
The QVariant is defined by the QMetaType \a type and the address of the object \a t.
*/
void dtkCorePluginFactoryPrivate::touch(const QVariant &v) const
{
emit created(v);
}
/*! \fn void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager)
Enables connection to \a manager.
*/
void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager) const
{
QObject::connect(this, SIGNAL(created(const QVariant&)), manager, SLOT(add(const QVariant&)));
}
/*! \fn void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager)
Enables connection to \a manager.
*/
void dtkCorePluginFactoryPrivate::disconnect(dtkObjectManager *manager) const
{
QObject::disconnect(this, SIGNAL(created(const QVariant&)), manager, SLOT(add(const QVariant&)));
}
//
// dtkCorePluginFactory_p.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkCoreExport.h>
#include <QtCore>
class dtkObjectManager;
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class DTKCORE_EXPORT dtkCorePluginFactoryPrivate : public QObject
{
Q_OBJECT
signals:
void created(const QVariant&) const;
public:
void touch(const QVariant&) const;
public:
void connect(dtkObjectManager *manager) const;
void disconnect(dtkObjectManager *manager) const;
};
//
// dtkCorePluginFactory_p.h ends here
......@@ -25,10 +25,5 @@ dtkCorePluginManagerRecorder::dtkCorePluginManagerRecorder(dtkCoreLayerManager *
layer_manager->record(plugin_manager_name, plugin_manager);
}
dtkCorePluginManagerRecorder::~dtkCorePluginManagerRecorder(void)
{
}
//
// dtkCorePluginManagerRecorder.cpp ends here
......@@ -29,7 +29,7 @@ class DTKCORE_EXPORT dtkCorePluginManagerRecorder
{
public:
explicit dtkCorePluginManagerRecorder(dtkCoreLayerManager *layer_manager, dtkCorePluginManagerBase *plugin_manager, const QString& plugin_manager_name);
~dtkCorePluginManagerRecorder(void);
~dtkCorePluginManagerRecorder(void) = default;
};
//
......
......@@ -33,6 +33,11 @@ int dtkObjectManager::count(void)
return d->instances.count();
}
void dtkObjectManager::add(const QVariant& instance, const QString& name)
{
d->instances.insert(name, instance);
}
void dtkObjectManager::add(const QVariant& instance)
{
static int count = 0;
......
......@@ -29,6 +29,7 @@ public:
int count(void);
public slots:
void add(const QVariant&, const QString&);
void add(const QVariant&);
bool del(const QVariant&);
......
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