[89] | 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>
|
---|
[138] | 9 | /// @author Julien Moras <firstname.surname@utc.fr>
|
---|
[89] | 10 | /// @date February, 2006
|
---|
| 11 | /// @version $Id: ComponentBase.h 76 2013-01-10 17:05:10Z kurdejma $
|
---|
| 12 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
| 13 | /// @brief Generic ComponentBase class. This is an abstract class.
|
---|
| 14 | ///
|
---|
| 15 | /// Detailed description.
|
---|
| 16 | /// @todo - see if some methods can be private with ComponentManager
|
---|
| 17 | /// friendship
|
---|
| 18 | /// - include the copy of Xml node in param here
|
---|
| 19 | /// - see if there is a possibility to avoid the constraint
|
---|
| 20 | /// on parameters in the constructor of derived class
|
---|
| 21 |
|
---|
| 22 | #ifndef DEF_PACPUS_COMPONENTBASE_H
|
---|
| 23 | #define DEF_PACPUS_COMPONENTBASE_H
|
---|
| 24 |
|
---|
| 25 | #include <Pacpus/kernel/ComponentManager.h>
|
---|
| 26 | #include <Pacpus/kernel/pacpus.h>
|
---|
| 27 | #include <Pacpus/kernel/XmlComponentConfig.h>
|
---|
[138] | 28 | #include <Pacpus/kernel/InputOutputBase.h>
|
---|
[89] | 29 |
|
---|
| 30 | #include <QString>
|
---|
| 31 | #include <QMap>
|
---|
| 32 |
|
---|
[110] | 33 | class QWidget;
|
---|
| 34 |
|
---|
[89] | 35 | namespace pacpus {
|
---|
| 36 |
|
---|
| 37 | // Forward declarations.
|
---|
| 38 | class ComponentManager;
|
---|
| 39 |
|
---|
| 40 | /** ComponentBase
|
---|
| 41 | * @brief Base class of a Pacpus component.
|
---|
| 42 | */
|
---|
| 43 | class PACPUSLIB_API ComponentBase
|
---|
| 44 | {
|
---|
| 45 | friend class ComponentManager;
|
---|
| 46 | public:
|
---|
| 47 | /**
|
---|
| 48 | * Enumeration of the state that can take a component, the three last states suppose
|
---|
| 49 | * that the component is started.
|
---|
| 50 | */
|
---|
| 51 | enum COMPONENT_STATE
|
---|
| 52 | {
|
---|
| 53 | STOPPED,
|
---|
| 54 | NOT_MONITORED,
|
---|
| 55 | MONITOR_OK,
|
---|
| 56 | MONITOR_NOK
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | /** Resulting state of a component after its configuration. */
|
---|
| 60 | enum COMPONENT_CONFIGURATION
|
---|
| 61 | {
|
---|
| 62 | CONFIGURED_OK,
|
---|
| 63 | NOT_CONFIGURED,
|
---|
| 64 | CONFIGURATION_DELAYED,
|
---|
| 65 | CONFIGURED_FAILED
|
---|
| 66 | };
|
---|
| 67 |
|
---|
| 68 | /** Ctor of ComponentBase.
|
---|
| 69 | * @param name Name of your component.
|
---|
| 70 | */
|
---|
| 71 | ComponentBase(const QString& name);
|
---|
| 72 |
|
---|
| 73 | /** Dtor of ComponentBase. */
|
---|
| 74 | virtual ~ComponentBase();
|
---|
| 75 |
|
---|
| 76 | /** Return the state of the component.
|
---|
| 77 | * @return Value of the current state.
|
---|
| 78 | */
|
---|
| 79 | COMPONENT_STATE getState();
|
---|
| 80 |
|
---|
| 81 | /** Check whether the component if configurer or not.
|
---|
| 82 | * @return True if the component is configured, otherwise false.
|
---|
| 83 | */
|
---|
| 84 | bool isConfigured() const;
|
---|
| 85 |
|
---|
| 86 | /** Return the name of the component.
|
---|
| 87 | * @return Name of the component.
|
---|
| 88 | */
|
---|
| 89 | QString getName() const;
|
---|
| 90 |
|
---|
| 91 | InputInterfaceBase * getInput(QString) const;
|
---|
| 92 |
|
---|
| 93 | OutputInterfaceBase * getOutput(QString) const;
|
---|
| 94 |
|
---|
| 95 | protected:
|
---|
| 96 | /** Change the state of the component.
|
---|
| 97 | * @param state New component state.
|
---|
| 98 | */
|
---|
| 99 | void setState(COMPONENT_STATE state);
|
---|
| 100 |
|
---|
| 101 | /** Called when the component starts, you must override this function. */
|
---|
| 102 | virtual void startActivity() = 0;
|
---|
| 103 |
|
---|
| 104 | /** Called when the component stops, you must override this function. */
|
---|
| 105 | virtual void stopActivity() = 0;
|
---|
| 106 |
|
---|
| 107 | /** Called by the ComponentManager, it configure the component thanks a XML node.
|
---|
| 108 | * @param config Component's XML node.
|
---|
| 109 | * @return State of the configuration.
|
---|
| 110 | * FIXME: 'config' should be const, but we can't change the prototype without breaking
|
---|
| 111 | * old stuff.
|
---|
| 112 | */
|
---|
| 113 | virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0;
|
---|
| 114 |
|
---|
| 115 | // virtual QString getType() = 0;
|
---|
[120] | 116 |
|
---|
| 117 | virtual void addInput();
|
---|
| 118 |
|
---|
| 119 | virtual void addOutput();
|
---|
[89] | 120 |
|
---|
| 121 | protected:
|
---|
| 122 | /// The XML node that is got in the configureComponent method
|
---|
| 123 | XmlComponentConfig param;
|
---|
| 124 |
|
---|
| 125 | /// the name of the component. It is this one in the XML config file
|
---|
| 126 | QString componentName;
|
---|
| 127 |
|
---|
| 128 | /// is the component is recording data?
|
---|
| 129 | bool recording;
|
---|
| 130 |
|
---|
| 131 | /// provided for compatibility with old DBITE framework
|
---|
| 132 | bool THREAD_ALIVE;
|
---|
| 133 |
|
---|
| 134 | /// is the component active?
|
---|
| 135 | bool mIsActive;
|
---|
| 136 |
|
---|
| 137 | /// a pointer to the manager of components
|
---|
| 138 | ComponentManager * mgr;
|
---|
| 139 |
|
---|
| 140 | QMap<QString, InputInterfaceBase *> input;
|
---|
| 141 | QMap<QString, OutputInterfaceBase *> output;
|
---|
| 142 |
|
---|
[138] | 143 | /// a pointer to an optional widget
|
---|
[110] | 144 | QWidget * ui;
|
---|
| 145 |
|
---|
[89] | 146 | private:
|
---|
| 147 | /// called by the ComponentManager to start the component
|
---|
| 148 | int startComponent();
|
---|
| 149 |
|
---|
| 150 | /// called by the ComponentManager to stop the component
|
---|
| 151 | int stopComponent();
|
---|
| 152 |
|
---|
| 153 | /// store the state of the component
|
---|
| 154 | COMPONENT_STATE componentState_;
|
---|
| 155 |
|
---|
| 156 | /// is the component configured (ie configureComponent method was called)
|
---|
| 157 | COMPONENT_CONFIGURATION configuration_;
|
---|
| 158 | };
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | } // pacpus
|
---|
| 162 |
|
---|
| 163 | #endif // DEF_PACPUS_COMPONENTBASE_H
|
---|