| [182] | 1 | #include <Pacpus/kernel/InputOutputBase.h>
|
|---|
| 2 |
|
|---|
| [111] | 3 | #include <Pacpus/kernel/ComponentBase.h>
|
|---|
| [182] | 4 | #include <Pacpus/kernel/ConnectionBase.h>
|
|---|
| [137] | 5 | #include <Pacpus/kernel/InputOutputInterface.h>
|
|---|
| [111] | 6 | #include <Pacpus/kernel/Log.h>
|
|---|
| 7 |
|
|---|
| 8 | using namespace pacpus;
|
|---|
| 9 |
|
|---|
| [137] | 10 | DECLARE_STATIC_LOGGER("pacpus.core.InputOutputInterface");
|
|---|
| [111] | 11 |
|
|---|
| [182] | 12 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 13 |
|
|---|
| 14 | AbstractInterface::AbstractInterface(QString name, ComponentBase * component, QObject * parent)
|
|---|
| 15 | : m_name(name)
|
|---|
| 16 | , m_component(component)
|
|---|
| 17 | , QObject(parent)
|
|---|
| [111] | 18 | {
|
|---|
| [182] | 19 | LOG_DEBUG("constructing abstract connection '" << getName() << "'");
|
|---|
| [111] | 20 | }
|
|---|
| [182] | 21 |
|
|---|
| 22 | AbstractInterface::~AbstractInterface()
|
|---|
| 23 | {}
|
|---|
| 24 |
|
|---|
| 25 | QString AbstractInterface::getSignature() const
|
|---|
| 26 | {
|
|---|
| 27 | return getComponent()->getName() + '.' + getName();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | QString AbstractInterface::getName() const
|
|---|
| 31 | {
|
|---|
| 32 | return m_name;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | QList<ConnectionBase> & AbstractInterface::connections()
|
|---|
| 36 | {
|
|---|
| 37 | return m_connections;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | const QList<ConnectionBase> & AbstractInterface::getConnections() const
|
|---|
| 41 | {
|
|---|
| 42 | return m_connections;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | ComponentBase * AbstractInterface::component()
|
|---|
| 46 | {
|
|---|
| 47 | return m_component;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | const ComponentBase * AbstractInterface::getComponent() const
|
|---|
| 51 | {
|
|---|
| 52 | return m_component;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void AbstractInterface::addConnection(ConnectionBase connection)
|
|---|
| 56 | {
|
|---|
| 57 | m_connections.append(connection);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | bool AbstractInterface::removeConnection(ConnectionBase connection)
|
|---|
| 61 | {
|
|---|
| 62 | return m_connections.removeOne(connection);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | bool AbstractInterface::hasConnection()
|
|---|
| 66 | {
|
|---|
| 67 | return m_connections.size() > 0;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 71 |
|
|---|
| 72 | InputInterfaceBase::InputInterfaceBase(QString name, ComponentBase * component, QObject * parent)
|
|---|
| 73 | : AbstractInterface(name, component, parent)
|
|---|
| 74 | {}
|
|---|
| 75 |
|
|---|
| 76 | InputInterfaceBase::~InputInterfaceBase()
|
|---|
| 77 | {}
|
|---|
| 78 |
|
|---|
| 79 | // TODO for serialization prupose (not yet implemented !!!)
|
|---|
| 80 | void InputInterfaceBase::customEvent(QEvent* e)
|
|---|
| 81 | {
|
|---|
| 82 | //if (event->type())
|
|---|
| 83 | //TODO get event Type anf call callback function
|
|---|
| 84 |
|
|---|
| 85 | PacpusEvent * event = dynamic_cast<PacpusEvent *>(e);
|
|---|
| 86 | QByteArray buf;
|
|---|
| 87 | QDataStream out(&buf, QIODevice::WriteOnly);
|
|---|
| 88 | event->streamOut(out);
|
|---|
| 89 | // Callback QByteArray
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | InputInterfaceBase::ReadingMode & InputInterfaceBase::readingMode()
|
|---|
| 93 | {
|
|---|
| 94 | return m_readingMode;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| [185] | 97 | const InputInterfaceBase::ReadingMode & InputInterfaceBase::getReadingMode() const
|
|---|
| [182] | 98 | {
|
|---|
| 99 | return m_readingMode;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void InputInterfaceBase::setReadingMode(ReadingMode mode)
|
|---|
| 103 | {
|
|---|
| 104 | m_readingMode = mode;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | PacpusEvent * InputInterfaceBase::getEventTemplate()
|
|---|
| 108 | {
|
|---|
| 109 | // TODO: check
|
|---|
| 110 | return new PacpusEvent(GENERIC_EVENT);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 114 |
|
|---|
| 115 | QStringList OutputInterfaceBase::getInputConnectedList()
|
|---|
| 116 | {
|
|---|
| 117 | QStringList list;
|
|---|
| 118 | for (QList<ConnectionBase>::iterator it = connections().begin(); it != connections().end(); ++it) {
|
|---|
| 119 | list.append(it->getInterface()->getName());
|
|---|
| 120 | }
|
|---|
| 121 | return list;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| [206] | 124 | // TODO for serialization purpose (not yet implemented !!!)
|
|---|
| 125 | //void OutputInterfaceBase::send(/*const*/ QByteArray & data)
|
|---|
| 126 | //{
|
|---|
| 127 | // // TODO check at least one Typed connection
|
|---|
| 128 | //
|
|---|
| 129 | // for (QList<ConnectionBase>::iterator it = connections().begin(), itend = connections().end(); it != itend; ++it) {
|
|---|
| 130 | // QDataStream in(&data, QIODevice::ReadOnly);
|
|---|
| 131 | // InputInterfaceBase * interfaceBase
|
|---|
| 132 | // = dynamic_cast<InputInterfaceBase *>(connections().at(0).getInterface());
|
|---|
| 133 | // //AbstractInterface * interfaceBase = connections().at(0).getInterface();
|
|---|
| 134 | // if (!interfaceBase) {
|
|---|
| 135 | // continue;
|
|---|
| 136 | // }
|
|---|
| 137 | // PacpusEvent * event = interfaceBase->getEventTemplate();
|
|---|
| 138 | // if (!event) {
|
|---|
| 139 | // continue;
|
|---|
| 140 | // }
|
|---|
| 141 | // event->streamIn(in);
|
|---|
| 142 | // QCoreApplication::postEvent(
|
|---|
| 143 | // it->getInterface(),
|
|---|
| 144 | // event,
|
|---|
| 145 | // it->getPriority()
|
|---|
| 146 | // );
|
|---|
| 147 | // }
|
|---|
| 148 | //}
|
|---|