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