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

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

Modified property: added svn:keywords=Id.

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