source: pacpusframework/trunk/src/PacpusLib/ComponentFactoryBase.cpp@ 41

Last change on this file since 41 was 31, checked in by sgosseli, 12 years ago

Huge commit: use the new includes style in all the files, add the license header in all the headers, and in some cpp.

File size: 1.5 KB
RevLine 
[31]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 */
[3]10
[31]11#include <Pacpus/kernel/ComponentFactoryBase.h>
12#include <Pacpus/kernel/ComponentBase.h>
13#include <Pacpus/kernel/ComponentManager.h>
14#include <Pacpus/kernel/Log.h>
[3]15
16#include <cassert>
17#include <QString>
18
[31]19using namespace pacpus;
[3]20
21DECLARE_STATIC_LOGGER("pacpus.core.ComponentFactoryBase");
22
23ComponentFactoryBase::ComponentFactoryBase()
24{
25 LOG_TRACE("constructor");
26
27 // get the adress of the ComponentManager instance
28 mgr_ = ComponentManager::getInstance();
29}
30
31ComponentFactoryBase::~ComponentFactoryBase()
32{
33 LOG_TRACE("destructor");
34}
35
36void 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
50void 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}
Note: See TracBrowser for help on using the repository browser.