[89] | 1 | #ifndef IN_OUT_BASE_H
|
---|
| 2 | #define IN_OUT_BASE_H
|
---|
| 3 |
|
---|
[95] | 4 | #include <Pacpus/kernel/pacpus.h>
|
---|
[89] | 5 | #include <Pacpus/kernel/ConnectionBase.h>
|
---|
[96] | 6 | #include <Pacpus/kernel/PacpusEvent.h>
|
---|
[89] | 7 |
|
---|
[96] | 8 | #include <QApplication>
|
---|
[89] | 9 | #include <typeinfo>
|
---|
| 10 | #include <QList>
|
---|
| 11 | #include <QStringList>
|
---|
| 12 |
|
---|
| 13 | namespace pacpus {
|
---|
| 14 |
|
---|
| 15 | class ComponentBase;
|
---|
| 16 |
|
---|
[94] | 17 | class PACPUSLIB_API AbstractInterface : public QObject
|
---|
[89] | 18 | {
|
---|
| 19 | Q_OBJECT
|
---|
| 20 | protected:
|
---|
| 21 | AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0):_name(name),_component(component),QObject(parent) {}
|
---|
| 22 | ~AbstractInterface(){}
|
---|
| 23 | public:
|
---|
| 24 | QString getSignature();
|
---|
| 25 | QString getName() {return _name;}
|
---|
| 26 | virtual QString getDataType() = 0;
|
---|
[96] | 27 | ComponentBase * getComponent() {return _component;}
|
---|
[89] | 28 |
|
---|
[96] | 29 | void addConnection(ConnectionBase connection) { _connection.append(connection);}
|
---|
| 30 | bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);}
|
---|
| 31 |
|
---|
[89] | 32 | protected:
|
---|
| 33 | QString _name;
|
---|
| 34 | ComponentBase * _component;
|
---|
[96] | 35 | QList<ConnectionBase> _connection;
|
---|
[89] | 36 | };
|
---|
| 37 |
|
---|
[94] | 38 | class PACPUSLIB_API InputInterfaceBase : public AbstractInterface
|
---|
[89] | 39 | {
|
---|
| 40 | Q_OBJECT
|
---|
[96] | 41 | protected:
|
---|
| 42 | InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
|
---|
| 43 |
|
---|
[89] | 44 | public:
|
---|
[96] | 45 | //InputInterfaceBase(QString name, ComponentBase * component,int a, QObject * parent = 0):AbstractInterface(name,component,parent) {} // TODO add ctor with function pointer
|
---|
| 46 |
|
---|
[89] | 47 | virtual ~InputInterfaceBase(){}
|
---|
| 48 |
|
---|
[96] | 49 | virtual void customEvent(QEvent* e) {
|
---|
[89] | 50 |
|
---|
[96] | 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 ??
|
---|
| 61 |
|
---|
[89] | 62 | };
|
---|
| 63 |
|
---|
[94] | 64 | class PACPUSLIB_API OutputInterfaceBase: public AbstractInterface
|
---|
[89] | 65 | {
|
---|
| 66 | Q_OBJECT
|
---|
[96] | 67 |
|
---|
[89] | 68 | public:
|
---|
| 69 | OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
|
---|
[96] | 70 |
|
---|
[89] | 71 | virtual ~OutputInterfaceBase(){}
|
---|
| 72 |
|
---|
| 73 | QStringList getInputConnectedList() {
|
---|
| 74 | QStringList list;
|
---|
| 75 | for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
|
---|
[96] | 76 | list.append(it->getInterface()->getName());
|
---|
[89] | 77 | return list;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[96] | 80 | void send(/*const*/ QByteArray & data) {
|
---|
[89] | 81 |
|
---|
[96] | 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 | }
|
---|
| 92 |
|
---|
[89] | 93 | };
|
---|
| 94 |
|
---|
[96] | 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 | }
|
---|
| 109 |
|
---|
[89] | 110 | } // namespace pacpus
|
---|
| 111 |
|
---|
| 112 | #endif // IN_OUT_BASE_H
|
---|