Commit 90a62a35 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Merge branch 'master' into thibaud

parents d0382055 499431a4
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Mon Feb 4 10:17:21 2013 (+0100)
## Version:
## Last-Updated: Tue Feb 26 14:45:18 2013 (+0100)
## Last-Updated: Thu Feb 28 18:06:22 2013 (+0100)
## By: Julien Wintz
## Update #: 118
## Update #: 119
######################################################################
##
### Change Log:
......@@ -75,6 +75,7 @@ find_package(Qt5Widgets REQUIRED)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src/dtk)
include_directories(${PROJECT_SOURCE_DIR}/src/dtkLog)
include_directories(${PROJECT_SOURCE_DIR}/src/dtkCore)
include_directories(${PROJECT_SOURCE_DIR}/src/dtkDistributed)
include_directories(${PROJECT_SOURCE_DIR}/src/dtkTest)
......
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Tue Feb 5 10:26:22 2013 (+0100)
## Version:
## Last-Updated: Fri Feb 8 15:13:12 2013 (+0100)
## Last-Updated: Thu Feb 28 18:56:45 2013 (+0100)
## By: Julien Wintz
## Update #: 18
## Update #: 21
######################################################################
##
### Change Log:
......@@ -22,6 +22,8 @@ set(dtk_INCLUDE_DIRS
"@CMAKE_SOURCE_DIR@"
"@CMAKE_SOURCE_DIR@/src"
"@CMAKE_SOURCE_DIR@/src/dtk"
"@CMAKE_SOURCE_DIR@/src/dtkLog"
"@CMAKE_SOURCE_DIR@/src/dtkCore"
"@CMAKE_SOURCE_DIR@/src/dtkDistributed"
"@CMAKE_SOURCE_DIR@/src/dtkTest")
......
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Fri Feb 8 16:49:52 2013 (+0100)
## Version:
## Last-Updated: 2013 Thu Feb 28 14:27:21 (+0100)
## By: Thibaud Kloczko
## Update #: 17
## Last-Updated: Thu Feb 28 18:39:32 2013 (+0100)
## By: Julien Wintz
## Update #: 27
######################################################################
##
### Change Log:
......@@ -19,13 +19,22 @@ project(dtkCore)
## #################################################################
set(${PROJECT_NAME}_HEADERS
dtkCore
dtkCore.h
dtkCoreObject
dtkCoreObject.h
dtkCorePlugin
dtkCorePlugin.h
dtkCorePluginFactory
dtkCorePluginFactory.h
dtkCorePluginFactory.tpp
dtkCorePluginManager
dtkCorePluginManager.h
dtkCorePluginManager.tpp
dtkCoreSettings
dtkCoreSettings.h)
set(${PROJECT_NAME}_SOURCES
dtkCorePluginManager.cpp
dtkCoreSettings.cpp)
## #################################################################
......
#include "dtkCore.h"
#include "dtkCoreObject.h"
#include "dtkCorePlugin.h"
#include "dtkCorePluginFactory.h"
#include "dtkCorePluginManager.h"
#include "dtkCoreSettings.h"
/* dtkCore.h ---
*
* Author: Julien Wintz
* Created: Thu Feb 28 16:28:31 2013 (+0100)
* Version:
* Last-Updated: Thu Feb 28 16:28:38 2013 (+0100)
* By: Julien Wintz
* Update #: 2
*/
/* Change Log:
*
*/
#pragma once
#include "dtkCoreObject.h"
/* dtkCoreObject.h ---
*
* Author: Julien Wintz
* Created: Thu Feb 28 17:59:25 2013 (+0100)
* Version:
* Last-Updated: Thu Feb 28 17:59:44 2013 (+0100)
* By: Julien Wintz
* Update #: 2
*/
/* Change Log:
*
*/
#pragma once
#include <QtCore>
class dtkCoreObject : public QObject {};
#include "dtkCorePlugin.h"
/* dtkCorePlugin.h ---
*
* Author: Julien Wintz
* Created: Thu Feb 28 16:15:02 2013 (+0100)
* Version:
* Last-Updated: Thu Feb 28 18:55:08 2013 (+0100)
* By: Julien Wintz
* Update #: 88
*/
/* Change Log:
*
*/
#pragma once
#include "dtkCorePluginManager"
#include "dtkCorePluginFactory"
// ///////////////////////////////////////////////////////////////////
// DTK_DECLARE_OBJECT
// ///////////////////////////////////////////////////////////////////
#define DTK_DECLARE_OBJECT(type) \
Q_DECLARE_METATYPE(type)
// ///////////////////////////////////////////////////////////////////
// DTK_DECLARE_PLUGIN
// ///////////////////////////////////////////////////////////////////
#define DTK_DECLARE_PLUGIN(type) \
class type##Plugin : public QObject \
{ \
Q_OBJECT \
\
public: \
type##Plugin(void) {} \
virtual ~type##Plugin(void) {} \
\
public: \
virtual void initialize(void) = 0; \
virtual void uninitialize(void) = 0; \
}; \
// ///////////////////////////////////////////////////////////////////
// DTK_DECLARE_PLUGIN_FACTORY
// ///////////////////////////////////////////////////////////////////
#define DTK_DECLARE_PLUGIN_FACTORY(type) \
class type##PluginFactory : public dtkCorePluginFactory<type> {};
// ///////////////////////////////////////////////////////////////////
// DTK_DECLARE_PLUGIN_MANAGER
// ///////////////////////////////////////////////////////////////////
#define DTK_DECLARE_PLUGIN_MANAGER(type) \
class type##PluginManager : public dtkCorePluginManager<type##Plugin> {};
/* dtkCorePluginFactory.h ---
*
* Author: Thibaud Kloczko
* Created: 2013 Thu Feb 28 14:13:28 (+0100)
* Author: Julien Wintz
* Created: Thu Feb 28 15:43:06 2013 (+0100)
* Version:
* Last-Updated: Thu Feb 28 15:45:40 2013 (+0100)
* By: Julien Wintz
* Update #: 7
*/
/* Commentary:
*
*/
/* Change log:
/* Change Log:
*
*/
......@@ -16,29 +16,34 @@
#include <QtCore>
//template <typename T> class dtkCorePluginFactoryPrivate;
template <typename T> class dtkCorePluginFactory : public QObject
{
public:
typedef T *(*creator) (void);
public:
dtkCorePluginFactory(void);
~dtkCorePluginFactory(void);
public:
T *create(const QString& key);
#pragma mark -
#pragma Type creator definition
public:
QStringList keys(void);
typedef T *(*creator) (void);
#pragma mark -
#pragma Type creator registration
public:
void record(QString key, creator func);
#pragma mark -
#pragma Type creator invokation
T *create(const QString& key);
#pragma mark -
#pragma Type creator inspection
QStringList keys(void);
private:
QHash<QString, creator> creators;
//dtkCorePluginFactoryPrivate<T> *d;
};
#include "dtkCorePluginFactory.tpp"
......@@ -3,9 +3,9 @@
* Author: Julien Wintz
* Created: Fri Feb 8 16:20:47 2013 (+0100)
* Version:
* Last-Updated: 2013 Thu Feb 28 14:47:18 (+0100)
* By: Thibaud Kloczko
* Update #: 54
* Last-Updated: Thu Feb 28 15:50:06 2013 (+0100)
* By: Julien Wintz
* Update #: 66
*/
/* Change Log:
......@@ -14,36 +14,36 @@
#pragma once
// template <typename X> class dtkCorePluginFactoryPrivate
// {
// public:
// dtkCorePluginFactory<X>::creator toto;
// QHash<QString, dtkCorePluginFactory<X>::creator> creators;
// };
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void)
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void)
{
}
template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
{
}
template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key)
#pragma mark -
#pragma Type creator registration
template <typename T> void dtkCorePluginFactory<T>::record(QString key, creator func)
{
Q_ASSERT(this->creators.contains(key));
this->creators.insert(key, func);
}
#pragma mark -
#pragma Type creator invokation
template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key)
{
return this->creators.value(key)();
}
#pragma mark -
#pragma Type creator inspection
template <typename T> QStringList dtkCorePluginFactory<T>::keys(void)
{
return this->creators.keys();
}
template <typename T> void dtkCorePluginFactory<T>::record(QString key, creator func)
{
this->creators.insert(key, func);
}
......@@ -3,9 +3,9 @@
* Author: Julien Wintz
* Created: Mon Feb 11 12:07:50 2013 (+0100)
* Version:
* Last-Updated: Mon Feb 11 18:52:08 2013 (+0100)
* Last-Updated: Thu Feb 28 15:58:49 2013 (+0100)
* By: Julien Wintz
* Update #: 30
* Update #: 43
*/
/* Change Log:
......@@ -14,14 +14,12 @@
#pragma once
#include <QtCore/QObject>
#include <QtCore>
class dtkCorePluginManagerPrivate;
template <typename T> class dtkCorePluginManagerPrivate;
class dtkCorePluginManager : public QObject
template <typename T> class dtkCorePluginManager : public QObject
{
Q_OBJECT
public:
dtkCorePluginManager(void);
~dtkCorePluginManager(void);
......@@ -29,7 +27,6 @@ public:
#pragma mark -
#pragma Manager Management
virtual void initialize(void) = 0;
virtual void initialize(const QString& path);
virtual void uninitialize(void);
......@@ -37,8 +34,8 @@ public:
#pragma Plugin Management
virtual void scan(const QString& path);
virtual void load(const QString& path) = 0;
virtual void unload(const QString& path) = 0;
virtual void load(const QString& path);
virtual void unload(const QString& path);
#pragma mark -
#pragma Plugin Queries
......@@ -46,5 +43,7 @@ public:
QStringList plugins(void);
protected:
dtkCorePluginManagerPrivate *d;
dtkCorePluginManagerPrivate<T> *d;
};
#include "dtkCorePluginManager.tpp"
......@@ -3,26 +3,42 @@
* Author: Julien Wintz
* Created: Mon Feb 11 12:08:44 2013 (+0100)
* Version:
* Last-Updated: Mon Feb 11 18:52:16 2013 (+0100)
* Last-Updated: Thu Feb 28 16:01:42 2013 (+0100)
* By: Julien Wintz
* Update #: 29
* Update #: 57
*/
/* Change Log:
*
*/
#include "dtkCorePluginManager.h"
#include "dtkCorePluginManager_p.h"
#pragma once
#include <QtCore>
#include <QtDebug>
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginManagerPrivate
// ///////////////////////////////////////////////////////////////////
bool dtkCorePluginManagerPrivate::check(const QString& path)
template <typename T> class dtkCorePluginManagerPrivate
{
public:
bool check(const QString& path);
public:
QHash<QString, QVariant> names;
QHash<QString, QVariant> versions;
QHash<QString, QVariantList> dependencies;
public:
QHash<QString, QPluginLoader *> loaders;
};
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginManagerPrivate
// ///////////////////////////////////////////////////////////////////
template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString& path)
{
bool status = true;
......@@ -59,19 +75,22 @@ bool dtkCorePluginManagerPrivate::check(const QString& path)
// dtkCorePluginManager
// ///////////////////////////////////////////////////////////////////
dtkCorePluginManager::dtkCorePluginManager(void) : d(new dtkCorePluginManagerPrivate)
template <typename T> dtkCorePluginManager<T>::dtkCorePluginManager(void) : d(new dtkCorePluginManagerPrivate<T>)
{
}
dtkCorePluginManager::~dtkCorePluginManager(void)
template <typename T> dtkCorePluginManager<T>::~dtkCorePluginManager(void)
{
delete d;
d = NULL;
}
void dtkCorePluginManager::initialize(const QString& path)
#pragma mark -
#pragma Manager Management
template <typename T> void dtkCorePluginManager<T>::initialize(const QString& path)
{
QDir dir(path);
......@@ -82,13 +101,16 @@ void dtkCorePluginManager::initialize(const QString& path)
this->load(info.absoluteFilePath());
}
void dtkCorePluginManager::uninitialize(void)
template <typename T> void dtkCorePluginManager<T>::uninitialize(void)
{
foreach(const QString &path, d->loaders.keys())
this->unload(path);
}
void dtkCorePluginManager::scan(const QString& path)
#pragma mark -
#pragma Plugin Management
template <typename T> void dtkCorePluginManager<T>::scan(const QString& path)
{
if(!QLibrary::isLibrary(path))
return;
......@@ -102,7 +124,52 @@ void dtkCorePluginManager::scan(const QString& path)
delete loader;
}
QStringList dtkCorePluginManager::plugins(void)
template <typename T> void dtkCorePluginManager<T>::load(const QString& path)
{
if(!QLibrary::isLibrary(path))
return;
if(!d->check(path))
return;
QPluginLoader *loader = new QPluginLoader(path);
if(!loader)
return;
loader->setLoadHints(QLibrary::ExportExternalSymbolsHint);
T *plugin = qobject_cast<T *>(loader->instance());
if(!plugin) {
delete loader;
return;
}
plugin->initialize();
d->loaders.insert(path, loader);
}
template <typename T> void dtkCorePluginManager<T>::unload(const QString& path)
{
QPluginLoader *loader = d->loaders.value(path);
T *plugin = qobject_cast<T *>(loader->instance());
if (plugin)
plugin->uninitialize();
if(loader->unload()) {
d->loaders.remove(path);
delete loader;
}
}
#pragma mark -
#pragma Plugin Queries
template <typename T> QStringList dtkCorePluginManager<T>::plugins(void)
{
return d->loaders.keys();
}
......@@ -3,9 +3,9 @@
* Author: Julien Wintz
* Created: Mon Feb 11 12:13:49 2013 (+0100)
* Version:
* Last-Updated: Mon Feb 11 12:44:57 2013 (+0100)
* Last-Updated: Thu Feb 28 15:48:37 2013 (+0100)
* By: Julien Wintz
* Update #: 3
* Update #: 4
*/
/* Change Log:
......@@ -17,16 +17,3 @@
#include <QtCore>
#include <QtDebug>
class dtkCorePluginManagerPrivate
{
public:
bool check(const QString& path);
public:
QHash<QString, QVariant> names;
QHash<QString, QVariant> versions;
QHash<QString, QVariantList> dependencies;
public:
QHash<QString, QPluginLoader *> loaders;
};
......@@ -21,12 +21,6 @@ set(${PROJECT_NAME}_HEADERS
dtkDistributedArray.tpp
dtkDistributedArrayItem.h
dtkDistributedCommunicator.h
dtkDistributedCommunicatorPlugin
dtkDistributedCommunicatorPlugin.h
dtkDistributedCommunicatorPluginFactory
dtkDistributedCommunicatorPluginFactory.h
dtkDistributedCommunicatorPluginManager
dtkDistributedCommunicatorPluginManager.h
dtkDistributedContainer.h
dtkDistributedContainerIndexed.h
dtkDistributedContainerSequence.h
......@@ -41,8 +35,6 @@ set(${PROJECT_NAME}_HEADERS
set(${PROJECT_NAME}_SOURCES
dtkDistributed.cpp
dtkDistributedCommunicator.cpp
dtkDistributedCommunicatorPluginFactory.cpp
dtkDistributedCommunicatorPluginManager.cpp
dtkDistributedMapper.cpp
dtkDistributedPolicy.cpp
dtkDistributedSettings.cpp
......
#include "dtkDistributed.h"
#include "dtkDistributedCommunicator.h"
#include "dtkDistributedCommunicatorPlugin.h"
#include "dtkDistributedCommunicatorPluginFactory.h"
#include "dtkDistributedCommunicatorPluginManager.h"
#include "dtkDistributedContainer.h"
#include "dtkDistributedMapper.h"
#include "dtkDistributedSettings.h"
......@@ -10,9 +10,10 @@
#include "dtkDistributed.h"
#include "dtkDistributedCommunicator.h"
#include "dtkDistributedCommunicatorPlugin.h"
#include "dtkDistributedCommunicatorPluginFactory.h"
#include "dtkDistributedCommunicatorPluginManager.h"
// #include "dtkDistributedCommunicatorPlugin.h"
// #include "dtkDistributedCommunicatorPluginFactory.h"
// #include "dtkDistributedCommunicatorPluginManager.h"
namespace dtkDistributed
{
......@@ -35,8 +36,6 @@ namespace dtkDistributed
dtkDistributedCommunicatorPluginManager manager;
}
dtkDistributedCommunicatorPluginFactory& pluginFactory(void) {
return _private::factory;
}
......
......@@ -14,11 +14,17 @@ class dtkDistributedCommunicatorPlugin;
class dtkDistributedCommunicatorPluginFactory;
class dtkDistributedCommunicatorPluginManager;
#define DTK_DISTRIBUTED_BEGIN_GLOBAL comm->barrier(); dtkDistributed::setMode(dtkDistributed::Global); if (dtkDistributedWork::worker()->master()) { time.restart();
#define DTK_DISTRIBUTED_END_GLOBAL qDebug() << "global section:" << time.elapsed() << "ms"; } ; comm->barrier();
#define DTK_DISTRIBUTED_BEGIN_LOCAL comm->barrier(); dtkDistributed::setMode(dtkDistributed::Local); time.restart();
#define DTK_DISTRIBUTED_END_LOCAL qDebug() << "local section:" << time.elapsed() << "ms";
#define DTK_DISTRIBUTED_BEGIN_GLOBAL \
comm->barrier(); dtkDistributed::setMode(dtkDistributed::Global); if (dtkDistributedWork::worker()->master()) { time.restart();
#define DTK_DISTRIBUTED_END_GLOBAL \
qDebug() << "global section:" << time.elapsed() << "ms"; } ; comm->barrier();
#define DTK_DISTRIBUTED_BEGIN_LOCAL \
comm->barrier(); dtkDistributed::setMode(dtkDistributed::Local); time.restart();
#define DTK_DISTRIBUTED_END_LOCAL \
qDebug() << "local section:" << time.elapsed() << "ms";
namespace dtkDistributed
{
......