source: pacpusframework/trunk/include/Pacpus/kernel/ComponentBase.h@ 64

Last change on this file since 64 was 64, checked in by Marek Kurdej, 12 years ago

Modified property: added svn:keywords=Id.

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