1 | /**
|
---|
2 | *
|
---|
3 | * This file is part of the PACPUS framework distributed under the
|
---|
4 | * CECILL-C License, Version 1.0.
|
---|
5 | *
|
---|
6 | * @author Samuel Gosselin
|
---|
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/ComponentBase.h>
|
---|
14 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
15 | #include <Pacpus/kernel/Log.h>
|
---|
16 |
|
---|
17 | using namespace pacpus;
|
---|
18 |
|
---|
19 | DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase");
|
---|
20 |
|
---|
21 | ComponentBase::ComponentBase(const QString& name)
|
---|
22 | : componentName(name)
|
---|
23 | , recording(true)
|
---|
24 | , THREAD_ALIVE(true)
|
---|
25 | , mIsActive(false)
|
---|
26 | , mgr(NULL)
|
---|
27 | , componentState_(NOT_MONITORED)
|
---|
28 | {
|
---|
29 | LOG_TRACE("constructor");
|
---|
30 | // Get a pointer on the instance of ComponentManager.
|
---|
31 | mgr = ComponentManager::getInstance();
|
---|
32 | LOG_INFO("component " << componentName << " was created");
|
---|
33 | }
|
---|
34 |
|
---|
35 | ComponentBase::~ComponentBase()
|
---|
36 | {
|
---|
37 | LOG_TRACE("destructor");
|
---|
38 | }
|
---|
39 |
|
---|
40 | int ComponentBase::startComponent()
|
---|
41 | {
|
---|
42 | if (mIsActive)
|
---|
43 | return false;
|
---|
44 |
|
---|
45 | mIsActive = true;
|
---|
46 | startActivity();
|
---|
47 |
|
---|
48 | return true;
|
---|
49 | }
|
---|
50 |
|
---|
51 | int ComponentBase::stopComponent()
|
---|
52 | {
|
---|
53 | if (!mIsActive)
|
---|
54 | return false;
|
---|
55 |
|
---|
56 | mIsActive = false;
|
---|
57 | stopActivity();
|
---|
58 |
|
---|
59 | return true;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void ComponentBase::setState(const COMPONENT_STATE state)
|
---|
63 | {
|
---|
64 | componentState_ = state;
|
---|
65 | }
|
---|
66 |
|
---|
67 | // FIXME: this should be const.
|
---|
68 | ComponentBase::COMPONENT_STATE ComponentBase::getState()
|
---|
69 | {
|
---|
70 | COMPONENT_STATE state = componentState_;
|
---|
71 | if (ComponentBase::NOT_MONITORED != componentState_) {
|
---|
72 | componentState_ = ComponentBase::MONITOR_NOK;
|
---|
73 | }
|
---|
74 | return state;
|
---|
75 | }
|
---|
76 |
|
---|
77 | bool ComponentBase::isConfigured() const
|
---|
78 | {
|
---|
79 | return configuration_ == CONFIGURED_OK;
|
---|
80 | }
|
---|