source: pacpusframework/branches/2.0-beta1/src/PacpusLib/ComponentFactoryBase.cpp@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

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