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

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

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