[89] | 1 | #ifndef IN_OUT_BASE_H
|
---|
| 2 | #define IN_OUT_BASE_H
|
---|
| 3 |
|
---|
[182] | 4 | #include <Pacpus/kernel/ConnectionBase.h>
|
---|
[153] | 5 | #include <Pacpus/kernel/Log.h>
|
---|
[95] | 6 | #include <Pacpus/kernel/pacpus.h>
|
---|
[96] | 7 | #include <Pacpus/kernel/PacpusEvent.h>
|
---|
[89] | 8 |
|
---|
[96] | 9 | #include <QApplication>
|
---|
[89] | 10 | #include <QList>
|
---|
[148] | 11 | #include <QString>
|
---|
[89] | 12 | #include <QStringList>
|
---|
[148] | 13 | #include <typeinfo>
|
---|
[89] | 14 |
|
---|
| 15 | namespace pacpus {
|
---|
| 16 |
|
---|
| 17 | class ComponentBase;
|
---|
| 18 |
|
---|
[148] | 19 | class PACPUSLIB_API AbstractInterface
|
---|
| 20 | : public QObject
|
---|
[89] | 21 | {
|
---|
| 22 | Q_OBJECT
|
---|
[148] | 23 |
|
---|
[89] | 24 | protected:
|
---|
[182] | 25 | AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0);
|
---|
| 26 | virtual ~AbstractInterface();
|
---|
[148] | 27 |
|
---|
[89] | 28 | public:
|
---|
[182] | 29 | QString getSignature() const;
|
---|
| 30 | QString getName() const;
|
---|
[89] | 31 | virtual QString getDataType() = 0;
|
---|
[148] | 32 |
|
---|
[182] | 33 | void addConnection(ConnectionBase connection);
|
---|
| 34 | bool removeConnection(ConnectionBase connection);
|
---|
| 35 | bool hasConnection();
|
---|
[148] | 36 |
|
---|
[89] | 37 | protected:
|
---|
[182] | 38 | QList<ConnectionBase> & connections();
|
---|
| 39 | const QList<ConnectionBase> & getConnections() const;
|
---|
[148] | 40 |
|
---|
[182] | 41 | ComponentBase * component();
|
---|
| 42 | const ComponentBase * getComponent() const;
|
---|
[148] | 43 |
|
---|
| 44 | private:
|
---|
| 45 | QString m_name;
|
---|
| 46 | ComponentBase * m_component;
|
---|
| 47 | QList<ConnectionBase> m_connections;
|
---|
[89] | 48 | };
|
---|
| 49 |
|
---|
[148] | 50 | class PACPUSLIB_API InputInterfaceBase
|
---|
| 51 | : public AbstractInterface
|
---|
[89] | 52 | {
|
---|
| 53 | Q_OBJECT
|
---|
[152] | 54 |
|
---|
[96] | 55 | protected:
|
---|
[182] | 56 | // TODO: add ctor with function pointer
|
---|
| 57 | InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0);
|
---|
[96] | 58 |
|
---|
[89] | 59 | public:
|
---|
[148] | 60 | enum ReadingMode {
|
---|
[102] | 61 | NeverSkip,
|
---|
| 62 | TimeBounded,
|
---|
| 63 | GetLast
|
---|
| 64 | };
|
---|
| 65 |
|
---|
[182] | 66 | virtual ~InputInterfaceBase();
|
---|
[89] | 67 |
|
---|
[182] | 68 | virtual void customEvent(QEvent* e);
|
---|
[96] | 69 |
|
---|
[182] | 70 | ReadingMode & readingMode();
|
---|
| 71 | const ReadingMode & readingMode() const;
|
---|
| 72 | void setReadingMode(ReadingMode mode);
|
---|
[96] | 73 |
|
---|
[182] | 74 | virtual PacpusEvent * getEventTemplate();
|
---|
[148] | 75 |
|
---|
[110] | 76 | private:
|
---|
[148] | 77 | ReadingMode m_readingMode;
|
---|
[110] | 78 |
|
---|
[148] | 79 | // metode(QByteArray)
|
---|
| 80 | //QQueue jobQueue_;
|
---|
[89] | 81 | };
|
---|
| 82 |
|
---|
[148] | 83 | class PACPUSLIB_API OutputInterfaceBase
|
---|
| 84 | : public AbstractInterface
|
---|
[89] | 85 | {
|
---|
| 86 | Q_OBJECT
|
---|
[96] | 87 |
|
---|
[89] | 88 | public:
|
---|
[148] | 89 | OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0)
|
---|
| 90 | : AbstractInterface(name, component, parent)
|
---|
| 91 | {}
|
---|
[96] | 92 |
|
---|
[148] | 93 | virtual ~OutputInterfaceBase()
|
---|
| 94 | {}
|
---|
[89] | 95 |
|
---|
[182] | 96 | QStringList getInputConnectedList();
|
---|
[89] | 97 |
|
---|
[182] | 98 | // TODO for serialization prupose (not yet implemented !!!)
|
---|
| 99 | void send(/*const*/ QByteArray & data);
|
---|
| 100 | };
|
---|
[89] | 101 |
|
---|
[182] | 102 | namespace {
|
---|
[96] | 103 |
|
---|
[182] | 104 | bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast);
|
---|
[89] | 105 |
|
---|
[182] | 106 | bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode)
|
---|
[96] | 107 | {
|
---|
[182] | 108 | if (out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
|
---|
[96] | 109 | // Add connection
|
---|
[182] | 110 | out->addConnection(ConnectionBase(in, priority)); // TODO make connect function
|
---|
| 111 | in->addConnection(ConnectionBase(out, priority));
|
---|
[110] | 112 | in->setReadingMode(mode);
|
---|
[96] | 113 | //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
|
---|
| 114 | return true;
|
---|
| 115 | } else {
|
---|
[148] | 116 | //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name()));
|
---|
| 117 | return false;
|
---|
[96] | 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[182] | 121 | } // namespace
|
---|
| 122 |
|
---|
[89] | 123 | } // namespace pacpus
|
---|
| 124 |
|
---|
| 125 | #endif // IN_OUT_BASE_H
|
---|