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