Ignore:
Timestamp:
05/23/13 12:16:31 (11 years ago)
Author:
morasjul
Message:

2.0 minor fixs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h

    r95 r96  
    44#include <Pacpus/kernel/pacpus.h>
    55#include <Pacpus/kernel/ConnectionBase.h>
     6#include <Pacpus/kernel/PacpusEvent.h>
    67
     8#include <QApplication>
    79#include <typeinfo>
    8 #include <QEvent>
    910#include <QList>
    1011#include <QStringList>
     
    2425    QString getName() {return _name;}
    2526    virtual QString getDataType() = 0;
    26     //ComponentBase * getComponent() {return _component;}
     27    ComponentBase * getComponent() {return _component;}
     28
     29    void addConnection(ConnectionBase connection) { _connection.append(connection);}
     30    bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);}
    2731
    2832protected:
    2933    QString _name;
    3034    ComponentBase * _component;
     35    QList<ConnectionBase> _connection;
    3136};
    3237
     
    3439{
    3540    Q_OBJECT
     41protected:
     42    InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
     43
    3644public:
    37     InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
     45    //InputInterfaceBase(QString name, ComponentBase * component,int a, QObject * parent = 0):AbstractInterface(name,component,parent) {} // TODO add ctor with function pointer
     46
    3847    virtual ~InputInterfaceBase(){}
    3948
    40     virtual void customEvent(QEvent* e) = 0;
     49    virtual void customEvent(QEvent* e) {
     50
     51        //if(event->type())
     52            //TODO get event Type anf call callback function
     53
     54    QByteArray buf;
     55    QDataStream out(&buf,QIODevice::WriteOnly);
     56    out << e;
     57    // Callback QByteArray
     58    }
     59
     60    virtual PacpusEvent getEventTemplate() {return PacpusEvent(GENERIC_EVENT);} // TODO check ??
    4161
    4262};
     
    4565{
    4666    Q_OBJECT
     67
    4768public:
    4869    OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
     70
    4971    virtual ~OutputInterfaceBase(){}
    50 
    51     void addConnection(ConnectionBase connection) { _connection.append(connection);}
    52     bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);}
    5372
    5473    QStringList getInputConnectedList() {
    5574        QStringList list;
    5675        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
    57             list.append(it->getInputInterface()->getName());
     76            list.append(it->getInterface()->getName());
    5877        return list;
    5978    }
    6079
    61 protected:
    62     QList<ConnectionBase> _connection;
     80    void send(/*const*/ QByteArray & data) {
     81
     82        // TODo getEvent
     83        //PacpusEvent& event = _connection.at(0).getInterface()->
     84        QDataStream in(&data,QIODevice::ReadOnly);
     85        //in >> event;
     86
     87        //for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
     88        //        QApplication::postEvent(it->getInterface(),&event,it->getPriority());
     89
     90
     91    }
    6392
    6493};
     94
     95static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority)
     96{
     97    if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
     98
     99        // Add connection
     100        out->addConnection(ConnectionBase(in,priority));  // TODO make connect function
     101        in->addConnection(ConnectionBase(out,priority));
     102        //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
     103        return true;
     104    } else {
     105   //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " <<  QString(typeid(QByteArray).name()));
     106   return false;
     107    }
     108}
    65109
    66110} // namespace pacpus
Note: See TracChangeset for help on using the changeset viewer.