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

Last change on this file since 18 was 3, checked in by sgosseli, 12 years ago
  • Add the existing Pacpus files from pacpusdev and pacpuscore.
  • Provide a clean build system based on multiple CMake files.
File size: 3.5 KB
RevLine 
[3]1// *********************************************************************
2// created: 2006/02/07 - 11:59
3// filename: component.h
4//
5// author: Gerald Dherbomez
6//
7// purpose: generic ComponentBase class. This is an abstract class
8//
9// todo: - see if some methods can be private with ComponentManager
10// friendship
11// - include the copy of Xml node in param here
12// - see if there is a possibility to avoid the constraint
13// on parameters in the constructor of derived class
14// *********************************************************************
15
16#ifndef COMPONENTBASE_H
17#define COMPONENTBASE_H
18
19#include "kernel/ComponentManager.h" // FIXME: remove this line when all components include it
20#include "kernel/pacpus.h"
21#include "XmlComponentConfig.h"
22
23#include <QString>
24
25namespace pacpus {
26
27class ComponentManager;
28
29class PACPUSLIB_API ComponentBase
30{
31 friend class ComponentManager;
32
33public:
34 // Here is the enumeration of the state that can take a component
35 // The 3 last states suppose that the component is started
36 enum COMPONENT_STATE
37 {
38 STOPPED,
39 NOT_MONITORED,
40 MONITOR_OK,
41 MONITOR_NOK
42 };
43
44 // The different identifying the configuration of the component
45 enum COMPONENT_CONFIGURATION
46 {
47 CONFIGURED_OK,
48 NOT_CONFIGURED,
49 CONFIGURATION_DELAYED,
50 CONFIGURED_FAILED
51 };
52
53 // constructor - your derived component must have only one parameter
54 // in its constructor which is name
55 ComponentBase(QString name);
56
57 // destructor
58 virtual ~ComponentBase();
59
60 // return the state of the component
61 COMPONENT_STATE getState();
62
63 // return true if the component is configured, false else
64 inline bool isConfigured()
65 {
66 return (CONFIGURED_OK == configuration_);
67 }
68
69protected:
70 // define the state of the component
71 void setState(COMPONENT_STATE state);
72
73 // pure virtual function - what to do when the component starts?
74 virtual void startActivity() = 0;
75
76 // pure virtual function - what to do when the component stops?
77 virtual void stopActivity() = 0;
78
79 // This function is called by the ComponentManager when it loads the XML file
80 // It gives to the component the XML node corresponding to its
81 // So the component can handle some properties defined in the XML config file
82 // via XmlComponentConfig methods
83 virtual COMPONENT_CONFIGURATION configureComponent(pacpus::XmlComponentConfig config) = 0;
84
85 // The XML node that is got in the configureComponent method
86 pacpus::XmlComponentConfig param;
87
88 // the name of the component. It is this one in the XML config file
89 QString componentName;
90
91 // is the component is recording data?
92 bool recording;
93
94 // provided for compatibility with old DBITE framework
95 bool THREAD_ALIVE;
96
97 // is the component active?
98 bool mIsActive;
99
100 // a pointer to the manager of components
101 ComponentManager * mgr;
102
103private:
104 // called by the ComponentManager to start the component
105 int startComponent();
106
107 // called by the ComponentManager to stop the component
108 int stopComponent();
109
110 // store the state of the component
111 COMPONENT_STATE componentState_;
112
113 // is the component configured (ie configureComponent method was called)
114 COMPONENT_CONFIGURATION configuration_;
115};
116
117} // namespace pacpus
118
119#endif // COMPONENTBASE_H
Note: See TracBrowser for help on using the repository browser.