source: pacpusframework/branches/0.0.x/src/PacpusLib/ComponentFactoryBase.cpp@ 185

Last change on this file since 185 was 91, checked in by DHERBOMEZ Gérald, 12 years ago

Improvement of the build system to avoid some workarounds

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
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/// @author Gerald Dherbomez <firstname.surname@utc.fr>
6/// @version $Id: ComponentFactoryBase.cpp 91 2013-05-19 10:32:48Z gdherbom $
7
8#include <Pacpus/kernel/ComponentFactoryBase.h>
9#include <Pacpus/kernel/ComponentBase.h>
10#include <Pacpus/kernel/ComponentManager.h>
11#include <Pacpus/kernel/Log.h>
12
13#include <cassert>
14#include <QString>
15
16using namespace pacpus;
17
18DECLARE_STATIC_LOGGER("pacpus.core.ComponentFactoryBase");
19
20ComponentFactoryBase::ComponentFactoryBase()
21 : mgr_(NULL)
22{
23 LOG_TRACE("constructor");
24 // get the adress of the ComponentManager instance
25 mgr_ = ComponentManager::getInstance();
26}
27
28ComponentFactoryBase::~ComponentFactoryBase()
29{
30 LOG_TRACE("destructor");
31}
32
33void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString& type)
34{
35 LOG_DEBUG("addFactory(type="<< type << ")");
36
37 assert(mgr_);
38 if (!mgr_->registerComponentFactory(addr, type)) {
39 /*
40 // FIXME: delete in a secure manner (no double delete)
41 delete addr;
42 addr = NULL;
43 */
44 }
45}
46
47void ComponentFactoryBase::addComponent(const QString& name)
48{
49 LOG_DEBUG("addComponent(" << name << ")");
50
51 // FIXME: instantiated component is never deleted!
52 // who should do it? ComponentManager?
53 ComponentBase * addr = instantiateComponent(name);
54 assert(mgr_);
55 if (!mgr_->registerComponent(addr, name)) {
56 delete addr;
57 addr = NULL;
58 }
59}
Note: See TracBrowser for help on using the repository browser.