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

Last change on this file since 73 was 66, checked in by Marek Kurdej, 11 years ago

Documentation: file info.

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