Changeset 96 in pacpusframework for branches/2.0-beta1/include/Pacpus/kernel


Ignore:
Timestamp:
May 23, 2013, 12:16:31 PM (11 years ago)
Author:
morasjul
Message:

2.0 minor fixs

Location:
branches/2.0-beta1/include/Pacpus/kernel
Files:
4 edited

Legend:

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

    r89 r96  
    55namespace pacpus {
    66
    7 class InputInterfaceBase;
     7class AbstractInterface;
    88
    99class ConnectionBase
    1010{
    1111public:
    12     ConnectionBase(InputInterfaceBase * input, int priority):_input(input),_priority(priority) {}
     12    ConnectionBase(AbstractInterface * interface, int priority):_interface(interface),_priority(priority) {}
    1313    ~ConnectionBase() {}
    1414
    15     InputInterfaceBase *  getInputInterface() const {return _input;}
     15    AbstractInterface *  getInterface() const {return _interface;}
    1616    int getPriority() const {return _priority;}
    1717
    1818    bool operator== (ConnectionBase const &c) {
    19         return _input == c.getInputInterface() && _priority == c.getPriority();}
     19        return _interface == c.getInterface() && _priority == c.getPriority();}
    2020
    2121private:
    22     InputInterfaceBase * _input;
     22    AbstractInterface * _interface;
    2323    int _priority;
    2424};
  • branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h

    r94 r96  
    55#include "Pacpus/kernel/road_time.h"
    66#include <Pacpus/kernel/pacpus.h>
     7#include <QDataStream>
    78
    89namespace pacpus {
     
    3637{
    3738public:
    38     PacpusEvent(QEvent::Type type):QEvent(type) {}
     39    PacpusEvent(PacpusEventType type, road_time_t t = road_time(), road_timerange_t tr = 0):QEvent(QEvent::Type(type)),t_(t),tr_(tr) {}
     40    virtual ~PacpusEvent() {}
     41
     42    virtual QDataStream& streamOut(QDataStream& out) {}; // NOTE virtual pure ??
     43    virtual QDataStream& streamIn(QDataStream& in) {};
     44
     45public: // TODO make protected
     46    road_time_t t_;
     47    road_timerange_t tr_;
    3948};
    4049
     
    4352{
    4453public:
    45     PacpusTypedEvent(QEvent::Type type, T data, road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type)
    46     {_data = data; t_ = t; tr_ = tr;}
     54    PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),_data(data) {}
    4755    ~PacpusTypedEvent() {}
     56
     57    QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<_data*/;} // FIXME Stream Data errors
     58    QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> _data*/;}
     59
     60public: // TODO make protected
    4861    T _data;
    49     road_time_t t_;
    50     road_timerange_t tr_;
    5162};
     63
     64inline QDataStream& operator << (QDataStream& out, PacpusEvent& ev) {return ev.streamOut(out);}
     65inline QDataStream& operator >> (QDataStream& in, PacpusEvent& ev) {return ev.streamIn(in);}
    5266
    5367class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
    5468{
    5569public:
    56     PacpusGenericEvent(QEvent::Type type, char* data, size_t size):PacpusEvent(type) {
     70    PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) {
    5771        _data = (char*)malloc(size);
    5872        memcpy(_data,data,size);
  • 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
  • branches/2.0-beta1/include/Pacpus/kernel/inputOutputInterface.h

    r95 r96  
    44#include <Pacpus/kernel/Log.h>
    55#include <Pacpus/kernel/inputOutputBase.h>
    6 #include <Pacpus/kernel/PacpusEvent.h>
    76
    87#include <typeinfo>
     
    4140    public:
    4241
     42    PacpusEvent getEventTemplate() {return PacpusTypedEvent<T>(TYPED_EVENT); }
     43
    4344    void customEvent(QEvent* event) {
    4445
     
    7273
    7374                // from Connection interface to Component (G->T)
    74             case GENERIC_EVENT2: {
     75/*            case GENERIC_EVENT2: {
    7576                PacpusTypedEvent<QByteArray> * genericEvent = dynamic_cast<PacpusTypedEvent<QByteArray> *> (event);
    76                 qDebug() << "E2 ";
    77                 //if(sizeof(T) != genericEvent->_data.size())
    78                 //    qDebug() << "Incorrecte size " << sizeof(T) << " " << genericEvent->_data.size();
    79               qDebug() << "t[18]= " << road_time();
    8077                T data;
    8178                QByteArray& buf = (QByteArray&) genericEvent->_data;
    82                 //qDebug() << "DataSize " <<buf.size();
    8379                QDataStream in(&buf,QIODevice::ReadOnly);
    8480
    85                 qDebug() << "t[19]= " << road_time();
    86                 //in >> data; // copy 7
    87                 qDebug() << "t[20]= " << road_time();
    88 
    8981                (dynamic_cast<C*>(_component)->*method)(data); // copy 8 X
    90 
    91                 qDebug() << "t[21]= " << road_time();
    9282                break;
    9383            }
     
    9686            case GENERIC_EVENT3: {
    9787                PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event);
    98                 qDebug() << "E3 ";
    99               qDebug() << "t[6]= " << road_time();
    10088                (dynamic_cast<C*>(_component)->*method)(typedEvent->_data);     // copy 3 X
    101               qDebug() << "t[7]= " << road_time();
     89
    10290                break;
    103             }
     91            }*/
    10492
    10593            default:
    10694
    107             qDebug() << "Bad event ID " << event->type();
     95            qDebug() << "Unknown event ID " << event->type();
    10896                break;
    10997        }
     
    128116        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){
    129117
    130             if(it->getInputInterface()->getDataType() != QString(typeid(QByteArray).name()))
    131                 QApplication::postEvent(it->getInputInterface(),new PacpusTypedEvent<T>(QEvent::Type(TYPED_EVENT),data),it->getPriority());
    132            else {
    133               qDebug() << "t[1]= " << road_time();
    134                 //QByteArray buf((char*)(&data),sizeof(T));
     118            //if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name()))
     119                QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data),it->getPriority());
     120           /*else {
    135121                QByteArray buf;
    136122                QDataStream out(&buf,QIODevice::ReadWrite);
    137               qDebug() << "t[2]= " << road_time();
    138                // out << data;    // Copy 1
    139               qDebug() << "t[3]= " << road_time();
    140 
    141                 PacpusTypedEvent<QByteArray> * ev =new PacpusTypedEvent<QByteArray>(QEvent::Type(GENERIC_EVENT3),buf);
    142               qDebug() << "t[4]= " << road_time();
    143                 QApplication::postEvent(it->getInputInterface(),ev,it->getPriority()); // Copy 2 (ctor)
    144               qDebug() << "t[5]= " << road_time();
    145                 //QApplication::postEvent(it->getInputInterface(),new PacpusTypedEvent<QByteArray>(QEvent::Type(GENERIC_EVENT3),buf),it->getPriority()); // Copy 2 (ctor)
    146                 }
    147 
    148         //qDebug() << "send thread " << QThread::currentThread();
     123                PacpusTypedEvent<QByteArray> * ev =new PacpusTypedEvent<QByteArray>(GENERIC_EVENT3,buf);
     124                QApplication::postEvent(it->getInterface(),ev,it->getPriority()); // Copy 2 (ctor)
     125                }*/
    149126        }
    150127    }
    151128
    152129    // Used by Connection Interfaces only to pose generic event
    153     void sendGenericData(char * data, size_t size) {
    154               qDebug() << "t[15]= " << road_time();
     130/*    void sendGenericData(char * data, size_t size) {
    155131        QByteArray buf(data,size);  // copy 5
    156               qDebug() << "t[16]= " << road_time();
    157132        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
    158             QApplication::postEvent(it->getInputInterface(),new PacpusTypedEvent<QByteArray>(QEvent::Type(GENERIC_EVENT2),buf),it->getPriority()); // Copy 6(ctor)
    159               qDebug() << "t[17]= " << road_time();
    160         //qDebug() << "send thread " << QThread::currentThread();
     133            QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<QByteArray>(GENERIC_EVENT2,buf),it->getPriority()); // Copy 6(ctor)
     134
     135
    161136    }
    162 
     137*/
    163138    size_t getDataSize() {return sizeof(T);}
    164139    QString getDataType() {return QString(typeid(T).name());}
Note: See TracChangeset for help on using the changeset viewer.