[76] | 1 | // %pacpus:license{
|
---|
[73] | 2 | // This file is part of the PACPUS framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[76] | 4 | // %pacpus:license}
|
---|
[91] | 5 | /// @author Gerald Dherbomez <firstname.surname@utc.fr>
|
---|
[73] | 6 | /// @version $Id: ComponentFactoryBase.cpp 91 2013-05-19 10:32:48Z gdherbom $
|
---|
| 7 |
|
---|
| 8 | #include <Pacpus/kernel/ComponentFactoryBase.h>
|
---|
| 9 | #include <Pacpus/kernel/ComponentBase.h>
|
---|
| 10 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
| 11 | #include <Pacpus/kernel/Log.h>
|
---|
| 12 |
|
---|
| 13 | #include <cassert>
|
---|
| 14 | #include <QString>
|
---|
| 15 |
|
---|
| 16 | using namespace pacpus;
|
---|
| 17 |
|
---|
| 18 | DECLARE_STATIC_LOGGER("pacpus.core.ComponentFactoryBase");
|
---|
| 19 |
|
---|
| 20 | ComponentFactoryBase::ComponentFactoryBase()
|
---|
| 21 | : mgr_(NULL)
|
---|
| 22 | {
|
---|
| 23 | LOG_TRACE("constructor");
|
---|
| 24 | // get the adress of the ComponentManager instance
|
---|
| 25 | mgr_ = ComponentManager::getInstance();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | ComponentFactoryBase::~ComponentFactoryBase()
|
---|
| 29 | {
|
---|
| 30 | LOG_TRACE("destructor");
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString& type)
|
---|
| 34 | {
|
---|
| 35 | LOG_DEBUG("addFactory(type="<< type << ")");
|
---|
| 36 |
|
---|
| 37 | assert(mgr_);
|
---|
| 38 | if (!mgr_->registerComponentFactory(addr, type)) {
|
---|
| 39 | /*
|
---|
| 40 | // FIXME: delete in a secure manner (no double delete)
|
---|
| 41 | delete addr;
|
---|
| 42 | addr = NULL;
|
---|
| 43 | */
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | void ComponentFactoryBase::addComponent(const QString& name)
|
---|
| 48 | {
|
---|
| 49 | LOG_DEBUG("addComponent(" << name << ")");
|
---|
| 50 |
|
---|
| 51 | // FIXME: instantiated component is never deleted!
|
---|
| 52 | // who should do it? ComponentManager?
|
---|
| 53 | ComponentBase * addr = instantiateComponent(name);
|
---|
| 54 | assert(mgr_);
|
---|
| 55 | if (!mgr_->registerComponent(addr, name)) {
|
---|
| 56 | delete addr;
|
---|
| 57 | addr = NULL;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|