source: pacpusframework/branches/2.0-beta1/include/Pacpus/kernel/ComponentBase.h@ 135

Last change on this file since 135 was 120, checked in by morasjul, 11 years ago
  • add PacpusSerialport (QT 5.1 required)
  • add part of QT4 / QT5 cmake script
  • fix CMake (link)
  • add ComponentBase virtual function addInput() & addOutput() call before component configuration
  • Property svn:executable set to *
File size: 4.5 KB
Line 
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 76 2013-01-10 17:05:10Z 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/pacpus.h>
26#include <Pacpus/kernel/XmlComponentConfig.h>
27#include <Pacpus/kernel/inputOutputBase.h>
28
29#include <QString>
30#include <QMap>
31
32class QWidget;
33
34namespace pacpus {
35
36// Forward declarations.
37class ComponentManager;
38
39/** ComponentBase
40 * @brief Base class of a Pacpus component.
41 */
42class PACPUSLIB_API ComponentBase
43{
44 friend class ComponentManager;
45public:
46 /**
47 * Enumeration of the state that can take a component, the three last states suppose
48 * that the component is started.
49 */
50 enum COMPONENT_STATE
51 {
52 STOPPED,
53 NOT_MONITORED,
54 MONITOR_OK,
55 MONITOR_NOK
56 };
57
58 /** Resulting state of a component after its configuration. */
59 enum COMPONENT_CONFIGURATION
60 {
61 CONFIGURED_OK,
62 NOT_CONFIGURED,
63 CONFIGURATION_DELAYED,
64 CONFIGURED_FAILED
65 };
66
67 /** Ctor of ComponentBase.
68 * @param name Name of your component.
69 */
70 ComponentBase(const QString& name);
71
72 /** Dtor of ComponentBase. */
73 virtual ~ComponentBase();
74
75 /** Return the state of the component.
76 * @return Value of the current state.
77 */
78 COMPONENT_STATE getState();
79
80 /** Check whether the component if configurer or not.
81 * @return True if the component is configured, otherwise false.
82 */
83 bool isConfigured() const;
84
85 /** Return the name of the component.
86 * @return Name of the component.
87 */
88 QString getName() const;
89
90 InputInterfaceBase * getInput(QString) const;
91
92 OutputInterfaceBase * getOutput(QString) const;
93
94protected:
95 /** Change the state of the component.
96 * @param state New component state.
97 */
98 void setState(COMPONENT_STATE state);
99
100 /** Called when the component starts, you must override this function. */
101 virtual void startActivity() = 0;
102
103 /** Called when the component stops, you must override this function. */
104 virtual void stopActivity() = 0;
105
106 /** Called by the ComponentManager, it configure the component thanks a XML node.
107 * @param config Component's XML node.
108 * @return State of the configuration.
109 * FIXME: 'config' should be const, but we can't change the prototype without breaking
110 * old stuff.
111 */
112 virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0;
113
114 // virtual QString getType() = 0;
115
116 virtual void addInput();
117
118 virtual void addOutput();
119
120protected:
121 /// The XML node that is got in the configureComponent method
122 XmlComponentConfig param;
123
124 /// the name of the component. It is this one in the XML config file
125 QString componentName;
126
127 /// is the component is recording data?
128 bool recording;
129
130 /// provided for compatibility with old DBITE framework
131 bool THREAD_ALIVE;
132
133 /// is the component active?
134 bool mIsActive;
135
136 /// a pointer to the manager of components
137 ComponentManager * mgr;
138
139 QMap<QString, InputInterfaceBase *> input;
140 QMap<QString, OutputInterfaceBase *> output;
141
142 QWidget * ui;
143
144private:
145 /// called by the ComponentManager to start the component
146 int startComponent();
147
148 /// called by the ComponentManager to stop the component
149 int stopComponent();
150
151 /// store the state of the component
152 COMPONENT_STATE componentState_;
153
154 /// is the component configured (ie configureComponent method was called)
155 COMPONENT_CONFIGURATION configuration_;
156};
157
158
159} // pacpus
160
161#endif // DEF_PACPUS_COMPONENTBASE_H
Note: See TracBrowser for help on using the repository browser.