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