[76] | 1 | // %pacpus:license{
|
---|
[62] | 2 | // This file is part of the PACPUS framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[76] | 4 | // %pacpus:license}
|
---|
[66] | 5 | /// @file
|
---|
[62] | 6 | /// @author Gerald Dhermobez <firstname.surname@utc.fr>
|
---|
| 7 | /// @author Marek Kurdej <firstname.surname@utc.fr>
|
---|
| 8 | /// @author Samuel Gosselin <firstname.surname@utc.fr>
|
---|
[63] | 9 | /// @date February, 2006
|
---|
[62] | 10 | /// @version $Id: ComponentBase.h 116 2013-06-25 11:44:25Z kurdejma $
|
---|
| 11 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
[63] | 12 | /// @brief Generic ComponentBase class. This is an abstract class.
|
---|
[62] | 13 | ///
|
---|
| 14 | /// Detailed description.
|
---|
[63] | 15 | /// @todo - see if some methods can be private with ComponentManager
|
---|
| 16 | /// friendship
|
---|
| 17 | /// - include the copy of Xml node in param here
|
---|
| 18 | /// - see if there is a possibility to avoid the constraint
|
---|
| 19 | /// on parameters in the constructor of derived class
|
---|
[62] | 20 |
|
---|
[30] | 21 | #ifndef DEF_PACPUS_COMPONENTBASE_H
|
---|
| 22 | #define DEF_PACPUS_COMPONENTBASE_H
|
---|
[3] | 23 |
|
---|
[30] | 24 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
[116] | 25 | #include <Pacpus/kernel/PacpusLibConfig.h>
|
---|
[30] | 26 | #include <Pacpus/kernel/XmlComponentConfig.h>
|
---|
[3] | 27 |
|
---|
| 28 | #include <QString>
|
---|
| 29 |
|
---|
[42] | 30 | namespace pacpus {
|
---|
| 31 |
|
---|
| 32 | // Forward declarations.
|
---|
| 33 | class ComponentManager;
|
---|
| 34 |
|
---|
[116] | 35 | /// Base class of a Pacpus component.
|
---|
[42] | 36 | class PACPUSLIB_API ComponentBase
|
---|
[30] | 37 | {
|
---|
[3] | 38 | friend class ComponentManager;
|
---|
[116] | 39 |
|
---|
[42] | 40 | public:
|
---|
[116] | 41 | /// Enumeration of the state that can take a component, the three last states suppose
|
---|
| 42 | /// that the component is started.
|
---|
[42] | 43 | enum COMPONENT_STATE
|
---|
| 44 | {
|
---|
[116] | 45 | STOPPED,
|
---|
| 46 | NOT_MONITORED,
|
---|
| 47 | MONITOR_OK,
|
---|
| 48 | MONITOR_NOK
|
---|
[42] | 49 | };
|
---|
[3] | 50 |
|
---|
[116] | 51 | /// Resulting state of a component after its configuration.
|
---|
[42] | 52 | enum COMPONENT_CONFIGURATION
|
---|
| 53 | {
|
---|
[116] | 54 | CONFIGURED_OK,
|
---|
| 55 | NOT_CONFIGURED,
|
---|
| 56 | CONFIGURATION_DELAYED,
|
---|
| 57 | CONFIGURED_FAILED
|
---|
[42] | 58 | };
|
---|
[3] | 59 |
|
---|
[116] | 60 | /// Ctor of ComponentBase.
|
---|
| 61 | /// @param name Name of your component.
|
---|
| 62 | ComponentBase(const QString & name);
|
---|
[3] | 63 |
|
---|
[116] | 64 | /// Dtor of ComponentBase.
|
---|
[42] | 65 | virtual ~ComponentBase();
|
---|
[3] | 66 |
|
---|
[116] | 67 | /// @returns Value of the current state.
|
---|
[42] | 68 | COMPONENT_STATE getState();
|
---|
[3] | 69 |
|
---|
[116] | 70 | /// Checks whether the component if configurer or not.
|
---|
| 71 | /// @returns @b true if the component is configured, @b false otherwise.
|
---|
[42] | 72 | bool isConfigured() const;
|
---|
[3] | 73 |
|
---|
[42] | 74 | protected:
|
---|
[116] | 75 | /// Change the state of the component.
|
---|
| 76 | /// @param state New component state.
|
---|
[42] | 77 | void setState(COMPONENT_STATE state);
|
---|
[3] | 78 |
|
---|
[116] | 79 | /// Called when the component starts, you must override this function.
|
---|
[42] | 80 | virtual void startActivity() = 0;
|
---|
[3] | 81 |
|
---|
[116] | 82 | /// Called when the component stops, you must override this function.
|
---|
[42] | 83 | virtual void stopActivity() = 0;
|
---|
[3] | 84 |
|
---|
[116] | 85 | /// Called by the ComponentManager, it configure the component thanks a XML node.
|
---|
| 86 | /// @param config Component's XML node.
|
---|
| 87 | /// @returns State of the configuration.
|
---|
| 88 | /// @todo FIXME: 'config' should be const, but we can't change the prototype without breaking old stuff.
|
---|
[42] | 89 | virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0;
|
---|
[116] | 90 |
|
---|
[61] | 91 | protected:
|
---|
| 92 | /// The XML node that is got in the configureComponent method
|
---|
[42] | 93 | XmlComponentConfig param;
|
---|
[3] | 94 |
|
---|
[61] | 95 | /// the name of the component. It is this one in the XML config file
|
---|
[42] | 96 | QString componentName;
|
---|
[3] | 97 |
|
---|
[61] | 98 | /// is the component is recording data?
|
---|
[42] | 99 | bool recording;
|
---|
[3] | 100 |
|
---|
[61] | 101 | /// provided for compatibility with old DBITE framework
|
---|
[42] | 102 | bool THREAD_ALIVE;
|
---|
[3] | 103 |
|
---|
[61] | 104 | /// is the component active?
|
---|
[42] | 105 | bool mIsActive;
|
---|
[3] | 106 |
|
---|
[61] | 107 | /// a pointer to the manager of components
|
---|
[42] | 108 | ComponentManager * mgr;
|
---|
[3] | 109 |
|
---|
[42] | 110 | private:
|
---|
[61] | 111 | /// called by the ComponentManager to start the component
|
---|
[42] | 112 | int startComponent();
|
---|
[3] | 113 |
|
---|
[61] | 114 | /// called by the ComponentManager to stop the component
|
---|
[42] | 115 | int stopComponent();
|
---|
[3] | 116 |
|
---|
[61] | 117 | /// store the state of the component
|
---|
[42] | 118 | COMPONENT_STATE componentState_;
|
---|
[3] | 119 |
|
---|
[61] | 120 | /// is the component configured (ie configureComponent method was called)
|
---|
[42] | 121 | COMPONENT_CONFIGURATION configuration_;
|
---|
| 122 | };
|
---|
[3] | 123 |
|
---|
[116] | 124 | } // namespace pacpus
|
---|
[42] | 125 |
|
---|
| 126 | #endif // DEF_PACPUS_COMPONENTBASE_H
|
---|