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