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