| 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 |
|
|---|
| 14 | #ifndef DEF_PACPUS_COMPONENTBASE_H
|
|---|
| 15 | #define DEF_PACPUS_COMPONENTBASE_H
|
|---|
| 16 |
|
|---|
| 17 | #include <Pacpus/kernel/ComponentManager.h>
|
|---|
| 18 | #include <Pacpus/kernel/pacpus.h>
|
|---|
| 19 | #include <Pacpus/kernel/XmlComponentConfig.h>
|
|---|
| 20 |
|
|---|
| 21 | #include <QString>
|
|---|
| 22 |
|
|---|
| 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
|
|---|
| 32 | {
|
|---|
| 33 | friend class ComponentManager;
|
|---|
| 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 | };
|
|---|
| 46 |
|
|---|
| 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 | };
|
|---|
| 55 |
|
|---|
| 56 | /** Ctor of ComponentBase.
|
|---|
| 57 | * @param name Name of your component.
|
|---|
| 58 | */
|
|---|
| 59 | ComponentBase(const QString& name);
|
|---|
| 60 |
|
|---|
| 61 | /** Dtor of ComponentBase. */
|
|---|
| 62 | virtual ~ComponentBase();
|
|---|
| 63 |
|
|---|
| 64 | /** Return the state of the component.
|
|---|
| 65 | * @return Value of the current state.
|
|---|
| 66 | */
|
|---|
| 67 | COMPONENT_STATE getState();
|
|---|
| 68 |
|
|---|
| 69 | /** Check whether the component if configurer or not.
|
|---|
| 70 | * @return True if the component is configured, otherwise false.
|
|---|
| 71 | */
|
|---|
| 72 | bool isConfigured() const;
|
|---|
| 73 |
|
|---|
| 74 | protected:
|
|---|
| 75 | /** Change the state of the component.
|
|---|
| 76 | * @param state New component state.
|
|---|
| 77 | */
|
|---|
| 78 | void setState(COMPONENT_STATE state);
|
|---|
| 79 |
|
|---|
| 80 | /** Called when the component starts, you must override this function. */
|
|---|
| 81 | virtual void startActivity() = 0;
|
|---|
| 82 |
|
|---|
| 83 | /** Called when the component stops, you must override this function. */
|
|---|
| 84 | virtual void stopActivity() = 0;
|
|---|
| 85 |
|
|---|
| 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;
|
|---|
| 93 |
|
|---|
| 94 | protected:
|
|---|
| 95 | /// The XML node that is got in the configureComponent method
|
|---|
| 96 | XmlComponentConfig param;
|
|---|
| 97 |
|
|---|
| 98 | /// the name of the component. It is this one in the XML config file
|
|---|
| 99 | QString componentName;
|
|---|
| 100 |
|
|---|
| 101 | /// is the component is recording data?
|
|---|
| 102 | bool recording;
|
|---|
| 103 |
|
|---|
| 104 | /// provided for compatibility with old DBITE framework
|
|---|
| 105 | bool THREAD_ALIVE;
|
|---|
| 106 |
|
|---|
| 107 | /// is the component active?
|
|---|
| 108 | bool mIsActive;
|
|---|
| 109 |
|
|---|
| 110 | /// a pointer to the manager of components
|
|---|
| 111 | ComponentManager * mgr;
|
|---|
| 112 |
|
|---|
| 113 | private:
|
|---|
| 114 | /// called by the ComponentManager to start the component
|
|---|
| 115 | int startComponent();
|
|---|
| 116 |
|
|---|
| 117 | /// called by the ComponentManager to stop the component
|
|---|
| 118 | int stopComponent();
|
|---|
| 119 |
|
|---|
| 120 | /// store the state of the component
|
|---|
| 121 | COMPONENT_STATE componentState_;
|
|---|
| 122 |
|
|---|
| 123 | /// is the component configured (ie configureComponent method was called)
|
|---|
| 124 | COMPONENT_CONFIGURATION configuration_;
|
|---|
| 125 | };
|
|---|
| 126 |
|
|---|
| 127 | } // pacpus
|
|---|
| 128 |
|
|---|
| 129 | #endif // DEF_PACPUS_COMPONENTBASE_H
|
|---|