Changeset 148 in pacpusframework for branches/2.0-beta1/include/Pacpus/kernel/InputOutputBase.h
- Timestamp:
- 07/31/13 14:42:05 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/include/Pacpus/kernel/InputOutputBase.h
r137 r148 7 7 8 8 #include <QApplication> 9 #include <QList> 10 #include <QString> 11 #include <QStringList> 9 12 #include <typeinfo> 10 #include <QList>11 #include <QStringList>12 13 13 14 namespace pacpus { … … 15 16 class ComponentBase; 16 17 17 class PACPUSLIB_API AbstractInterface : public QObject 18 class PACPUSLIB_API AbstractInterface 19 : public QObject 18 20 { 19 21 Q_OBJECT 22 20 23 protected: 21 AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0):_name(name),_component(component),QObject(parent) {} 22 ~AbstractInterface(){} 24 AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0) 25 : m_name(name) 26 , m_component(component) 27 , QObject(parent) 28 {} 29 30 ~AbstractInterface() 31 {} 32 23 33 public: 24 34 QString getSignature(); 25 QString getName() {return _name;} 35 QString getName() 36 { 37 return m_name; 38 } 39 26 40 virtual QString getDataType() = 0; 27 ComponentBase * getComponent() {return _component;} 28 29 void addConnection(ConnectionBase connection) { _connection.append(connection);} 30 bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);} 31 32 bool hasConnection() { return _connection.size() > 0;} 33 41 42 ComponentBase * getComponent() 43 { 44 return m_component; 45 } 46 47 void addConnection(ConnectionBase connection) 48 { 49 m_connections.append(connection); 50 } 51 52 bool removeConnection(ConnectionBase connection) 53 { 54 return m_connections.removeOne(connection); 55 } 56 57 bool hasConnection() 58 { 59 return m_connections.size() > 0; 60 } 61 34 62 protected: 35 QString _name; 36 ComponentBase * _component; 37 QList<ConnectionBase> _connection; 63 QList<ConnectionBase> & connections() 64 { 65 return m_connections; 66 } 67 68 const QList<ConnectionBase> & connections() const 69 { 70 return m_connections; 71 } 72 73 QString name() 74 { 75 return m_name; 76 } 77 78 ComponentBase * component() 79 { 80 return m_component; 81 } 82 83 const ComponentBase * component() const 84 { 85 return m_component; 86 } 87 88 private: 89 QString m_name; 90 ComponentBase * m_component; 91 QList<ConnectionBase> m_connections; 38 92 }; 39 93 40 class PACPUSLIB_API InputInterfaceBase : public AbstractInterface 94 class PACPUSLIB_API InputInterfaceBase 95 : public AbstractInterface 41 96 { 42 97 Q_OBJECT 43 98 protected: 44 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {} 99 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0) 100 : AbstractInterface(name, component, parent) 101 {} 45 102 46 103 public: 47 104 //InputInterfaceBase(QString name, ComponentBase * component,int a, QObject * parent = 0):AbstractInterface(name,component,parent) {} // TODO add ctor with function pointer 48 105 49 106 enum ReadingMode { 50 107 NeverSkip, 51 108 TimeBounded, … … 53 110 }; 54 111 55 virtual ~InputInterfaceBase(){} 56 57 virtual void customEvent(QEvent* e) { 58 112 virtual ~InputInterfaceBase() 113 {} 114 115 virtual void customEvent(QEvent* e) 116 { 59 117 //if(event->type()) 60 //TODO get event Type anf call callback function 61 62 PacpusEvent * event = dynamic_cast<PacpusEvent *>(e); 63 QByteArray buf; 64 QDataStream out(&buf,QIODevice::WriteOnly); 65 event->streamOut(out); 66 // Callback QByteArray 67 } 68 69 void setReadingMode(ReadingMode mode) { readingMode_ = mode;} 70 virtual PacpusEvent* getEventTemplate() {return new PacpusEvent(GENERIC_EVENT);} // TODO check ?? 71 protected: 72 ReadingMode readingMode_; 118 //TODO get event Type anf call callback function 119 120 PacpusEvent * event = dynamic_cast<PacpusEvent *>(e); 121 QByteArray buf; 122 QDataStream out(&buf, QIODevice::WriteOnly); 123 event->streamOut(out); 124 // Callback QByteArray 125 } 126 127 ReadingMode & readingMode() 128 { 129 return m_readingMode; 130 } 131 132 const ReadingMode & readingMode() const 133 { 134 return m_readingMode; 135 } 136 137 void setReadingMode(ReadingMode mode) 138 { 139 m_readingMode = mode; 140 } 141 142 virtual PacpusEvent* getEventTemplate() 143 { 144 // TODO: check 145 return new PacpusEvent(GENERIC_EVENT); 146 } 147 73 148 private: 74 // metode(QByteArray) 75 76 //QQueue jobQueue_; 149 ReadingMode m_readingMode; 150 151 // metode(QByteArray) 152 //QQueue jobQueue_; 77 153 }; 78 154 79 class PACPUSLIB_API OutputInterfaceBase: public AbstractInterface 155 class PACPUSLIB_API OutputInterfaceBase 156 : public AbstractInterface 80 157 { 81 158 Q_OBJECT 82 159 83 160 public: 84 OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {} 85 86 virtual ~OutputInterfaceBase(){} 87 88 QStringList getInputConnectedList() { 161 OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0) 162 : AbstractInterface(name, component, parent) 163 {} 164 165 virtual ~OutputInterfaceBase() 166 {} 167 168 QStringList getInputConnectedList() 169 { 89 170 QStringList list; 90 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)171 for(QList<ConnectionBase>::iterator it = connections().begin(); it != connections().end(); ++it) { 91 172 list.append(it->getInterface()->getName()); 173 } 92 174 return list; 93 175 } 94 176 95 void send(/*const*/ QByteArray & data) { 177 void send(/*const*/ QByteArray & data) 178 { 96 179 // TODO check at least one Typed connection 97 180 98 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it){181 for(QList<ConnectionBase>::iterator it = connections().begin(); it!=connections().end(); ++it){ 99 182 QDataStream in(&data,QIODevice::ReadOnly); 100 PacpusEvent* event = dynamic_cast<InputInterfaceBase*>( _connection.at(0).getInterface())->getEventTemplate();183 PacpusEvent* event = dynamic_cast<InputInterfaceBase*>(connections().at(0).getInterface())->getEventTemplate(); 101 184 event->streamIn(in); 102 185 QApplication::postEvent(it->getInterface(),event,it->getPriority()); 103 186 } 104 105 106 187 } 107 188 … … 111 192 { 112 193 if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) { 113 114 194 // Add connection 115 195 out->addConnection(ConnectionBase(in,priority)); // TODO make connect function … … 119 199 return true; 120 200 } else { 121 //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name()));122 return false;201 //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name())); 202 return false; 123 203 } 124 204 }
Note:
See TracChangeset
for help on using the changeset viewer.