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

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

Added: automated license updating lines:
%pacpus:license{
%pacpus:license}

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