Ignore:
Timestamp:
08/01/13 10:45:50 (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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.