Changeset 42 in pacpusframework for trunk


Ignore:
Timestamp:
01/08/13 21:44:51 (11 years ago)
Author:
sgosseli
Message:
  • Coding style
  • License header
  • Some clean-up
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Pacpus/kernel/ComponentBase.h

    r30 r42  
    11/**
    22 *
    3  * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
    4  * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
    5  *
    6  * See the LICENSE file for more information or a copy at:
    7  *   http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
    8  *
     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 *
    911 */
    1012 
     
    1820#include <QString>
    1921
    20 namespace pacpus
     22namespace pacpus {
     23
     24// Forward declarations.
     25class ComponentManager;
     26
     27/** ComponentBase
     28 * @brief Base class of a Pacpus component.
     29 */
     30class PACPUSLIB_API ComponentBase
    2131{
    22   class ComponentManager;
     32    friend class ComponentManager;
     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    };
    2345
    24   /** ComponentBase
    25    * @brief Base class of a Pacpus component.
    26    */
    27   class PACPUSLIB_API ComponentBase
    28   {
    29     friend class ComponentManager;
    30     public:
    31       /**
    32        * Enumeration of the state that can take a component, the three last states suppose
    33        * that the component is started.
    34        */
    35       enum COMPONENT_STATE
    36       {
    37         STOPPED,
    38         NOT_MONITORED,
    39         MONITOR_OK,
    40         MONITOR_NOK
    41       };
     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    };
    4254
    43       /** Resulting state of a component after its configuration. */
    44       enum COMPONENT_CONFIGURATION
    45       {
    46         CONFIGURED_OK,
    47         NOT_CONFIGURED,
    48         CONFIGURATION_DELAYED,
    49         CONFIGURED_FAILED
    50       };
     55    /** Ctor of ComponentBase.
     56     * @param name Name of your component.
     57     */
     58    ComponentBase(const QString& name);
    5159
    52       /** Ctor of ComponentBase.
    53        * @param name Name of your component.
    54        */
    55       ComponentBase(const QString& name);
     60    /** Dtor of ComponentBase. */
     61    virtual ~ComponentBase();
    5662
    57       /** Dtor of ComponentBase. */
    58       virtual ~ComponentBase();
     63    /** Return the state of the component.
     64     * @return Value of the current state.
     65     */
     66    COMPONENT_STATE getState();
    5967
    60       /** Return the state of the component.
    61        * @return Value of the current state.
    62        */
    63       COMPONENT_STATE getState();
     68    /** Check whether the component if configurer or not.
     69     * @return True if the component is configured, otherwise false.
     70     */
     71    bool isConfigured() const;
    6472
    65       /** Check whether the component if configurer or not.
    66        * @return True if the component is configured, otherwise false.
    67        */
    68       bool isConfigured() const;
     73protected:
     74    /** Change the state of the component.
     75     * @param state New component state.
     76     */
     77    void setState(COMPONENT_STATE state);
    6978
    70     protected:
    71       /** Change the state of the component.
    72        * @param state New component state.
    73        */
    74       void setState(COMPONENT_STATE state);
     79    /** Called when the component starts, you must override this function. */
     80    virtual void startActivity() = 0;
    7581
    76       /** Called when the component starts, you must override this function. */
    77       virtual void startActivity() = 0;
     82    /** Called when the component stops, you must override this function. */
     83    virtual void stopActivity() = 0;
    7884
    79       /** Called when the component stops, you must override this function. */
    80       virtual void stopActivity() = 0;
     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;
    8192
    82       /** Called by the ComponentManager, it configure the component thanks a XML node.
    83        * @param config Component's XML node.
    84        * @return State of the configuration.
    85        * FIXME: 'config' should be const, but we can't change the prototype without breaking
    86        * old stuff.
    87        */
    88       virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config) = 0;
     93    // The XML node that is got in the configureComponent method
     94    XmlComponentConfig param;
    8995
    90       // The XML node that is got in the configureComponent method
    91       XmlComponentConfig param;
     96    // the name of the component. It is this one in the XML config file
     97    QString componentName;
    9298
    93       // the name of the component. It is this one in the XML config file
    94       QString componentName;
     99    // is the component is recording data?
     100    bool recording;
    95101
    96       // is the component is recording data?
    97       bool recording;
     102    // provided for compatibility with old DBITE framework
     103    bool THREAD_ALIVE;
    98104
    99       // provided for compatibility with old DBITE framework
    100       bool THREAD_ALIVE;
     105    // is the component active?
     106    bool mIsActive;
    101107
    102       // is the component active?
    103       bool mIsActive;
     108    // a pointer to the manager of components
     109    ComponentManager * mgr;
    104110
    105       // a pointer to the manager of components
    106       ComponentManager * mgr;
     111private:
     112    // called by the ComponentManager to start the component
     113    int startComponent();
    107114
    108     private:
    109       // called by the ComponentManager to start the component
    110       int startComponent();
     115    // called by the ComponentManager to stop the component
     116    int stopComponent();
    111117
    112       // called by the ComponentManager to stop the component
    113       int stopComponent();
     118    // store the state of the component
     119    COMPONENT_STATE componentState_;
    114120
    115       // store the state of the component
    116       COMPONENT_STATE componentState_;
     121    // is the component configured (ie configureComponent method was called)
     122    COMPONENT_CONFIGURATION configuration_;
     123};
    117124
    118       // is the component configured (ie configureComponent method was called)
    119       COMPONENT_CONFIGURATION configuration_;
    120   };
    121 }
     125} // pacpus
    122126
    123 #endif
     127#endif // DEF_PACPUS_COMPONENTBASE_H
  • trunk/src/PacpusLib/ComponentBase.cpp

    r31 r42  
    11/**
    22 *
    3  * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
    4  * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
    5  *
    6  * See the LICENSE file for more information or a copy at:
    7  *   http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
    8  *
     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 *
    911 */
    1012
     
    1820
    1921ComponentBase::ComponentBase(const QString& name)
     22  : componentName(name)
     23  , recording(true)
     24  , THREAD_ALIVE(true)
     25  , mIsActive(false)
     26  , mgr(NULL)
     27  , componentState_(NOT_MONITORED)
    2028{
    2129    LOG_TRACE("constructor");
    22 
    23     configuration_ = NOT_CONFIGURED;
    24     componentName = name;
    25     recording = true;
    26     THREAD_ALIVE = true;
    27     mIsActive = 0;
    28     componentState_ = ComponentBase::NOT_MONITORED;
    29 
    30     // we get a pointer on the instance of ComponentManager
     30    // Get a pointer on the instance of ComponentManager.
    3131    mgr = ComponentManager::getInstance();
    32 
    33     LOG_INFO("component " << componentName
    34              << " was created"
    35              );
     32    LOG_INFO("component " << componentName << " was created");
    3633}
    3734
     
    4340int ComponentBase::startComponent()
    4441{
    45     if (mIsActive == 0) {
    46         mIsActive = 1;
    47         startActivity();
    48         return 1;
    49     } else {
    50         return 0;
    51     }
     42    if (mIsActive)
     43      return false;
     44     
     45    mIsActive = true;
     46    startActivity();
     47   
     48    return true;
    5249}
    5350
    5451int ComponentBase::stopComponent()
    5552{
    56     if (mIsActive == 1) {
    57         mIsActive = 0;
    58         stopActivity();
    59         return 1;
    60     } else {
    61         return 0;
    62     }
     53    if (!mIsActive)
     54      return false;
     55
     56    mIsActive = false;
     57    stopActivity();
     58   
     59    return true;
    6360}
    6461
    6562void ComponentBase::setState(const COMPONENT_STATE state)
    6663{
    67     if (state != componentState_) {
    68         componentState_ = state;
    69     }
     64    componentState_ = state;
    7065}
    7166
     
    8277bool ComponentBase::isConfigured() const
    8378{
    84     return CONFIGURED_OK == configuration_;
     79    return configuration_ == CONFIGURED_OK;
    8580}
Note: See TracChangeset for help on using the changeset viewer.