Changeset 182 in pacpusframework for trunk/src/PacpusLib/InputOutputBase.cpp


Ignore:
Timestamp:
Oct 23, 2013, 9:09:51 AM (11 years ago)
Author:
Marek Kurdej
Message:

Fixed: dependencies in InputOutputBase, ConnectionBase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PacpusLib/InputOutputBase.cpp

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