Changeset 152 in pacpusframework
- Timestamp:
- Aug 1, 2013, 10:45:50 AM (11 years ago)
- Location:
- branches/2.0-beta1
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyEngine.h
r89 r152 91 91 92 92 protected: 93 virtual void addInputs(); 94 virtual void addOutputs(); 95 93 96 /// @todo Documentation 94 97 virtual void startActivity(); -
branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyTrigger.h
r89 r152 55 55 56 56 protected: 57 virtual void addInputs(); 58 virtual void addOutputs(); 59 57 60 /// @todo Documentation 58 61 virtual void startActivity(); -
branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyUserInterface.h
r89 r152 73 73 /// Displays the current time of the player. 74 74 void displayTime(road_time_t time); 75 76 protected: 77 virtual void addInputs(); 78 virtual void addOutputs(); 75 79 76 80 private: -
branches/2.0-beta1/include/Pacpus/PacpusTools/PacpusSerialPort.h
r122 r152 20 20 namespace pacpus { 21 21 22 class PacpusSerialPort : public QObject, public ComponentBase 22 class PacpusSerialPort 23 : public QObject 24 , public ComponentBase 23 25 { 24 26 Q_OBJECT 25 27 26 28 public: 27 28 typedef enum { ASCII, BINARY } DataMode; 29 typedef enum { 30 ASCII, 31 BINARY 32 } DataMode; 29 33 30 34 PacpusSerialPort(QString name); … … 36 40 ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config); 37 41 38 v oid addInput();39 v oid addOutput();42 virtual void addInputs(); 43 virtual void addOutputs(); 40 44 void processInputFrame(const QByteArray &); 41 45 42 private Q_SLOTS 46 private Q_SLOTS: 43 47 void readData(); 44 48 45 49 private: 46 47 50 QThread thread_; 48 51 … … 68 71 69 72 bool log; 70 71 72 73 }; 73 74 -
branches/2.0-beta1/include/Pacpus/kernel/ComponentBase.h
r138 r152 38 38 class ComponentManager; 39 39 40 template <typename T, class C> 41 class InputInterface; 42 43 template <typename T, class C> 44 class OutputInterface; 45 40 46 /** ComponentBase 41 47 * @brief Base class of a Pacpus component. … … 44 50 { 45 51 friend class ComponentManager; 52 46 53 public: 47 54 /** … … 87 94 * @return Name of the component. 88 95 */ 96 QString name() const; 89 97 QString getName() const; 90 98 91 InputInterfaceBase * getInput(QString ) const;92 93 OutputInterfaceBase * getOutput(QString ) const;99 InputInterfaceBase * getInput(QString name) const; 100 101 OutputInterfaceBase * getOutput(QString name) const; 94 102 95 103 protected: … … 115 123 // virtual QString getType() = 0; 116 124 117 virtual void addInput(); 118 119 virtual void addOutput(); 125 virtual void addInputs() = 0; 126 virtual void addOutputs() = 0; 127 128 protected: 129 typedef QMap<QString, InputInterfaceBase *> InputsMap; 130 typedef QMap<QString, OutputInterfaceBase *> OutputsMap; 131 132 // TODO: use std::function<void (const DataType &)> 133 // TODO: use std::mem_fun<void (const DataType &)> 134 template <typename DataType, class ComponentType, typename Function> 135 void addInput(const char * name, Function function) 136 { 137 typedef InputInterface<DataType, ComponentType> InputType; 138 InputType * connection = new InputType(name, dynamic_cast<ComponentType *>(this), function); 139 inputs().insert(name, connection); 140 } 141 142 template <typename DataType, class ComponentType> 143 void addOutput(const char * name) 144 { 145 typedef OutputInterface<DataType, ComponentType> OutputType; 146 OutputType * connection = new OutputType(name, dynamic_cast<ComponentType *>(this)); 147 outputs().insert(name, connection); 148 } 149 150 template <typename DataType, class ComponentType> 151 InputInterface<DataType, ComponentType> * 152 getTypedInput(const char * name) const 153 { 154 return dynamic_cast<InputInterface<DataType, ComponentType> *>(getInput(name)); 155 } 156 157 template <typename DataType, class ComponentType> 158 OutputInterface<DataType, ComponentType> * 159 getTypedOutput(const char * name) const 160 { 161 return dynamic_cast<OutputInterface<DataType, ComponentType> *>(getOutput(name)); 162 } 163 164 bool isActive() const; 165 void setActive(bool isActive); 166 bool isRecording() const; 167 void setRecording(bool isRecording); 168 169 InputsMap & inputs(); 170 const InputsMap & inputs() const; 171 OutputsMap & outputs(); 172 const OutputsMap & outputs() const; 173 174 COMPONENT_CONFIGURATION configurationState() const; 175 void setConfigurationState(COMPONENT_CONFIGURATION state); 176 177 const XmlComponentConfig xmlParameters() const; 120 178 121 protected:122 /// The XML node that is got in the configureComponent method123 XmlComponentConfig param;124 125 /// the name of the component. It is this one in the XML config file126 QString componentName;127 128 /// is the component is recording data?129 bool recording;130 131 /// provided for compatibility with old DBITE framework132 bool THREAD_ALIVE;133 134 /// is the component active?135 bool mIsActive;136 137 /// a pointer to the manager of components138 ComponentManager * mgr;139 140 QMap<QString, InputInterfaceBase *> input;141 QMap<QString, OutputInterfaceBase *> output;142 143 /// a pointer to an optional widget144 QWidget * ui;145 146 179 private: 147 180 /// called by the ComponentManager to start the component … … 151 184 int stopComponent(); 152 185 186 private: 187 /// The XML node that is got in the configureComponent method 188 XmlComponentConfig param; 189 190 /// the name of the component. It is this one in the XML config file 191 QString m_componentName; 192 193 /// is the component active? 194 volatile bool m_isActive; 195 196 /// is the component is recording data? 197 bool m_isRecording; 198 199 /// a pointer to the manager of components 200 ComponentManager * m_manager; 201 202 InputsMap m_inputs; 203 OutputsMap m_outputs; 204 205 /// a pointer to an optional widget 206 QWidget * m_ui; 207 153 208 /// store the state of the component 154 COMPONENT_STATE componentState_;209 COMPONENT_STATE m_componentState; 155 210 156 211 /// is the component configured (ie configureComponent method was called) 157 COMPONENT_CONFIGURATION configuration_;212 COMPONENT_CONFIGURATION m_configurationState; 158 213 }; 159 214 160 161 215 } // pacpus 162 216 -
branches/2.0-beta1/include/Pacpus/kernel/InputOutputBase.h
r148 r152 96 96 { 97 97 Q_OBJECT 98 98 99 protected: 99 100 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0) -
branches/2.0-beta1/include/Pacpus/kernel/InputOutputInterface.h
r148 r152 12 12 #include <QByteArray> 13 13 14 #define ADD_INPUT(name,ComponentType, DataType, functionName) input.insert(name,new InputInterface<DataType,ComponentType> (name,this,&ComponentType::functionName)) 15 #define ADD_OUTPUT(name,ComponentType, DataType) output.insert(name,new OutputInterface<DataType,ComponentType> (name,this)) 16 17 #define GET_OUTPUT(name,ComponentType, DataType) dynamic_cast<OutputInterface<DataType,ComponentType> *> (output.value(name)) 18 #define GET_INPUT(name,ComponentType, DataType) dynamic_cast<InputInterface<DataType,ComponentType> *> (input.value(name)) 14 //#define ADD_INPUT(name, ComponentType, DataType, functionName) \ 15 // inputs().insert((name), new InputInterface<DataType, ComponentType> ((name), this, &ComponentType::functionName)) 16 //#define ADD_OUTPUT(name, ComponentType, DataType) \ 17 // outputs().insert((name), new OutputInterface<DataType, ComponentType> ((name), this)) 18 19 //#define GET_INPUT(name, ComponentType, DataType) \ 20 // dynamic_cast<InputInterface<DataType, ComponentType> *> (input.value(name)) 21 //#define GET_OUTPUT(name, ComponentType, DataType) \ 22 // dynamic_cast<OutputInterface<DataType, ComponentType> *> (output.value(name)) 19 23 20 24 namespace pacpus { 21 25 22 template < classT, class C>26 template <typename T, class C> 23 27 class InputInterface 24 28 : public InputInterfaceBase … … 26 30 public: 27 31 InputInterface(QString name, C * component, void (C::*m)(const T&)) 28 : InputInterfaceBase(name, component,component)32 : InputInterfaceBase(name, component, component) 29 33 , method(m) 30 34 {} … … 140 144 }; 141 145 142 template < classT, class C>146 template <typename T, class C> 143 147 class OutputInterface : public OutputInterfaceBase 144 148 { -
branches/2.0-beta1/src/DBITEPlayerLib/DbtPlyEngine.cpp
r89 r152 23 23 DECLARE_STATIC_LOGGER("pacpus.core.DbtPlyEngine"); 24 24 25 static const stringkPropertyDataDirectory = "datadir";26 27 static const stringkPropertyLoggerConfiguration = "log-config-file";28 29 static const stringkPropertyReplayMode = "replay_mode";30 static const stringkPropertyReplayModeLastData = "1";31 static const stringkPropertyReplayModeAllData = "2";25 static const char * kPropertyDataDirectory = "datadir"; 26 27 static const char * kPropertyLoggerConfiguration = "log-config-file"; 28 29 static const char * kPropertyReplayMode = "replay_mode"; 30 static const char * kPropertyReplayModeLastData = "1"; 31 static const char * kPropertyReplayModeAllData = "2"; 32 32 33 33 typedef float SpeedType; … … 63 63 } 64 64 65 void DbtPlyEngine::addInputs() 66 { 67 // empty: no inputs 68 } 69 70 void DbtPlyEngine::addOutputs() 71 { 72 // empty: no outputs 73 } 74 65 75 //////////////////////////////////////////////////////////////////////////////// 66 76 /// Returns the directory where the data are stored. … … 103 113 int i = 0; 104 114 105 while ( THREAD_ALIVE) {115 while (isActive()) { 106 116 tNow_ = road_time(); 107 117 float elapsedTime = tNow_ - lastTNow_; … … 145 155 /// Configuration method of the engine 146 156 /// called automatically by the component manager 147 ComponentBase::COMPONENT_CONFIGURATION DbtPlyEngine::configureComponent(XmlComponentConfig /*config*/)157 ComponentBase::COMPONENT_CONFIGURATION DbtPlyEngine::configureComponent(XmlComponentConfig config) 148 158 { 149 159 // datadir 150 dataDir_ = param.getProperty(kPropertyDataDirectory.c_str());151 LOG_INFO("property " << kPropertyDataDirectory .c_str()<< "=\""160 dataDir_ = config.getProperty(kPropertyDataDirectory); 161 LOG_INFO("property " << kPropertyDataDirectory << "=\"" 152 162 << dataDir_ << "\""); 153 163 if (dataDir_.isNull()) { 154 LOG_FATAL("The data directory '" << componentName<< "' is invalid or unavailable!");164 LOG_FATAL("The data directory '" << name() << "' is invalid or unavailable!"); 155 165 } 156 166 … … 162 172 //////////////////////////////////////////////////////////////////////////////// 163 173 // logger configuration 164 QString loggerConfig = param.getProperty(kPropertyLoggerConfiguration.c_str());165 LOG_INFO("property " << kPropertyLoggerConfiguration .c_str()<< "=\""174 QString loggerConfig = config.getProperty(kPropertyLoggerConfiguration); 175 LOG_INFO("property " << kPropertyLoggerConfiguration << "=\"" 166 176 << loggerConfig << "\""); 167 177 if (!loggerConfig.isNull()) { … … 172 182 //////////////////////////////////////////////////////////////////////////////// 173 183 // Replay Mode 174 QString replayModeValue = param.getProperty(kPropertyReplayMode.c_str());175 LOG_INFO("property " << kPropertyReplayMode .c_str()<< "=\""184 QString replayModeValue = config.getProperty(kPropertyReplayMode); 185 LOG_INFO("property " << kPropertyReplayMode << "=\"" 176 186 << replayModeValue << "\""); 177 187 if (replayModeValue.isNull()) { 178 LOG_INFO("property " << kPropertyReplayMode .c_str()<< " unset."188 LOG_INFO("property " << kPropertyReplayMode << " unset." 179 189 << " Set to default = 1."); 180 190 replayMode_ = PlayModeLastData; … … 185 195 replayMode_ = PlayModeAllData; 186 196 } else { 187 LOG_WARN("unknown " << kPropertyReplayMode .c_str()<< " '" << replayModeValue << "'."197 LOG_WARN("unknown " << kPropertyReplayMode << " '" << replayModeValue << "'." 188 198 << " Set to default = 1."); 189 199 replayMode_ = PlayModeLastData; … … 200 210 LOG_INFO("Starting..."); 201 211 202 THREAD_ALIVE = true;212 setActive(true); 203 213 start(); 204 214 } … … 210 220 LOG_TRACE("stopping activity..."); 211 221 212 THREAD_ALIVE = false;222 setActive(false); 213 223 } 214 224 -
branches/2.0-beta1/src/DBITEPlayerLib/DbtPlyFileManager.cpp
r141 r152 21 21 DECLARE_STATIC_LOGGER("pacpus.core.DbtPlyFileManager"); 22 22 23 const stringkPropertyVerbose = "verbose";23 const char * kPropertyVerbose = "verbose"; 24 24 const int kPropertyVerboseDefaultValue = 1; 25 25 26 const stringkPropertyDbiteFileName = "dbt";26 const char * kPropertyDbiteFileName = "dbt"; 27 27 28 28 // It is the maximum time elapsed between the computation of the tDbt and the data replay in microseconds … … 31 31 //////////////////////////////////////////////////////////////////////////////// 32 32 /// Constructor. 33 DbtPlyFileManager::DbtPlyFileManager(QString name):ComponentBase(name) 33 DbtPlyFileManager::DbtPlyFileManager(QString name) 34 : ComponentBase(name) 34 35 { 35 36 LOG_TRACE("constructor"); … … 85 86 ///////////////////////////////////////// 86 87 { 87 QString verbose = param.getProperty(kPropertyVerbose.c_str());88 QString verbose = config.getProperty(kPropertyVerbose); 88 89 if (verbose.isNull()) { 89 90 LOG_INFO("property " << kPropertyVerbose << " not set." … … 103 104 104 105 ///////////////////////////////////////// 105 dbtProperty_ = param.getProperty(kPropertyDbiteFileName.c_str());106 mShowGui = param.getProperty("ui").toInt();106 dbtProperty_ = config.getProperty(kPropertyDbiteFileName); 107 mShowGui = config.getProperty("ui").toInt(); 107 108 mDbtDataPath = mEngine->getDataDir(); 108 109 … … 180 181 void DbtPlyFileManager::displayUI() 181 182 { 182 LOG_WARN("component '" << componentName<< "' has no user interface. Please set ui property to 0 in your XML configuration");183 LOG_WARN("component '" << name() << "' has no user interface. Please set ui property to 0 in your XML configuration"); 183 184 } 184 185 … … 300 301 deltaTDbtTab_[(deltaTDbtTabLoop_++)%1000] = deltaT; 301 302 if (deltaT > kMaxPendingTimeFromEngineMicrosecs) { 302 LOG_WARN( componentName<< ": data not replayed: elapsed time since engine notification too big:" << deltaT << "us");303 LOG_WARN(name() << ": data not replayed: elapsed time since engine notification too big:" << deltaT << "us"); 303 304 return; 304 305 } -
branches/2.0-beta1/src/DBITEPlayerLib/DbtPlyTrigger.cpp
r89 r152 21 21 , mEngine(NULL) 22 22 { 23 THREAD_ALIVE = false;24 23 } 25 24 26 25 DbtPlyTrigger::~DbtPlyTrigger() 27 26 { 27 } 28 29 void DbtPlyTrigger::addInputs() 30 { 31 // empty: no inputs 32 } 33 34 void DbtPlyTrigger::addOutputs() 35 { 36 // empty: no outputs 28 37 } 29 38 … … 46 55 void DbtPlyTrigger::startActivity() 47 56 { 48 THREAD_ALIVE = true;49 57 start(); 50 58 } … … 52 60 void DbtPlyTrigger::stopActivity() 53 61 { 54 THREAD_ALIVE = false;55 62 } 56 63 … … 62 69 #endif 63 70 64 while( THREAD_ALIVE) {71 while(isActive()) { 65 72 if (mEngine->isPlaying()) { 66 73 Q_EMIT triggerSig(); -
branches/2.0-beta1/src/DBITEPlayerLib/DbtPlyUserInterface.cpp
r89 r152 48 48 } 49 49 50 void DbtPlyUserInterface::addInputs() 51 { 52 // empty: no inputs 53 } 54 55 void DbtPlyUserInterface::addOutputs() 56 { 57 // empty: no outputs 58 } 59 50 60 //////////////////////////////////////////////////////////////////////////////// 51 61 ComponentBase::COMPONENT_CONFIGURATION DbtPlyUserInterface::configureComponent(XmlComponentConfig /*config*/) -
branches/2.0-beta1/src/PacpusLib/ComponentBase.cpp
r120 r152 13 13 DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase"); 14 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 , ui(NULL) 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) 23 22 { 24 23 LOG_TRACE("constructor"); 25 24 // Get a pointer on the instance of ComponentManager. 26 m gr = ComponentManager::getInstance();27 LOG_INFO("component " << componentName<< " was created");25 m_manager = ComponentManager::getInstance(); 26 LOG_INFO("component " << name() << " was created"); 28 27 } 29 28 … … 33 32 } 34 33 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 35 59 int ComponentBase::startComponent() 36 60 { 37 if (mIsActive) 38 return false; 39 40 mIsActive = true; 61 if (isActive()) { 62 LOG_DEBUG("component already started, cannot (re-)start"); 63 return false; 64 } 65 66 setActive(true); 41 67 startActivity(); 42 68 … … 46 72 int ComponentBase::stopComponent() 47 73 { 48 if (!mIsActive) 49 return false; 50 51 mIsActive = false; 74 if (!isActive()) { 75 LOG_DEBUG("component already stopped, cannot (re-)stop"); 76 return false; 77 } 78 79 setActive(false); 52 80 stopActivity(); 53 81 … … 57 85 void ComponentBase::setState(const COMPONENT_STATE state) 58 86 { 59 componentState_= state;87 m_componentState = state; 60 88 } 61 89 … … 63 91 ComponentBase::COMPONENT_STATE ComponentBase::getState() 64 92 { 65 COMPONENT_STATE state = componentState_;66 if (ComponentBase::NOT_MONITORED != componentState_) {67 componentState_= ComponentBase::MONITOR_NOK;93 COMPONENT_STATE state = m_componentState; 94 if (ComponentBase::NOT_MONITORED != m_componentState) { 95 m_componentState = ComponentBase::MONITOR_NOK; 68 96 } 69 97 return state; 70 98 } 71 99 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 72 110 bool ComponentBase::isConfigured() const 73 111 { 74 return configuration_ == CONFIGURED_OK; 112 return (m_configurationState == CONFIGURED_OK); 113 } 114 115 QString ComponentBase::name() const 116 { 117 return m_componentName; 75 118 } 76 119 77 120 QString ComponentBase::getName() const 78 121 { 79 return componentName; 122 return m_componentName; 123 } 124 125 ComponentBase::InputsMap & ComponentBase::inputs() 126 { 127 return m_inputs; 128 } 129 130 const ComponentBase::InputsMap & ComponentBase::inputs() const 131 { 132 return m_inputs; 133 } 134 135 ComponentBase::OutputsMap & ComponentBase::outputs() 136 { 137 return m_outputs; 138 } 139 140 const ComponentBase::OutputsMap & ComponentBase::outputs() const 141 { 142 return m_outputs; 80 143 } 81 144 82 145 InputInterfaceBase * ComponentBase::getInput(QString inputName) const 83 146 { 84 85 if(input.contains(inputName)) 86 return input[inputName]; 87 else { 88 LOG_WARN("Component " << componentName << " does not containt input " << inputName); 89 return NULL; 147 if (inputs().contains(inputName)) { 148 return inputs()[inputName]; 90 149 } 150 LOG_WARN("Component " << name() << " does not contain input " << inputName); 151 return NULL; 91 152 } 92 153 … … 97 158 LOG_INFO("Key : " << keys[i])*/; 98 159 99 if(output.contains(outputName)) 100 return output[outputName]; 101 else { 102 LOG_WARN("Component " << componentName << " does not containt output " << outputName); 103 return NULL; 160 if (outputs().contains(outputName)) { 161 return outputs()[outputName]; 104 162 } 163 LOG_WARN("Component " << name() << " does not containt output " << outputName); 164 return NULL; 105 165 } 106 107 void ComponentBase::addInput()108 {109 110 }111 112 void ComponentBase::addOutput()113 {114 115 } -
branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp
r146 r152 254 254 } else { 255 255 component->param.localCopy(cfg.qDomElement()); 256 component-> configuration_ = component->configureComponent(cfg);256 component->setConfigurationState(component->configureComponent(cfg)); 257 257 } 258 258 } // for … … 267 267 LOG_WARN("component '" << componentName << "' does not exist"); 268 268 } else { 269 // Pacpus 2.0 : add input and output270 component->addInput ();271 component->addOutput ();272 273 if ( component->configuration_ == ComponentBase::CONFIGURATION_DELAYED) {269 // Pacpus 2.0 : add inputs and outputs 270 component->addInputs(); 271 component->addOutputs(); 272 273 if (ComponentBase::CONFIGURATION_DELAYED == component->configurationState()) { 274 274 LOG_DEBUG("try to configure component '" << componentName << "'"); 275 275 276 276 // copy locally the config parameters of the component 277 277 component->param.localCopy(cfg.qDomElement()); 278 component-> configuration_ = component->configureComponent(cfg);278 component->setConfigurationState(component->configureComponent(cfg)); 279 279 } 280 280 281 if ( component->configuration_ == ComponentBase::CONFIGURED_OK) {281 if (ComponentBase::CONFIGURED_OK == component->configurationState()) { 282 282 --componentsToConfigureCount; 283 283 } else { … … 286 286 << ". It was not configured, please review your configuration and/or your component" 287 287 ); 288 component-> configuration_ = ComponentBase::CONFIGURED_FAILED;288 component->setConfigurationState(ComponentBase::CONFIGURED_FAILED); 289 289 } 290 290 }
Note:
See TracChangeset
for help on using the changeset viewer.