#ifndef IN_OUT_BASE_H #define IN_OUT_BASE_H #include #include #include #include #include #include #include #include #include namespace pacpus { class ComponentBase; class PACPUSLIB_API AbstractInterface : public QObject { Q_OBJECT protected: AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0); virtual ~AbstractInterface(); public: QString getSignature() const; QString getName() const; virtual QString getDataType() = 0; void addConnection(ConnectionBase connection); bool removeConnection(ConnectionBase connection); bool hasConnection(); protected: QList & connections(); const QList & getConnections() const; ComponentBase * component(); const ComponentBase * getComponent() const; private: QString m_name; ComponentBase * m_component; QList m_connections; }; class PACPUSLIB_API InputInterfaceBase : public AbstractInterface { Q_OBJECT protected: // TODO: add ctor with function pointer InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0); public: enum ReadingMode { NeverSkip, TimeBounded, GetLast }; virtual ~InputInterfaceBase(); virtual void customEvent(QEvent* e); ReadingMode & readingMode(); const ReadingMode & readingMode() const; void setReadingMode(ReadingMode mode); virtual PacpusEvent * getEventTemplate(); private: ReadingMode m_readingMode; // metode(QByteArray) //QQueue jobQueue_; }; class PACPUSLIB_API OutputInterfaceBase : public AbstractInterface { Q_OBJECT public: OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0) : AbstractInterface(name, component, parent) {} virtual ~OutputInterfaceBase() {} QStringList getInputConnectedList(); // TODO for serialization prupose (not yet implemented !!!) void send(/*const*/ QByteArray & data); }; namespace { bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast); bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode) { if (out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) { // Add connection out->addConnection(ConnectionBase(in, priority)); // TODO make connect function in->addConnection(ConnectionBase(out, priority)); in->setReadingMode(mode); //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature()); return true; } else { //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name())); return false; } } } // namespace } // namespace pacpus #endif // IN_OUT_BASE_H