Changeset 152 in pacpusframework for branches/2.0-beta1/include/Pacpus


Ignore:
Timestamp:
Aug 1, 2013, 10:45:50 AM (11 years ago)
Author:
Marek Kurdej
Message:

Major update.
Renamed: addInput -> addInputs, addOutput -> addOutputs and made pure virtual (=0).
Transformed macro definitions into template methods: ADD_INPUT -> ComponentBase::addInput, ADD_OUTPUT -> ComponentBase::addOutput, GET_INPUT -> ComponentBase::getTypedInput, GET_OUTPUT -> ComponentBase::getTypedOutput.
Fixed: added public/protected set/get methods in ComponentBase, made member fields private.

Location:
branches/2.0-beta1/include/Pacpus
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyEngine.h

    r89 r152  
    9191
    9292protected:
     93    virtual void addInputs();
     94    virtual void addOutputs();
     95
    9396    /// @todo Documentation
    9497    virtual void startActivity();
  • branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyTrigger.h

    r89 r152  
    5555
    5656protected:
     57    virtual void addInputs();
     58    virtual void addOutputs();
     59
    5760    /// @todo Documentation
    5861    virtual void startActivity();
  • branches/2.0-beta1/include/Pacpus/DbitePlayer/DbtPlyUserInterface.h

    r89 r152  
    7373    /// Displays the current time of the player.
    7474    void displayTime(road_time_t time);
     75   
     76protected:
     77    virtual void addInputs();
     78    virtual void addOutputs();
    7579
    7680private:
  • branches/2.0-beta1/include/Pacpus/PacpusTools/PacpusSerialPort.h

    r122 r152  
    2020namespace pacpus {
    2121
    22 class PacpusSerialPort : public QObject, public ComponentBase
     22class PacpusSerialPort
     23    : public QObject
     24    , public ComponentBase
    2325{
    2426    Q_OBJECT
    2527   
    2628public:
    27 
    28     typedef enum { ASCII, BINARY } DataMode;
     29    typedef enum {
     30        ASCII,
     31        BINARY
     32    } DataMode;
    2933
    3034    PacpusSerialPort(QString name);
     
    3640    ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
    3741
    38     void addInput();
    39     void addOutput();
     42    virtual void addInputs();
     43    virtual void addOutputs();
    4044    void processInputFrame(const QByteArray &);
    4145
    42 private Q_SLOTS :
     46private Q_SLOTS:
    4347    void readData();
    4448
    4549private:
    46 
    4750    QThread       thread_;
    4851
     
    6871
    6972    bool log;
    70 
    71 
    7273};
    7374
  • branches/2.0-beta1/include/Pacpus/kernel/ComponentBase.h

    r138 r152  
    3838class ComponentManager;
    3939
     40template <typename T, class C>
     41class InputInterface;
     42
     43template <typename T, class C>
     44class OutputInterface;
     45
    4046/** ComponentBase
    4147 * @brief Base class of a Pacpus component.
     
    4450{
    4551    friend class ComponentManager;
     52
    4653public:
    4754    /**
     
    8794     * @return Name of the component.
    8895     */
     96    QString name() const;
    8997    QString getName() const;
    9098
    91     InputInterfaceBase * getInput(QString) const;
    92 
    93     OutputInterfaceBase * getOutput(QString) const;
     99    InputInterfaceBase * getInput(QString name) const;
     100
     101    OutputInterfaceBase * getOutput(QString name) const;
    94102
    95103protected:
     
    115123    // virtual QString getType() = 0;
    116124
    117     virtual void addInput();
    118 
    119     virtual void addOutput();
     125    virtual void addInputs() = 0;
     126    virtual void addOutputs() = 0;
     127
     128protected:
     129    typedef QMap<QString, InputInterfaceBase *> InputsMap;
     130    typedef QMap<QString, OutputInterfaceBase *> OutputsMap;
     131
     132    // TODO: use std::function<void (const DataType &)>
     133    // TODO: use std::mem_fun<void (const DataType &)>
     134    template <typename DataType, class ComponentType, typename Function>
     135    void addInput(const char * name, Function function)
     136    {
     137        typedef InputInterface<DataType, ComponentType> InputType;
     138        InputType * connection = new InputType(name, dynamic_cast<ComponentType *>(this), function);
     139        inputs().insert(name, connection);
     140    }
     141
     142    template <typename DataType, class ComponentType>
     143    void addOutput(const char * name)
     144    {
     145        typedef OutputInterface<DataType, ComponentType> OutputType;
     146        OutputType * connection = new OutputType(name, dynamic_cast<ComponentType *>(this));
     147        outputs().insert(name, connection);
     148    }
     149
     150    template <typename DataType, class ComponentType>
     151    InputInterface<DataType, ComponentType> *
     152        getTypedInput(const char * name) const
     153    {
     154        return dynamic_cast<InputInterface<DataType, ComponentType> *>(getInput(name));
     155    }
     156
     157    template <typename DataType, class ComponentType>
     158    OutputInterface<DataType, ComponentType> *
     159        getTypedOutput(const char * name) const
     160    {
     161        return dynamic_cast<OutputInterface<DataType, ComponentType> *>(getOutput(name));
     162    }
     163
     164    bool isActive() const;
     165    void setActive(bool isActive);
     166    bool isRecording() const;
     167    void setRecording(bool isRecording);
     168
     169    InputsMap & inputs();
     170    const InputsMap & inputs() const;
     171    OutputsMap & outputs();
     172    const OutputsMap & outputs() const;
     173
     174    COMPONENT_CONFIGURATION configurationState() const;
     175    void setConfigurationState(COMPONENT_CONFIGURATION state);
     176
     177    const XmlComponentConfig xmlParameters() const;
    120178   
    121 protected:
    122     /// The XML node that is got in the configureComponent method
    123     XmlComponentConfig param;
    124 
    125     /// the name of the component. It is this one in the XML config file
    126     QString componentName;
    127 
    128     /// is the component is recording data?
    129     bool recording;
    130 
    131     /// provided for compatibility with old DBITE framework
    132     bool THREAD_ALIVE;
    133 
    134     /// is the component active?
    135     bool mIsActive;
    136 
    137     /// a pointer to the manager of components
    138     ComponentManager * mgr;
    139 
    140     QMap<QString, InputInterfaceBase *> input;
    141     QMap<QString, OutputInterfaceBase *> output;
    142 
    143     /// a pointer to an optional widget
    144     QWidget *   ui;
    145 
    146179private:
    147180    /// called by the ComponentManager to start the component
     
    151184    int stopComponent();
    152185
     186private:
     187    /// The XML node that is got in the configureComponent method
     188    XmlComponentConfig param;
     189
     190    /// the name of the component. It is this one in the XML config file
     191    QString m_componentName;
     192   
     193    /// is the component active?
     194    volatile bool m_isActive;
     195
     196    /// is the component is recording data?
     197    bool m_isRecording;
     198
     199    /// a pointer to the manager of components
     200    ComponentManager * m_manager;
     201
     202    InputsMap m_inputs;
     203    OutputsMap m_outputs;
     204
     205    /// a pointer to an optional widget
     206    QWidget * m_ui;
     207
    153208    /// store the state of the component
    154     COMPONENT_STATE componentState_;
     209    COMPONENT_STATE m_componentState;
    155210
    156211    /// is the component configured (ie configureComponent method was called)
    157     COMPONENT_CONFIGURATION configuration_;
     212    COMPONENT_CONFIGURATION m_configurationState;
    158213};
    159214
    160 
    161215} // pacpus
    162216
  • branches/2.0-beta1/include/Pacpus/kernel/InputOutputBase.h

    r148 r152  
    9696{
    9797    Q_OBJECT
     98
    9899protected:
    99100    InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0)
  • branches/2.0-beta1/include/Pacpus/kernel/InputOutputInterface.h

    r148 r152  
    1212#include <QByteArray>
    1313
    14 #define ADD_INPUT(name,ComponentType, DataType, functionName)  input.insert(name,new InputInterface<DataType,ComponentType> (name,this,&ComponentType::functionName))
    15 #define ADD_OUTPUT(name,ComponentType, DataType)      output.insert(name,new OutputInterface<DataType,ComponentType> (name,this))
    16 
    17 #define GET_OUTPUT(name,ComponentType, DataType) dynamic_cast<OutputInterface<DataType,ComponentType> *> (output.value(name))
    18 #define GET_INPUT(name,ComponentType, DataType) dynamic_cast<InputInterface<DataType,ComponentType> *> (input.value(name))
     14//#define ADD_INPUT(name, ComponentType, DataType, functionName) \
     15//    inputs().insert((name), new InputInterface<DataType, ComponentType> ((name), this, &ComponentType::functionName))
     16//#define ADD_OUTPUT(name, ComponentType, DataType) \
     17//    outputs().insert((name), new OutputInterface<DataType, ComponentType> ((name), this))
     18
     19//#define GET_INPUT(name, ComponentType, DataType) \
     20//    dynamic_cast<InputInterface<DataType, ComponentType> *> (input.value(name))
     21//#define GET_OUTPUT(name, ComponentType, DataType) \
     22//    dynamic_cast<OutputInterface<DataType, ComponentType> *> (output.value(name))
    1923
    2024namespace pacpus {
    2125
    22 template <class T, class C>
     26template <typename T, class C>
    2327class InputInterface
    2428    : public InputInterfaceBase
     
    2630public:
    2731    InputInterface(QString name, C * component, void (C::*m)(const T&))
    28         : InputInterfaceBase(name,component,component)
     32        : InputInterfaceBase(name, component, component)
    2933        , method(m)
    3034    {}
     
    140144};
    141145
    142 template <class T, class C>
     146template <typename T, class C>
    143147class OutputInterface : public OutputInterfaceBase
    144148{
Note: See TracChangeset for help on using the changeset viewer.