1 | /**
|
---|
2 | *
|
---|
3 | * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
|
---|
4 | * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
|
---|
5 | *
|
---|
6 | * See the LICENSE file for more information or a copy at:
|
---|
7 | * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | #include <Pacpus/kernel/ComponentFactoryBase.h>
|
---|
12 | #include <Pacpus/kernel/ComponentBase.h>
|
---|
13 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
14 | #include <Pacpus/kernel/Log.h>
|
---|
15 |
|
---|
16 | #include <cassert>
|
---|
17 | #include <QString>
|
---|
18 |
|
---|
19 | using 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 | }
|
---|