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

Last change on this file since 52 was 42, checked in by sgosseli, 12 years ago
  • Coding style
  • License header
  • Some clean-up
File size: 3.4 KB
RevLine 
[30]1/**
2 *
[42]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 *
[30]11 */
12
13#ifndef DEF_PACPUS_COMPONENTBASE_H
14#define DEF_PACPUS_COMPONENTBASE_H
[3]15
[30]16#include <Pacpus/kernel/ComponentManager.h>
17#include <Pacpus/kernel/pacpus.h>
18#include <Pacpus/kernel/XmlComponentConfig.h>
[3]19
20#include <QString>
21
[42]22namespace pacpus {
23
24// Forward declarations.
25class ComponentManager;
26
27/** ComponentBase
28 * @brief Base class of a Pacpus component.
29 */
30class PACPUSLIB_API ComponentBase
[30]31{
[3]32 friend class ComponentManager;
[42]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 };
[3]45
[42]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 };
[3]54
[42]55 /** Ctor of ComponentBase.
56 * @param name Name of your component.
57 */
58 ComponentBase(const QString& name);
[3]59
[42]60 /** Dtor of ComponentBase. */
61 virtual ~ComponentBase();
[3]62
[42]63 /** Return the state of the component.
64 * @return Value of the current state.
65 */
66 COMPONENT_STATE getState();
[3]67
[42]68 /** Check whether the component if configurer or not.
69 * @return True if the component is configured, otherwise false.
70 */
71 bool isConfigured() const;
[3]72
[42]73protected:
74 /** Change the state of the component.
75 * @param state New component state.
76 */
77 void setState(COMPONENT_STATE state);
[3]78
[42]79 /** Called when the component starts, you must override this function. */
80 virtual void startActivity() = 0;
[3]81
[42]82 /** Called when the component stops, you must override this function. */
83 virtual void stopActivity() = 0;
[3]84
[42]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;
[3]92
[42]93 // The XML node that is got in the configureComponent method
94 XmlComponentConfig param;
[3]95
[42]96 // the name of the component. It is this one in the XML config file
97 QString componentName;
[3]98
[42]99 // is the component is recording data?
100 bool recording;
[3]101
[42]102 // provided for compatibility with old DBITE framework
103 bool THREAD_ALIVE;
[3]104
[42]105 // is the component active?
106 bool mIsActive;
[3]107
[42]108 // a pointer to the manager of components
109 ComponentManager * mgr;
[3]110
[42]111private:
112 // called by the ComponentManager to start the component
113 int startComponent();
[3]114
[42]115 // called by the ComponentManager to stop the component
116 int stopComponent();
[3]117
[42]118 // store the state of the component
119 COMPONENT_STATE componentState_;
[3]120
[42]121 // is the component configured (ie configureComponent method was called)
122 COMPONENT_CONFIGURATION configuration_;
123};
[3]124
[42]125} // pacpus
126
127#endif // DEF_PACPUS_COMPONENTBASE_H
Note: See TracBrowser for help on using the repository browser.