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


Ignore:
Timestamp:
Jun 13, 2013, 1:43:39 PM (11 years ago)
Author:
morasjul
Message:

Beta-2 : Fix CMakeList (link), remove useless code and add improvement

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

Legend:

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

    r89 r110  
    2929#include <QString>
    3030#include <QMap>
     31
     32class QWidget;
    3133
    3234namespace pacpus {
     
    134136    QMap<QString, OutputInterfaceBase *> output;
    135137
     138    QWidget *   ui;
     139
    136140private:
    137141    /// called by the ComponentManager to start the component
  • branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h

    r98 r110  
    99namespace pacpus {
    1010
     11// registerEventType // TODO
     12
    1113class GenericData {
    1214public:
    1315    GenericData(char* data, size_t size) {
    14         _data = (char*)malloc(size);
    15         memcpy(_data,data,size);
     16        data_ = (char*)malloc(size);
     17        memcpy(data_,data,size);
    1618        _size = size;}
    1719
    18     ~GenericData() {free(_data);}
     20    ~GenericData() {free(data_);}
    1921
    20     char * data() { return _data;}
     22    char * data() { return data_;}
    2123    size_t size() {return _size;}
    2224
    2325private:
    24 char* _data;
     26char* data_;
    2527size_t _size;
    2628};
     
    5254{
    5355public:
    54     PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),_data(data) {}
     56    PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),data_(data) {}
    5557    ~PacpusTypedEvent() {}
    5658
    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    QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<data_*/;} // FIXME Stream Data errors
     60    QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> data_*/;}
    5961
    6062public: // TODO make protected
    61     T _data;
     63    T data_;
    6264};
    63 
    64 inline QDataStream& operator << (QDataStream& out, PacpusEvent& ev) {return ev.streamOut(out);}
    65 inline QDataStream& operator >> (QDataStream& in, PacpusEvent& ev) {return ev.streamIn(in);}
    6665
    6766class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
     
    6968public:
    7069    PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) {
    71         _data = (char*)malloc(size);
    72         memcpy(_data,data,size);
     70        data_ = (char*)malloc(size);
     71        memcpy(data_,data,size);
    7372        _size = size;
    7473
    7574    }
    76     virtual ~PacpusGenericEvent() {free(_data);}
    77     char* _data;
     75    virtual ~PacpusGenericEvent() {free(data_);}
     76    char* data_;
    7877    size_t _size;
    7978};
     
    8281} // namespace pacpus
    8382
     83inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;}
     84inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;}
     85
    8486#endif // PACPUS_EVENT_H
  • branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h

    r102 r110  
    6060            //TODO get event Type anf call callback function
    6161
     62            PacpusEvent * event = dynamic_cast<PacpusEvent *>(e);
    6263    QByteArray buf;
    6364    QDataStream out(&buf,QIODevice::WriteOnly);
    64     out << e;
     65    event->streamOut(out);
    6566    // Callback QByteArray
    6667    }
    6768
    6869    void setReadingMode(ReadingMode mode) { readingMode_ = mode;}
    69     virtual PacpusEvent getEventTemplate() {return PacpusEvent(GENERIC_EVENT);} // TODO check ??
     70    virtual PacpusEvent* getEventTemplate() {return new PacpusEvent(GENERIC_EVENT);} // TODO check ??
    7071protected:
    7172            ReadingMode readingMode_;
     73private:
     74        // metode(QByteArray)
     75
     76        //QQueue jobQueue_;
    7277};
    7378
     
    8994
    9095    void send(/*const*/ QByteArray & data) {
     96        // TODO check at least one Typed connection
    9197
    92         // TODo getEvent
    93         //PacpusEvent& event = _connection.at(0).getInterface()->
    94         QDataStream in(&data,QIODevice::ReadOnly);
    95         //in >> event;
    96 
    97         //for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
    98         //        QApplication::postEvent(it->getInterface(),&event,it->getPriority());
     98        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){
     99                QDataStream in(&data,QIODevice::ReadOnly);
     100                PacpusEvent* event = dynamic_cast<InputInterfaceBase*>(_connection.at(0).getInterface())->getEventTemplate();
     101                event->streamIn(in);
     102                QApplication::postEvent(it->getInterface(),event,it->getPriority());
     103        }
    99104
    100105
     
    103108};
    104109
    105 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority)
     110static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast)
    106111{
    107112    if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
     
    110115        out->addConnection(ConnectionBase(in,priority));  // TODO make connect function
    111116        in->addConnection(ConnectionBase(out,priority));
     117        in->setReadingMode(mode);
    112118        //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
    113                 in->setReadingMode(InputInterfaceBase::NeverSkip);
    114119        return true;
    115120    } else {
  • branches/2.0-beta1/include/Pacpus/kernel/inputOutputInterface.h

    r102 r110  
    44#include <Pacpus/kernel/Log.h>
    55#include <Pacpus/kernel/inputOutputBase.h>
     6#include <QApplication>
     7#include <typeinfo>
    68
    7 #include <typeinfo>
    89#include <QDebug>
    9 #include <QApplication>
     10#include <QThread>
    1011
    1112#include <QByteArray>
     
    1314#define ADD_INPUT(name,ComponentType, DataType, functionName)  input.insert(name,new InputInterface<DataType,ComponentType> (name,this,&ComponentType::functionName))
    1415#define ADD_OUTPUT(name,ComponentType, DataType)      output.insert(name,new OutputInterface<DataType,ComponentType> (name,this))
     16
    1517#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))
    1619
    1720namespace pacpus {
     
    2629    QString getDataType() {return QString(typeid(T).name());}
    2730
    28     protected:
    29     int boundingTime_;
     31protected:
    3032
    31     public:
     33public:
    3234
    33     PacpusEvent getEventTemplate() {return PacpusTypedEvent<T>(TYPED_EVENT); }
     35    PacpusEvent* getEventTemplate() {return new PacpusTypedEvent<T>(TYPED_EVENT); }
    3436
    3537    void customEvent(QEvent* event) {
     
    3739        switch (event->type()) {
    3840
    39                 // from Component to Component (T->T)
    40             case TYPED_EVENT: {
    41                 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event);
    42                 //qDebug() << "E1 ";
    43                 //qDebug() << "recived 2 thread " << QThread::currentThread();
    44                     if(typedEvent->tr_ == 0 && readingMode_ == TimeBounded) {
    45                         //LOG_WARN("Incorrect TimeRange (0), switch to NeverSkip");
    46                         readingMode_ = NeverSkip;}
     41        // from Component to Component (T->T)
     42        case TYPED_EVENT: {
     43            PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event);
    4744
    48                 switch (readingMode_){
    49                     case TimeBounded:
    50                                                 qDebug() << "Input " << this->getSignature() << " Time bournded "<< road_time()- typedEvent->t_ << " " << typedEvent->tr_;
    51                     if(road_time() - typedEvent->t_> typedEvent->tr_)
    52                                                 { qDebug() << "Data skip " << this->getSignature();
    53                                         break;}
    54                         (dynamic_cast<C*>(_component)->*method)(typedEvent->_data);
    55                         break;
    56                     case GetLast:
    57                                                 qDebug() << "Input " << this->getSignature() << "GetLast "<< road_time() - typedEvent->t_ << " " << typedEvent->tr_;
    58                         (dynamic_cast<C*>(_component)->*method)(typedEvent->_data);
    59                         QCoreApplication::removePostedEvents(this,TYPED_EVENT); // delete all remining events
    60                         break;
    61                     case NeverSkip:
    62                                                 qDebug() << "Input " << this->getSignature() << "NeverSkip "<< road_time() - typedEvent->t_ << " " << typedEvent->tr_;
    63                     default:
    64                         (dynamic_cast<C*>(_component)->*method)(typedEvent->_data);
    65                 }
     45            qDebug() << "Revever " << getSignature() << " thread " << QThread::currentThread() << " Data & " << & typedEvent->data_;
     46
     47            if(typedEvent->tr_ < 500 && readingMode_ == TimeBounded) {
     48                //LOG_WARN("Incorrect TimeRange (0), switch to NeverSkip");
     49                qDebug() << "Incorrect TimeRange (0), switch to NeverSkip";
     50                readingMode_ = NeverSkip;}
     51
     52            switch (readingMode_){
     53            case TimeBounded:
     54                qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("Time bournded").leftJustified(15) << road_time()- typedEvent->t_ << "\t" << typedEvent->tr_;
     55
     56                if(road_time() - typedEvent->t_> typedEvent->tr_)
     57                    {qDebug() << "Data skip " << this->getSignature();  break;}
     58
     59                (dynamic_cast<C*>(_component)->*method)(typedEvent->data_);
    6660                break;
     61
     62            case GetLast:
     63                qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("GetLast").leftJustified(15) << road_time() - typedEvent->t_ << "\t" << typedEvent->tr_;
     64
     65                (dynamic_cast<C*>(_component)->*method)(typedEvent->data_);
     66                QCoreApplication::removePostedEvents(this,TYPED_EVENT); // delete all remining events
     67                break;
     68
     69            case NeverSkip:
     70                qDebug() << "Input " << this->getSignature().leftJustified(20) << QString("NeverSkip").leftJustified(15) << road_time() - typedEvent->t_ << "\t" << typedEvent->tr_;
     71
     72            default:
     73                (dynamic_cast<C*>(_component)->*method)(typedEvent->data_);
    6774            }
     75            break;
     76        }
    6877
    69                 // from Connection interface to Component (G->T)
    70 /*            case GENERIC_EVENT2: {
     78            // from Connection interface to Component (G->T)
     79            /*            case GENERIC_EVENT2: {
    7180                PacpusTypedEvent<QByteArray> * genericEvent = dynamic_cast<PacpusTypedEvent<QByteArray> *> (event);
    7281                T data;
    73                 QByteArray& buf = (QByteArray&) genericEvent->_data;
     82                QByteArray& buf = (QByteArray&) genericEvent->data_;
    7483                QDataStream in(&buf,QIODevice::ReadOnly);
    7584
     
    8190            case GENERIC_EVENT3: {
    8291                PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event);
    83                 (dynamic_cast<C*>(_component)->*method)(typedEvent->_data);     // copy 3 X
     92                (dynamic_cast<C*>(_component)->*method)(typedEvent->data_);     // copy 3 X
    8493
    8594                break;
    8695            }*/
    8796
    88             default:
     97        default:
    8998
    9099            qDebug() << "Unknown event ID " << event->type();
    91                 break;
     100            break;
    92101        }
     102    event->accept();
     103    }
    93104
     105    T& getData() {
     106        T data;
     107        // TODO ask output data;
    94108
     109            //LOG4CXX_INFO(getLogger(), "Hello, World");
     110
     111        return data;
    95112    }
    96113
    97114protected:
    98115    void (C::*method)(const T&);
     116
     117 /*   log4cxx::LoggerPtr& getLogger() {
     118        static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(    LOG4CXX_LOCATION.getClassName()));
     119        return logger;
     120    }*/
    99121
    100122};
     
    109131    // Used by Components to send data througth typed output
    110132    void send(const T & data, road_time_t t = road_time(), road_timerange_t tr = 0) {
     133
     134        //QSharedPointer<T> sharedPointer = new T(data);
     135
     136        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){
     137            QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data,t,tr),it->getPriority()); // Event is delete by the event loop handler
     138            qDebug() << "sender " << it->getInterface()->getSignature() <<  " thread " << QThread::currentThread() << " Data & " << &data << " ";
     139            // TODO DAta SHAred
     140        }
     141    }
     142
     143    /*    void send(const T & data, road_time_t t = road_time(), road_timerange_t tr = 0) {
    111144        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){
    112145
    113             //if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name()))
     146            if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name()))
    114147                QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data,t,tr),it->getPriority());
    115            /*else {
     148           else {
    116149                QByteArray buf;
    117150                QDataStream out(&buf,QIODevice::ReadWrite);
    118151                PacpusTypedEvent<QByteArray> * ev =new PacpusTypedEvent<QByteArray>(GENERIC_EVENT3,buf);
    119152                QApplication::postEvent(it->getInterface(),ev,it->getPriority()); // Copy 2 (ctor)
    120                 }*/
     153                }
    121154        }
    122155    }
    123156
    124157    // Used by Connection Interfaces only to pose generic event
    125 /*    void sendGenericData(char * data, size_t size) {
     158        void sendGenericData(char * data, size_t size) {
    126159        QByteArray buf(data,size);  // copy 5
    127160        for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
Note: See TracChangeset for help on using the changeset viewer.