[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] | 22 | namespace pacpus {
|
---|
| 23 |
|
---|
| 24 | // Forward declarations.
|
---|
| 25 | class ComponentManager;
|
---|
| 26 |
|
---|
| 27 | /** ComponentBase
|
---|
| 28 | * @brief Base class of a Pacpus component.
|
---|
| 29 | */
|
---|
| 30 | class PACPUSLIB_API ComponentBase
|
---|
[30] | 31 | {
|
---|
[3] | 32 | friend class ComponentManager;
|
---|
[42] | 33 | public:
|
---|
| 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] | 73 | protected:
|
---|
| 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;
|
---|
[61] | 92 |
|
---|
| 93 | protected:
|
---|
| 94 | /// The XML node that is got in the configureComponent method
|
---|
[42] | 95 | XmlComponentConfig param;
|
---|
[3] | 96 |
|
---|
[61] | 97 | /// the name of the component. It is this one in the XML config file
|
---|
[42] | 98 | QString componentName;
|
---|
[3] | 99 |
|
---|
[61] | 100 | /// is the component is recording data?
|
---|
[42] | 101 | bool recording;
|
---|
[3] | 102 |
|
---|
[61] | 103 | /// provided for compatibility with old DBITE framework
|
---|
[42] | 104 | bool THREAD_ALIVE;
|
---|
[3] | 105 |
|
---|
[61] | 106 | /// is the component active?
|
---|
[42] | 107 | bool mIsActive;
|
---|
[3] | 108 |
|
---|
[61] | 109 | /// a pointer to the manager of components
|
---|
[42] | 110 | ComponentManager * mgr;
|
---|
[3] | 111 |
|
---|
[42] | 112 | private:
|
---|
[61] | 113 | /// called by the ComponentManager to start the component
|
---|
[42] | 114 | int startComponent();
|
---|
[3] | 115 |
|
---|
[61] | 116 | /// called by the ComponentManager to stop the component
|
---|
[42] | 117 | int stopComponent();
|
---|
[3] | 118 |
|
---|
[61] | 119 | /// store the state of the component
|
---|
[42] | 120 | COMPONENT_STATE componentState_;
|
---|
[3] | 121 |
|
---|
[61] | 122 | /// is the component configured (ie configureComponent method was called)
|
---|
[42] | 123 | COMPONENT_CONFIGURATION configuration_;
|
---|
| 124 | };
|
---|
[3] | 125 |
|
---|
[42] | 126 | } // pacpus
|
---|
| 127 |
|
---|
| 128 | #endif // DEF_PACPUS_COMPONENTBASE_H
|
---|