Changeset 96 in pacpusframework
- Timestamp:
- May 23, 2013, 12:16:31 PM (11 years ago)
- Location:
- branches/2.0-beta1
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/include/Pacpus/kernel/ConnectionBase.h
r89 r96 5 5 namespace pacpus { 6 6 7 class InputInterfaceBase;7 class AbstractInterface; 8 8 9 9 class ConnectionBase 10 10 { 11 11 public: 12 ConnectionBase( InputInterfaceBase * input, int priority):_input(input),_priority(priority) {}12 ConnectionBase(AbstractInterface * interface, int priority):_interface(interface),_priority(priority) {} 13 13 ~ConnectionBase() {} 14 14 15 InputInterfaceBase * getInputInterface() const {return _input;}15 AbstractInterface * getInterface() const {return _interface;} 16 16 int getPriority() const {return _priority;} 17 17 18 18 bool operator== (ConnectionBase const &c) { 19 return _in put == c.getInputInterface() && _priority == c.getPriority();}19 return _interface == c.getInterface() && _priority == c.getPriority();} 20 20 21 21 private: 22 InputInterfaceBase * _input;22 AbstractInterface * _interface; 23 23 int _priority; 24 24 }; -
branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h
r94 r96 5 5 #include "Pacpus/kernel/road_time.h" 6 6 #include <Pacpus/kernel/pacpus.h> 7 #include <QDataStream> 7 8 8 9 namespace pacpus { … … 36 37 { 37 38 public: 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 45 public: // TODO make protected 46 road_time_t t_; 47 road_timerange_t tr_; 39 48 }; 40 49 … … 43 52 { 44 53 public: 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) {} 47 55 ~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 60 public: // TODO make protected 48 61 T _data; 49 road_time_t t_;50 road_timerange_t tr_;51 62 }; 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);} 52 66 53 67 class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent 54 68 { 55 69 public: 56 PacpusGenericEvent( QEvent::Type type, char* data, size_t size):PacpusEvent(type) {70 PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) { 57 71 _data = (char*)malloc(size); 58 72 memcpy(_data,data,size); -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h
r95 r96 4 4 #include <Pacpus/kernel/pacpus.h> 5 5 #include <Pacpus/kernel/ConnectionBase.h> 6 #include <Pacpus/kernel/PacpusEvent.h> 6 7 8 #include <QApplication> 7 9 #include <typeinfo> 8 #include <QEvent>9 10 #include <QList> 10 11 #include <QStringList> … … 24 25 QString getName() {return _name;} 25 26 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);} 27 31 28 32 protected: 29 33 QString _name; 30 34 ComponentBase * _component; 35 QList<ConnectionBase> _connection; 31 36 }; 32 37 … … 34 39 { 35 40 Q_OBJECT 41 protected: 42 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {} 43 36 44 public: 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 38 47 virtual ~InputInterfaceBase(){} 39 48 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 ?? 41 61 42 62 }; … … 45 65 { 46 66 Q_OBJECT 67 47 68 public: 48 69 OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {} 70 49 71 virtual ~OutputInterfaceBase(){} 50 51 void addConnection(ConnectionBase connection) { _connection.append(connection);}52 bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);}53 72 54 73 QStringList getInputConnectedList() { 55 74 QStringList list; 56 75 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it) 57 list.append(it->getIn putInterface()->getName());76 list.append(it->getInterface()->getName()); 58 77 return list; 59 78 } 60 79 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 } 63 92 64 93 }; 94 95 static 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 } 65 109 66 110 } // namespace pacpus -
branches/2.0-beta1/include/Pacpus/kernel/inputOutputInterface.h
r95 r96 4 4 #include <Pacpus/kernel/Log.h> 5 5 #include <Pacpus/kernel/inputOutputBase.h> 6 #include <Pacpus/kernel/PacpusEvent.h>7 6 8 7 #include <typeinfo> … … 41 40 public: 42 41 42 PacpusEvent getEventTemplate() {return PacpusTypedEvent<T>(TYPED_EVENT); } 43 43 44 void customEvent(QEvent* event) { 44 45 … … 72 73 73 74 // from Connection interface to Component (G->T) 74 case GENERIC_EVENT2: {75 /* case GENERIC_EVENT2: { 75 76 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();80 77 T data; 81 78 QByteArray& buf = (QByteArray&) genericEvent->_data; 82 //qDebug() << "DataSize " <<buf.size();83 79 QDataStream in(&buf,QIODevice::ReadOnly); 84 80 85 qDebug() << "t[19]= " << road_time();86 //in >> data; // copy 787 qDebug() << "t[20]= " << road_time();88 89 81 (dynamic_cast<C*>(_component)->*method)(data); // copy 8 X 90 91 qDebug() << "t[21]= " << road_time();92 82 break; 93 83 } … … 96 86 case GENERIC_EVENT3: { 97 87 PacpusTypedEvent<T> * typedEvent = dynamic_cast<PacpusTypedEvent<T> *> (event); 98 qDebug() << "E3 ";99 qDebug() << "t[6]= " << road_time();100 88 (dynamic_cast<C*>(_component)->*method)(typedEvent->_data); // copy 3 X 101 qDebug() << "t[7]= " << road_time(); 89 102 90 break; 103 } 91 }*/ 104 92 105 93 default: 106 94 107 qDebug() << " Badevent ID " << event->type();95 qDebug() << "Unknown event ID " << event->type(); 108 96 break; 109 97 } … … 128 116 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){ 129 117 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 { 135 121 QByteArray buf; 136 122 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 }*/ 149 126 } 150 127 } 151 128 152 129 // 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) { 155 131 QByteArray buf(data,size); // copy 5 156 qDebug() << "t[16]= " << road_time();157 132 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it) 158 QApplication::postEvent(it->getIn putInterface(),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 161 136 } 162 137 */ 163 138 size_t getDataSize() {return sizeof(T);} 164 139 QString getDataType() {return QString(typeid(T).name());} -
branches/2.0-beta1/src/FileLib/CMakeLists.txt
r95 r96 42 42 # Libraries 43 43 # ======================================== 44 if(WIN32) # TODO find other solution 44 45 target_link_libraries( 45 46 ${PROJECT_NAME} 46 47 PacpusLib 47 48 ) 49 endif() 48 50 49 51 # ======================================== -
branches/2.0-beta1/src/PacpusLib/CMakeLists.txt
r94 r96 88 88 ) 89 89 90 if(UNIX) 91 set(LIBS 92 FileLib 93 ) 94 endif() 95 90 96 # ======================================== 91 97 # Libraries … … 95 101 ${QT_LIBRARIES} 96 102 ${PACPUS_DEPENDENCIES_LIB} 97 #FileLib103 ${LIBS} 98 104 ) 99 105 -
branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp
r89 r96 196 196 return false;} 197 197 198 OutputInterfaceBase * out = getComponent(output[0])->getOutput(output[1]); 199 InputInterfaceBase * in = getComponent(input[0])->getInput(input[1]); 200 201 // if(in->getDataType() == QString(typeid(QByteArray).name()) && out->getDataType() != QString(typeid(QByteArray).name())) 202 203 if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) { 204 205 // Add connection 206 out->addConnection(ConnectionBase(in,priority)); // TODO and type argument 207 LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature()) 208 return true; 209 } else { 210 LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name())); 211 return false; 212 } 213 214 /* 215 FactoryMap::iterator it = factoryMap_.find(type); 216 if (it != factoryMap_.end()) 217 { 218 (*it)->addComponent(name); 219 return true; 220 } 221 return false;*/ 198 // NOTE Create communicationInterface if needed ?? 199 200 return connectInterface(getComponent(output[0])->getOutput(output[1]), getComponent(input[0])->getInput(input[1]), priority); 201 222 202 } 223 203 -
branches/2.0-beta1/src/PacpusLib/inputOutputInterface.cpp
r89 r96 13 13 14 14 15 //void OutputInterfaceBase::send2(QVariant val) { 16 // Q_EMIT sendOut(val); 17 //} 15 16
Note:
See TracChangeset
for help on using the changeset viewer.