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

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

Added: some documentation and doc todo comments.

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