Changeset 110 in pacpusframework for branches/2.0-beta1/include/Pacpus/kernel
- Timestamp:
- Jun 13, 2013, 1:43:39 PM (11 years ago)
- 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 29 29 #include <QString> 30 30 #include <QMap> 31 32 class QWidget; 31 33 32 34 namespace pacpus { … … 134 136 QMap<QString, OutputInterfaceBase *> output; 135 137 138 QWidget * ui; 139 136 140 private: 137 141 /// called by the ComponentManager to start the component -
branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h
r98 r110 9 9 namespace pacpus { 10 10 11 // registerEventType // TODO 12 11 13 class GenericData { 12 14 public: 13 15 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); 16 18 _size = size;} 17 19 18 ~GenericData() {free( _data);}20 ~GenericData() {free(data_);} 19 21 20 char * data() { return _data;}22 char * data() { return data_;} 21 23 size_t size() {return _size;} 22 24 23 25 private: 24 char* _data;26 char* data_; 25 27 size_t _size; 26 28 }; … … 52 54 { 53 55 public: 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) {} 55 57 ~PacpusTypedEvent() {} 56 58 57 QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<< _data*/;} // FIXME Stream Data errors58 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_*/;} 59 61 60 62 public: // TODO make protected 61 T _data;63 T data_; 62 64 }; 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);}66 65 67 66 class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent … … 69 68 public: 70 69 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); 73 72 _size = size; 74 73 75 74 } 76 virtual ~PacpusGenericEvent() {free( _data);}77 char* _data;75 virtual ~PacpusGenericEvent() {free(data_);} 76 char* data_; 78 77 size_t _size; 79 78 }; … … 82 81 } // namespace pacpus 83 82 83 inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;} 84 inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;} 85 84 86 #endif // PACPUS_EVENT_H -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h
r102 r110 60 60 //TODO get event Type anf call callback function 61 61 62 PacpusEvent * event = dynamic_cast<PacpusEvent *>(e); 62 63 QByteArray buf; 63 64 QDataStream out(&buf,QIODevice::WriteOnly); 64 out << e;65 event->streamOut(out); 65 66 // Callback QByteArray 66 67 } 67 68 68 69 void setReadingMode(ReadingMode mode) { readingMode_ = mode;} 69 virtual PacpusEvent getEventTemplate() {returnPacpusEvent(GENERIC_EVENT);} // TODO check ??70 virtual PacpusEvent* getEventTemplate() {return new PacpusEvent(GENERIC_EVENT);} // TODO check ?? 70 71 protected: 71 72 ReadingMode readingMode_; 73 private: 74 // metode(QByteArray) 75 76 //QQueue jobQueue_; 72 77 }; 73 78 … … 89 94 90 95 void send(/*const*/ QByteArray & data) { 96 // TODO check at least one Typed connection 91 97 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 } 99 104 100 105 … … 103 108 }; 104 109 105 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority )110 static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast) 106 111 { 107 112 if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) { … … 110 115 out->addConnection(ConnectionBase(in,priority)); // TODO make connect function 111 116 in->addConnection(ConnectionBase(out,priority)); 117 in->setReadingMode(mode); 112 118 //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature()); 113 in->setReadingMode(InputInterfaceBase::NeverSkip);114 119 return true; 115 120 } else { -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputInterface.h
r102 r110 4 4 #include <Pacpus/kernel/Log.h> 5 5 #include <Pacpus/kernel/inputOutputBase.h> 6 #include <QApplication> 7 #include <typeinfo> 6 8 7 #include <typeinfo>8 9 #include <QDebug> 9 #include <Q Application>10 #include <QThread> 10 11 11 12 #include <QByteArray> … … 13 14 #define ADD_INPUT(name,ComponentType, DataType, functionName) input.insert(name,new InputInterface<DataType,ComponentType> (name,this,&ComponentType::functionName)) 14 15 #define ADD_OUTPUT(name,ComponentType, DataType) output.insert(name,new OutputInterface<DataType,ComponentType> (name,this)) 16 15 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)) 16 19 17 20 namespace pacpus { … … 26 29 QString getDataType() {return QString(typeid(T).name());} 27 30 28 protected: 29 int boundingTime_; 31 protected: 30 32 31 33 public: 32 34 33 PacpusEvent getEventTemplate() {returnPacpusTypedEvent<T>(TYPED_EVENT); }35 PacpusEvent* getEventTemplate() {return new PacpusTypedEvent<T>(TYPED_EVENT); } 34 36 35 37 void customEvent(QEvent* event) { … … 37 39 switch (event->type()) { 38 40 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); 47 44 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_); 66 60 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_); 67 74 } 75 break; 76 } 68 77 69 70 /* case GENERIC_EVENT2: {78 // from Connection interface to Component (G->T) 79 /* case GENERIC_EVENT2: { 71 80 PacpusTypedEvent<QByteArray> * genericEvent = dynamic_cast<PacpusTypedEvent<QByteArray> *> (event); 72 81 T data; 73 QByteArray& buf = (QByteArray&) genericEvent-> _data;82 QByteArray& buf = (QByteArray&) genericEvent->data_; 74 83 QDataStream in(&buf,QIODevice::ReadOnly); 75 84 … … 81 90 case GENERIC_EVENT3: { 82 91 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 83 (dynamic_cast<C*>(_component)->*method)(typedEvent-> _data); // copy 3 X92 (dynamic_cast<C*>(_component)->*method)(typedEvent->data_); // copy 3 X 84 93 85 94 break; 86 95 }*/ 87 96 88 97 default: 89 98 90 99 qDebug() << "Unknown event ID " << event->type(); 91 100 break; 92 101 } 102 event->accept(); 103 } 93 104 105 T& getData() { 106 T data; 107 // TODO ask output data; 94 108 109 //LOG4CXX_INFO(getLogger(), "Hello, World"); 110 111 return data; 95 112 } 96 113 97 114 protected: 98 115 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 }*/ 99 121 100 122 }; … … 109 131 // Used by Components to send data througth typed output 110 132 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) { 111 144 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){ 112 145 113 //if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name()))146 if(it->getInterface()->getDataType() != QString(typeid(QByteArray).name())) 114 147 QApplication::postEvent(it->getInterface(),new PacpusTypedEvent<T>(TYPED_EVENT,data,t,tr),it->getPriority()); 115 /*else {148 else { 116 149 QByteArray buf; 117 150 QDataStream out(&buf,QIODevice::ReadWrite); 118 151 PacpusTypedEvent<QByteArray> * ev =new PacpusTypedEvent<QByteArray>(GENERIC_EVENT3,buf); 119 152 QApplication::postEvent(it->getInterface(),ev,it->getPriority()); // Copy 2 (ctor) 120 } */153 } 121 154 } 122 155 } 123 156 124 157 // 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) { 126 159 QByteArray buf(data,size); // copy 5 127 160 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
Note:
See TracChangeset
for help on using the changeset viewer.