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

Last change on this file since 57 was 42, checked in by sgosseli, 12 years ago
  • Coding style
  • License header
  • Some clean-up
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
93 // The XML node that is got in the configureComponent method
94 XmlComponentConfig param;
95
96 // the name of the component. It is this one in the XML config file
97 QString componentName;
98
99 // is the component is recording data?
100 bool recording;
101
102 // provided for compatibility with old DBITE framework
103 bool THREAD_ALIVE;
104
105 // is the component active?
106 bool mIsActive;
107
108 // a pointer to the manager of components
109 ComponentManager * mgr;
110
111private:
112 // called by the ComponentManager to start the component
113 int startComponent();
114
115 // called by the ComponentManager to stop the component
116 int stopComponent();
117
118 // store the state of the component
119 COMPONENT_STATE componentState_;
120
121 // is the component configured (ie configureComponent method was called)
122 COMPONENT_CONFIGURATION configuration_;
123};
124
125} // pacpus
126
127#endif // DEF_PACPUS_COMPONENTBASE_H
Note: See TracBrowser for help on using the repository browser.