| 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 | /// @file
|
|---|
| 6 | /// @author Gerald Dhermobez <firstname.surname@utc.fr>
|
|---|
| 7 | /// @author Marek Kurdej <firstname.surname@utc.fr>
|
|---|
| 8 | /// @author Samuel Gosselin <firstname.surname@utc.fr>
|
|---|
| 9 | /// @date February, 2006
|
|---|
| 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.
|
|---|
| 12 | /// @brief Generic ComponentBase class. This is an abstract class.
|
|---|
| 13 | ///
|
|---|
| 14 | /// Detailed description.
|
|---|
| 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
|
|---|
| 20 |
|
|---|
| 21 | #ifndef DEF_PACPUS_COMPONENTBASE_H
|
|---|
| 22 | #define DEF_PACPUS_COMPONENTBASE_H
|
|---|
| 23 |
|
|---|
| 24 | #include <Pacpus/kernel/ComponentManager.h>
|
|---|
| 25 | #include <Pacpus/kernel/PacpusLibConfig.h>
|
|---|
| 26 | #include <Pacpus/kernel/XmlComponentConfig.h>
|
|---|
| 27 |
|
|---|
| 28 | #include <QString>
|
|---|
| 29 |
|
|---|
| 30 | namespace pacpus {
|
|---|
| 31 |
|
|---|
| 32 | // Forward declarations.
|
|---|
| 33 | class ComponentManager;
|
|---|
| 34 |
|
|---|
| 35 | /// Base class of a Pacpus component.
|
|---|
| 36 | class PACPUSLIB_API ComponentBase
|
|---|
| 37 | {
|
|---|
| 38 | friend class ComponentManager;
|
|---|
| 39 |
|
|---|
| 40 | public:
|
|---|
| 41 | /// Enumeration of the state that can take a component, the three last states suppose
|
|---|
| 42 | /// that the component is started.
|
|---|
| 43 | enum COMPONENT_STATE
|
|---|
| 44 | {
|
|---|
| 45 | STOPPED,
|
|---|
| 46 | NOT_MONITORED,
|
|---|
| 47 | MONITOR_OK,
|
|---|
| 48 | MONITOR_NOK
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | /// Resulting state of a component after its configuration.
|
|---|
| 52 | enum COMPONENT_CONFIGURATION
|
|---|
| 53 | {
|
|---|
| 54 | CONFIGURED_OK,
|
|---|
| 55 | NOT_CONFIGURED,
|
|---|
| 56 | CONFIGURATION_DELAYED,
|
|---|
| 57 | CONFIGURED_FAILED
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | /// Ctor of ComponentBase.
|
|---|
| 61 | /// @param name Name of your component.
|
|---|
| 62 | ComponentBase(const QString & name);
|
|---|
| 63 |
|
|---|
| 64 | /// Dtor of ComponentBase.
|
|---|
| 65 | virtual ~ComponentBase();
|
|---|
| 66 |
|
|---|
| 67 | /// @returns Value of the current state.
|
|---|
| 68 | COMPONENT_STATE getState();
|
|---|
| 69 |
|
|---|
| 70 | /// Checks whether the component if configurer or not.
|
|---|
| 71 | /// @returns @b true if the component is configured, @b false otherwise.
|
|---|
| 72 | bool isConfigured() const;
|
|---|
| 73 |
|
|---|
| 74 | protected:
|
|---|
| 75 | /// Change the state of the component.
|
|---|
| 76 | /// @param state New component state.
|
|---|
| 77 | void setState(COMPONENT_STATE state);
|
|---|
| 78 |
|
|---|
| 79 | /// Called when the component starts, you must override this function.
|
|---|
| 80 | virtual void startActivity() = 0;
|
|---|
| 81 |
|
|---|
| 82 | /// Called when the component stops, you must override this function.
|
|---|
| 83 | virtual void stopActivity() = 0;
|
|---|
| 84 |
|
|---|
| 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.
|
|---|
| 89 | virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0;
|
|---|
| 90 |
|
|---|
| 91 | protected:
|
|---|
| 92 | /// The XML node that is got in the configureComponent method
|
|---|
| 93 | XmlComponentConfig param;
|
|---|
| 94 |
|
|---|
| 95 | /// the name of the component. It is this one in the XML config file
|
|---|
| 96 | QString componentName;
|
|---|
| 97 |
|
|---|
| 98 | /// is the component is recording data?
|
|---|
| 99 | bool recording;
|
|---|
| 100 |
|
|---|
| 101 | /// provided for compatibility with old DBITE framework
|
|---|
| 102 | bool THREAD_ALIVE;
|
|---|
| 103 |
|
|---|
| 104 | /// is the component active?
|
|---|
| 105 | bool mIsActive;
|
|---|
| 106 |
|
|---|
| 107 | /// a pointer to the manager of components
|
|---|
| 108 | ComponentManager * mgr;
|
|---|
| 109 |
|
|---|
| 110 | private:
|
|---|
| 111 | /// called by the ComponentManager to start the component
|
|---|
| 112 | int startComponent();
|
|---|
| 113 |
|
|---|
| 114 | /// called by the ComponentManager to stop the component
|
|---|
| 115 | int stopComponent();
|
|---|
| 116 |
|
|---|
| 117 | /// store the state of the component
|
|---|
| 118 | COMPONENT_STATE componentState_;
|
|---|
| 119 |
|
|---|
| 120 | /// is the component configured (ie configureComponent method was called)
|
|---|
| 121 | COMPONENT_CONFIGURATION configuration_;
|
|---|
| 122 | };
|
|---|
| 123 |
|
|---|
| 124 | } // namespace pacpus
|
|---|
| 125 |
|
|---|
| 126 | #endif // DEF_PACPUS_COMPONENTBASE_H
|
|---|