- Timestamp:
- Jan 8, 2013, 5:32:28 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/ComponentBase.h
r3 r30 1 // ********************************************************************* 2 // created: 2006/02/07 - 11:59 3 // filename: component.h 4 // 5 // author: Gerald Dherbomez 6 // 7 // purpose: generic ComponentBase class. This is an abstract class 8 // 9 // todo: - see if some methods can be private with ComponentManager 10 // friendship 11 // - include the copy of Xml node in param here 12 // - see if there is a possibility to avoid the constraint 13 // on parameters in the constructor of derived class 14 // ********************************************************************* 1 /** 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 * 9 */ 10 11 #ifndef DEF_PACPUS_COMPONENTBASE_H 12 #define DEF_PACPUS_COMPONENTBASE_H 15 13 16 #ifndef COMPONENTBASE_H 17 #define COMPONENTBASE_H 18 19 #include "kernel/ComponentManager.h" // FIXME: remove this line when all components include it 20 #include "kernel/pacpus.h" 21 #include "XmlComponentConfig.h" 14 #include <Pacpus/kernel/ComponentManager.h> 15 #include <Pacpus/kernel/pacpus.h> 16 #include <Pacpus/kernel/XmlComponentConfig.h> 22 17 23 18 #include <QString> 24 19 25 namespace pacpus { 20 namespace pacpus 21 { 22 class ComponentManager; 26 23 27 class ComponentManager; 28 29 class PACPUSLIB_API ComponentBase 30 { 24 /** ComponentBase 25 * @brief Base class of a Pacpus component. 26 */ 27 class PACPUSLIB_API ComponentBase 28 { 31 29 friend class ComponentManager; 32 33 public: 34 // Here is the enumeration of the state that can take a component 35 // The 3 last states suppose that the component is started 36 enum COMPONENT_STATE 37 { 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 { 38 37 STOPPED, 39 38 NOT_MONITORED, 40 39 MONITOR_OK, 41 40 MONITOR_NOK 42 };41 }; 43 42 44 // The different identifying the configuration of the component45 enum COMPONENT_CONFIGURATION46 {43 /** Resulting state of a component after its configuration. */ 44 enum COMPONENT_CONFIGURATION 45 { 47 46 CONFIGURED_OK, 48 47 NOT_CONFIGURED, 49 48 CONFIGURATION_DELAYED, 50 49 CONFIGURED_FAILED 51 };50 }; 52 51 53 // constructor - your derived component must have only one parameter 54 // in its constructor which is name 55 ComponentBase(QString name); 52 /** Ctor of ComponentBase. 53 * @param name Name of your component. 54 */ 55 ComponentBase(const QString& name); 56 56 57 // destructor58 virtual ~ComponentBase();57 /** Dtor of ComponentBase. */ 58 virtual ~ComponentBase(); 59 59 60 // return the state of the component 61 COMPONENT_STATE getState(); 60 /** Return the state of the component. 61 * @return Value of the current state. 62 */ 63 COMPONENT_STATE getState(); 62 64 63 // return true if the component is configured, false else 64 inline bool isConfigured() 65 { 66 return (CONFIGURED_OK == configuration_); 67 } 65 /** Check whether the component if configurer or not. 66 * @return True if the component is configured, otherwise false. 67 */ 68 bool isConfigured() const; 68 69 69 protected: 70 // define the state of the component 71 void setState(COMPONENT_STATE state); 70 protected: 71 /** Change the state of the component. 72 * @param state New component state. 73 */ 74 void setState(COMPONENT_STATE state); 72 75 73 // pure virtual function - what to do when the component starts?74 virtual void startActivity() = 0;76 /** Called when the component starts, you must override this function. */ 77 virtual void startActivity() = 0; 75 78 76 // pure virtual function - what to do when the component stops?77 virtual void stopActivity() = 0;79 /** Called when the component stops, you must override this function. */ 80 virtual void stopActivity() = 0; 78 81 79 // This function is called by the ComponentManager when it loads the XML file 80 // It gives to the component the XML node corresponding to its 81 // So the component can handle some properties defined in the XML config file 82 // via XmlComponentConfig methods 83 virtual COMPONENT_CONFIGURATION configureComponent(pacpus::XmlComponentConfig config) = 0; 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; 84 89 85 // The XML node that is got in the configureComponent method86 pacpus::XmlComponentConfig param;90 // The XML node that is got in the configureComponent method 91 XmlComponentConfig param; 87 92 88 // the name of the component. It is this one in the XML config file89 QString componentName;93 // the name of the component. It is this one in the XML config file 94 QString componentName; 90 95 91 // is the component is recording data?92 bool recording;96 // is the component is recording data? 97 bool recording; 93 98 94 // provided for compatibility with old DBITE framework95 bool THREAD_ALIVE;99 // provided for compatibility with old DBITE framework 100 bool THREAD_ALIVE; 96 101 97 // is the component active?98 bool mIsActive;102 // is the component active? 103 bool mIsActive; 99 104 100 // a pointer to the manager of components101 ComponentManager * mgr;105 // a pointer to the manager of components 106 ComponentManager * mgr; 102 107 103 private:104 // called by the ComponentManager to start the component105 int startComponent();108 private: 109 // called by the ComponentManager to start the component 110 int startComponent(); 106 111 107 // called by the ComponentManager to stop the component108 int stopComponent();112 // called by the ComponentManager to stop the component 113 int stopComponent(); 109 114 110 // store the state of the component111 COMPONENT_STATE componentState_;115 // store the state of the component 116 COMPONENT_STATE componentState_; 112 117 113 // is the component configured (ie configureComponent method was called) 114 COMPONENT_CONFIGURATION configuration_; 115 }; 118 // is the component configured (ie configureComponent method was called) 119 COMPONENT_CONFIGURATION configuration_; 120 }; 121 } 116 122 117 } // namespace pacpus 118 119 #endif // COMPONENTBASE_H 123 #endif -
trunk/src/PacpusLib/ComponentBase.cpp
r3 r30 8 8 *********************************************************************/ 9 9 10 #include "kernel/ComponentBase.h" 10 #include <Pacpus/kernel/ComponentBase.h> 11 #include <Pacpus/kernel/ComponentManager.h> 12 #include <Pacpus/kernel/Log.h> 11 13 12 #include "kernel/ComponentManager.h" 13 #include "kernel/Log.h" 14 15 namespace pacpus { 14 using namespace pacpus; 16 15 17 16 DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase"); 18 17 19 ComponentBase::ComponentBase( QStringname)18 ComponentBase::ComponentBase(const QString& name) 20 19 { 21 20 LOG_TRACE("constructor"); … … 40 39 LOG_TRACE("destructor"); 41 40 } 42 43 //TODO44 //COMPONENT_CONFIGURATION ComponentBase::configureComponent(XmlComponentConfig config)45 //{46 //}47 41 48 42 int ComponentBase::startComponent() … … 75 69 } 76 70 77 // return the state of the component71 // FIXME: this should be const. 78 72 ComponentBase::COMPONENT_STATE ComponentBase::getState() 79 73 { … … 85 79 } 86 80 87 } // namespace pacpus 81 bool ComponentBase::isConfigured() const 82 { 83 return CONFIGURED_OK == configuration_; 84 }
Note:
See TracChangeset
for help on using the changeset viewer.