Changeset 42 in pacpusframework
- Timestamp:
- Jan 8, 2013, 9:44:51 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/ComponentBase.h
r30 r42 1 1 /** 2 2 * 3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0. 4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved. 5 * 6 * See the LICENSE file for more information or a copy at: 7 * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt 8 * 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 * 9 11 */ 10 12 … … 18 20 #include <QString> 19 21 20 namespace pacpus 22 namespace pacpus { 23 24 // Forward declarations. 25 class ComponentManager; 26 27 /** ComponentBase 28 * @brief Base class of a Pacpus component. 29 */ 30 class PACPUSLIB_API ComponentBase 21 31 { 22 class ComponentManager; 32 friend class ComponentManager; 33 public: 34 /** 35 * Enumeration of the state that can take a component, the three last states suppose 36 * that the component is started. 37 */ 38 enum COMPONENT_STATE 39 { 40 STOPPED, 41 NOT_MONITORED, 42 MONITOR_OK, 43 MONITOR_NOK 44 }; 23 45 24 /** ComponentBase 25 * @brief Base class of a Pacpus component. 26 */ 27 class PACPUSLIB_API ComponentBase 28 { 29 friend class ComponentManager; 30 public: 31 /** 32 * Enumeration of the state that can take a component, the three last states suppose 33 * that the component is started. 34 */ 35 enum COMPONENT_STATE 36 { 37 STOPPED, 38 NOT_MONITORED, 39 MONITOR_OK, 40 MONITOR_NOK 41 }; 46 /** Resulting state of a component after its configuration. */ 47 enum COMPONENT_CONFIGURATION 48 { 49 CONFIGURED_OK, 50 NOT_CONFIGURED, 51 CONFIGURATION_DELAYED, 52 CONFIGURED_FAILED 53 }; 42 54 43 /** Resulting state of a component after its configuration. */ 44 enum COMPONENT_CONFIGURATION 45 { 46 CONFIGURED_OK, 47 NOT_CONFIGURED, 48 CONFIGURATION_DELAYED, 49 CONFIGURED_FAILED 50 }; 55 /** Ctor of ComponentBase. 56 * @param name Name of your component. 57 */ 58 ComponentBase(const QString& name); 51 59 52 /** Ctor of ComponentBase. 53 * @param name Name of your component. 54 */ 55 ComponentBase(const QString& name); 60 /** Dtor of ComponentBase. */ 61 virtual ~ComponentBase(); 56 62 57 /** Dtor of ComponentBase. */ 58 virtual ~ComponentBase(); 63 /** Return the state of the component. 64 * @return Value of the current state. 65 */ 66 COMPONENT_STATE getState(); 59 67 60 /** Return the state of the component.61 * @return Value of the current state.62 63 COMPONENT_STATE getState();68 /** Check whether the component if configurer or not. 69 * @return True if the component is configured, otherwise false. 70 */ 71 bool isConfigured() const; 64 72 65 /** Check whether the component if configurer or not. 66 * @return True if the component is configured, otherwise false. 67 */ 68 bool isConfigured() const; 73 protected: 74 /** Change the state of the component. 75 * @param state New component state. 76 */ 77 void setState(COMPONENT_STATE state); 69 78 70 protected: 71 /** Change the state of the component. 72 * @param state New component state. 73 */ 74 void setState(COMPONENT_STATE state); 79 /** Called when the component starts, you must override this function. */ 80 virtual void startActivity() = 0; 75 81 76 /** Called when the component starts, you must override this function. */77 virtual void startActivity() = 0;82 /** Called when the component stops, you must override this function. */ 83 virtual void stopActivity() = 0; 78 84 79 /** Called when the component stops, you must override this function. */ 80 virtual void stopActivity() = 0; 85 /** Called by the ComponentManager, it configure the component thanks a XML node. 86 * @param config Component's XML node. 87 * @return State of the configuration. 88 * FIXME: 'config' should be const, but we can't change the prototype without breaking 89 * old stuff. 90 */ 91 virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0; 81 92 82 /** Called by the ComponentManager, it configure the component thanks a XML node. 83 * @param config Component's XML node. 84 * @return State of the configuration. 85 * FIXME: 'config' should be const, but we can't change the prototype without breaking 86 * old stuff. 87 */ 88 virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0; 93 // The XML node that is got in the configureComponent method 94 XmlComponentConfig param; 89 95 90 // The XML node that is got in the configureComponent method91 XmlComponentConfig param;96 // the name of the component. It is this one in the XML config file 97 QString componentName; 92 98 93 // the name of the component. It is this one in the XML config file94 QString componentName;99 // is the component is recording data? 100 bool recording; 95 101 96 // is the component is recording data?97 bool recording;102 // provided for compatibility with old DBITE framework 103 bool THREAD_ALIVE; 98 104 99 // provided for compatibility with old DBITE framework100 bool THREAD_ALIVE;105 // is the component active? 106 bool mIsActive; 101 107 102 // is the component active?103 bool mIsActive;108 // a pointer to the manager of components 109 ComponentManager * mgr; 104 110 105 // a pointer to the manager of components 106 ComponentManager * mgr; 111 private: 112 // called by the ComponentManager to start the component 113 int startComponent(); 107 114 108 private: 109 // called by the ComponentManager to start the component 110 int startComponent(); 115 // called by the ComponentManager to stop the component 116 int stopComponent(); 111 117 112 // called by the ComponentManager to stopthe component113 int stopComponent();118 // store the state of the component 119 COMPONENT_STATE componentState_; 114 120 115 // store the state of the component 116 COMPONENT_STATE componentState_; 121 // is the component configured (ie configureComponent method was called) 122 COMPONENT_CONFIGURATION configuration_; 123 }; 117 124 118 // is the component configured (ie configureComponent method was called) 119 COMPONENT_CONFIGURATION configuration_; 120 }; 121 } 125 } // pacpus 122 126 123 #endif 127 #endif // DEF_PACPUS_COMPONENTBASE_H -
trunk/src/PacpusLib/ComponentBase.cpp
r31 r42 1 1 /** 2 2 * 3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0. 4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved. 5 * 6 * See the LICENSE file for more information or a copy at: 7 * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt 8 * 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 * 9 11 */ 10 12 … … 18 20 19 21 ComponentBase::ComponentBase(const QString& name) 22 : componentName(name) 23 , recording(true) 24 , THREAD_ALIVE(true) 25 , mIsActive(false) 26 , mgr(NULL) 27 , componentState_(NOT_MONITORED) 20 28 { 21 29 LOG_TRACE("constructor"); 22 23 configuration_ = NOT_CONFIGURED; 24 componentName = name; 25 recording = true; 26 THREAD_ALIVE = true; 27 mIsActive = 0; 28 componentState_ = ComponentBase::NOT_MONITORED; 29 30 // we get a pointer on the instance of ComponentManager 30 // Get a pointer on the instance of ComponentManager. 31 31 mgr = ComponentManager::getInstance(); 32 33 LOG_INFO("component " << componentName 34 << " was created" 35 ); 32 LOG_INFO("component " << componentName << " was created"); 36 33 } 37 34 … … 43 40 int ComponentBase::startComponent() 44 41 { 45 if (mIsActive == 0) {46 mIsActive = 1;47 startActivity();48 return 1;49 } else {50 return 0;51 }42 if (mIsActive) 43 return false; 44 45 mIsActive = true; 46 startActivity(); 47 48 return true; 52 49 } 53 50 54 51 int ComponentBase::stopComponent() 55 52 { 56 if ( mIsActive == 1) {57 mIsActive = 0;58 stopActivity(); 59 return 1;60 } else {61 return 0;62 }53 if (!mIsActive) 54 return false; 55 56 mIsActive = false; 57 stopActivity(); 58 59 return true; 63 60 } 64 61 65 62 void ComponentBase::setState(const COMPONENT_STATE state) 66 63 { 67 if (state != componentState_) { 68 componentState_ = state; 69 } 64 componentState_ = state; 70 65 } 71 66 … … 82 77 bool ComponentBase::isConfigured() const 83 78 { 84 return CONFIGURED_OK == configuration_;79 return configuration_ == CONFIGURED_OK; 85 80 }
Note:
See TracChangeset
for help on using the changeset viewer.