[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 |
|
---|
[152] | 15 | ComponentBase::ComponentBase(const QString& componentName)
|
---|
| 16 | : m_componentName(componentName)
|
---|
| 17 | , m_isActive(false)
|
---|
| 18 | , m_isRecording(true)
|
---|
| 19 | , m_manager(NULL)
|
---|
| 20 | , m_ui(NULL)
|
---|
| 21 | , m_componentState(NOT_MONITORED)
|
---|
[89] | 22 | {
|
---|
| 23 | LOG_TRACE("constructor");
|
---|
| 24 | // Get a pointer on the instance of ComponentManager.
|
---|
[152] | 25 | m_manager = ComponentManager::getInstance();
|
---|
| 26 | LOG_INFO("component " << name() << " was created");
|
---|
[89] | 27 | }
|
---|
| 28 |
|
---|
| 29 | ComponentBase::~ComponentBase()
|
---|
| 30 | {
|
---|
| 31 | LOG_TRACE("destructor");
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[152] | 34 | bool ComponentBase::isActive() const
|
---|
| 35 | {
|
---|
| 36 | return m_isActive;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | void ComponentBase::setActive(bool isActive)
|
---|
| 40 | {
|
---|
| 41 | m_isActive = isActive;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | bool ComponentBase::isRecording() const
|
---|
| 45 | {
|
---|
| 46 | return m_isRecording;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void ComponentBase::setRecording(bool isRecording)
|
---|
| 50 | {
|
---|
| 51 | m_isRecording = isRecording;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | const XmlComponentConfig ComponentBase::xmlParameters() const
|
---|
| 55 | {
|
---|
| 56 | return param;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[89] | 59 | int ComponentBase::startComponent()
|
---|
| 60 | {
|
---|
[152] | 61 | if (isActive()) {
|
---|
| 62 | LOG_DEBUG("component already started, cannot (re-)start");
|
---|
| 63 | return false;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | setActive(true);
|
---|
[89] | 67 | startActivity();
|
---|
| 68 |
|
---|
| 69 | return true;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | int ComponentBase::stopComponent()
|
---|
| 73 | {
|
---|
[152] | 74 | if (!isActive()) {
|
---|
| 75 | LOG_DEBUG("component already stopped, cannot (re-)stop");
|
---|
| 76 | return false;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | setActive(false);
|
---|
[89] | 80 | stopActivity();
|
---|
| 81 |
|
---|
| 82 | return true;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void ComponentBase::setState(const COMPONENT_STATE state)
|
---|
| 86 | {
|
---|
[152] | 87 | m_componentState = state;
|
---|
[89] | 88 | }
|
---|
| 89 |
|
---|
| 90 | // FIXME: this should be const.
|
---|
| 91 | ComponentBase::COMPONENT_STATE ComponentBase::getState()
|
---|
| 92 | {
|
---|
[152] | 93 | COMPONENT_STATE state = m_componentState;
|
---|
| 94 | if (ComponentBase::NOT_MONITORED != m_componentState) {
|
---|
| 95 | m_componentState = ComponentBase::MONITOR_NOK;
|
---|
[89] | 96 | }
|
---|
| 97 | return state;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[152] | 100 | ComponentBase::COMPONENT_CONFIGURATION ComponentBase::configurationState() const
|
---|
| 101 | {
|
---|
| 102 | return m_configurationState;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void ComponentBase::setConfigurationState(COMPONENT_CONFIGURATION state)
|
---|
| 106 | {
|
---|
| 107 | m_configurationState = state;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[89] | 110 | bool ComponentBase::isConfigured() const
|
---|
| 111 | {
|
---|
[152] | 112 | return (m_configurationState == CONFIGURED_OK);
|
---|
[89] | 113 | }
|
---|
| 114 |
|
---|
[152] | 115 | QString ComponentBase::name() const
|
---|
| 116 | {
|
---|
| 117 | return m_componentName;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[89] | 120 | QString ComponentBase::getName() const
|
---|
| 121 | {
|
---|
[152] | 122 | return m_componentName;
|
---|
[89] | 123 | }
|
---|
| 124 |
|
---|
[152] | 125 | ComponentBase::InputsMap & ComponentBase::inputs()
|
---|
[89] | 126 | {
|
---|
[152] | 127 | return m_inputs;
|
---|
| 128 | }
|
---|
[89] | 129 |
|
---|
[152] | 130 | const ComponentBase::InputsMap & ComponentBase::inputs() const
|
---|
| 131 | {
|
---|
| 132 | return m_inputs;
|
---|
[89] | 133 | }
|
---|
| 134 |
|
---|
[152] | 135 | ComponentBase::OutputsMap & ComponentBase::outputs()
|
---|
[89] | 136 | {
|
---|
[152] | 137 | return m_outputs;
|
---|
| 138 | }
|
---|
[89] | 139 |
|
---|
[152] | 140 | const ComponentBase::OutputsMap & ComponentBase::outputs() const
|
---|
| 141 | {
|
---|
| 142 | return m_outputs;
|
---|
[89] | 143 | }
|
---|
[120] | 144 |
|
---|
[152] | 145 | InputInterfaceBase * ComponentBase::getInput(QString inputName) const
|
---|
[120] | 146 | {
|
---|
[152] | 147 | if (inputs().contains(inputName)) {
|
---|
| 148 | return inputs()[inputName];
|
---|
| 149 | }
|
---|
| 150 | LOG_WARN("Component " << name() << " does not contain input " << inputName);
|
---|
| 151 | return NULL;
|
---|
[120] | 152 | }
|
---|
| 153 |
|
---|
[152] | 154 | OutputInterfaceBase * ComponentBase::getOutput(QString outputName) const
|
---|
[120] | 155 | {
|
---|
[152] | 156 | /* QList<QString> keys = output.keys();
|
---|
| 157 | for(int i=0; i<keys.size();++i)
|
---|
| 158 | LOG_INFO("Key : " << keys[i])*/;
|
---|
[120] | 159 |
|
---|
[152] | 160 | if (outputs().contains(outputName)) {
|
---|
| 161 | return outputs()[outputName];
|
---|
| 162 | }
|
---|
| 163 | LOG_WARN("Component " << name() << " does not containt output " << outputName);
|
---|
| 164 | return NULL;
|
---|
[120] | 165 | }
|
---|