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