| [3] | 1 | // ********************************************************************
|
|---|
| 2 | // created: 2006/02/14 - 16:07
|
|---|
| 3 | // filename: ComponentFactoryBase.cpp
|
|---|
| 4 | //
|
|---|
| 5 | // author: Gerald Dherbomez
|
|---|
| 6 | //
|
|---|
| 7 | // purpose: Implementation of ComponentFactoryBase class
|
|---|
| 8 | // *********************************************************************
|
|---|
| 9 |
|
|---|
| 10 | #include "kernel/ComponentFactoryBase.h"
|
|---|
| 11 |
|
|---|
| 12 | #include "kernel/ComponentBase.h"
|
|---|
| 13 | #include "kernel/ComponentManager.h"
|
|---|
| 14 | #include "kernel/Log.h"
|
|---|
| 15 |
|
|---|
| 16 | #include <cassert>
|
|---|
| 17 | #include <QString>
|
|---|
| 18 |
|
|---|
| 19 | namespace pacpus {
|
|---|
| 20 |
|
|---|
| 21 | DECLARE_STATIC_LOGGER("pacpus.core.ComponentFactoryBase");
|
|---|
| 22 |
|
|---|
| 23 | ComponentFactoryBase::ComponentFactoryBase()
|
|---|
| 24 | {
|
|---|
| 25 | LOG_TRACE("constructor");
|
|---|
| 26 |
|
|---|
| 27 | // get the adress of the ComponentManager instance
|
|---|
| 28 | mgr_ = ComponentManager::getInstance();
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | ComponentFactoryBase::~ComponentFactoryBase()
|
|---|
| 32 | {
|
|---|
| 33 | LOG_TRACE("destructor");
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void ComponentFactoryBase::addFactory(ComponentFactoryBase * addr, const QString & type)
|
|---|
| 37 | {
|
|---|
| 38 | LOG_DEBUG("addFactory(type="<< type << ")");
|
|---|
| 39 |
|
|---|
| 40 | assert(mgr_);
|
|---|
| 41 | if (!mgr_->registerComponentFactory(addr, type)) {
|
|---|
| 42 | /*
|
|---|
| 43 | // FIXME: delete in a secure manner (no double delete)
|
|---|
| 44 | delete addr;
|
|---|
| 45 | addr = NULL;
|
|---|
| 46 | */
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void ComponentFactoryBase::addComponent(const QString & name)
|
|---|
| 51 | {
|
|---|
| 52 | LOG_DEBUG("addComponent(" << name << ")");
|
|---|
| 53 |
|
|---|
| 54 | // FIXME: instantiated component is never deleted!
|
|---|
| 55 | // who should do it? ComponentManager?
|
|---|
| 56 | ComponentBase * addr = instantiateComponent(name);
|
|---|
| 57 | assert(mgr_);
|
|---|
| 58 | if (!mgr_->registerComponent(addr, name)) {
|
|---|
| 59 | delete addr;
|
|---|
| 60 | addr = NULL;
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | } // namespace pacpus
|
|---|