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