[89] | 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: ComponentBase.cpp 76 2013-01-10 17:05:10Z kurdejma $
|
---|
| 6 |
|
---|
| 7 | #include <Pacpus/kernel/ComponentBase.h>
|
---|
| 8 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
| 9 | #include <Pacpus/kernel/Log.h>
|
---|
| 10 |
|
---|
| 11 | using namespace pacpus;
|
---|
| 12 |
|
---|
| 13 | DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase");
|
---|
| 14 |
|
---|
| 15 | ComponentBase::ComponentBase(const QString& name)
|
---|
| 16 | : componentName(name)
|
---|
| 17 | , recording(true)
|
---|
| 18 | , THREAD_ALIVE(true)
|
---|
| 19 | , mIsActive(false)
|
---|
| 20 | , mgr(NULL)
|
---|
| 21 | , componentState_(NOT_MONITORED)
|
---|
| 22 | {
|
---|
| 23 | LOG_TRACE("constructor");
|
---|
| 24 | // Get a pointer on the instance of ComponentManager.
|
---|
| 25 | mgr = ComponentManager::getInstance();
|
---|
| 26 | LOG_INFO("component " << componentName << " was created");
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | ComponentBase::~ComponentBase()
|
---|
| 30 | {
|
---|
| 31 | LOG_TRACE("destructor");
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | int ComponentBase::startComponent()
|
---|
| 35 | {
|
---|
| 36 | if (mIsActive)
|
---|
| 37 | return false;
|
---|
| 38 |
|
---|
| 39 | mIsActive = true;
|
---|
| 40 | startActivity();
|
---|
| 41 |
|
---|
| 42 | return true;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | int ComponentBase::stopComponent()
|
---|
| 46 | {
|
---|
| 47 | if (!mIsActive)
|
---|
| 48 | return false;
|
---|
| 49 |
|
---|
| 50 | mIsActive = false;
|
---|
| 51 | stopActivity();
|
---|
| 52 |
|
---|
| 53 | return true;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void ComponentBase::setState(const COMPONENT_STATE state)
|
---|
| 57 | {
|
---|
| 58 | componentState_ = state;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | // FIXME: this should be const.
|
---|
| 62 | ComponentBase::COMPONENT_STATE ComponentBase::getState()
|
---|
| 63 | {
|
---|
| 64 | COMPONENT_STATE state = componentState_;
|
---|
| 65 | if (ComponentBase::NOT_MONITORED != componentState_) {
|
---|
| 66 | componentState_ = ComponentBase::MONITOR_NOK;
|
---|
| 67 | }
|
---|
| 68 | return state;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | bool ComponentBase::isConfigured() const
|
---|
| 72 | {
|
---|
| 73 | return configuration_ == CONFIGURED_OK;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | QString ComponentBase::getName() const
|
---|
| 77 | {
|
---|
| 78 | return componentName;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | InputInterfaceBase * ComponentBase::getInput(QString inputName) const
|
---|
| 82 | {
|
---|
| 83 |
|
---|
| 84 | if(input.contains(inputName))
|
---|
| 85 | return input[inputName];
|
---|
| 86 | else {
|
---|
| 87 | LOG_WARN("Component " << componentName << " does not containt input " << inputName);
|
---|
| 88 | return NULL;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | OutputInterfaceBase * ComponentBase::getOutput(QString outputName) const
|
---|
| 93 | {
|
---|
| 94 | /* QList<QString> keys = output.keys();
|
---|
| 95 | for(int i=0; i<keys.size();++i)
|
---|
| 96 | LOG_INFO("Key : " << keys[i])*/;
|
---|
| 97 |
|
---|
| 98 | if(output.contains(outputName))
|
---|
| 99 | return output[outputName];
|
---|
| 100 | else {
|
---|
| 101 | LOG_WARN("Component " << componentName << " does not containt output " << outputName);
|
---|
| 102 | return NULL;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|