source: pacpusframework/trunk/src/PacpusLib/InputOutputBase.cpp@ 308

Last change on this file since 308 was 293, checked in by Marek Kurdej, 11 years ago

REVERTED: Reworked threading in InputInterfaceBase, each slot has its own processing thread.

  • Property svn:executable set to *
File size: 3.9 KB
RevLine 
[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
8using namespace pacpus;
9
[137]10DECLARE_STATIC_LOGGER("pacpus.core.InputOutputInterface");
[111]11
[182]12////////////////////////////////////////////////////////////////////////////////
13
14AbstractInterface::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
22AbstractInterface::~AbstractInterface()
[291]23{
24}
[182]25
26QString AbstractInterface::getSignature() const
27{
28 return getComponent()->getName() + '.' + getName();
29}
30
31QString AbstractInterface::getName() const
32{
33 return m_name;
34}
35
36QList<ConnectionBase> & AbstractInterface::connections()
37{
38 return m_connections;
39}
40
41const QList<ConnectionBase> & AbstractInterface::getConnections() const
42{
43 return m_connections;
44}
45
46ComponentBase * AbstractInterface::component()
47{
48 return m_component;
49}
50
51const ComponentBase * AbstractInterface::getComponent() const
52{
53 return m_component;
54}
55
56void AbstractInterface::addConnection(ConnectionBase connection)
57{
58 m_connections.append(connection);
59}
60
61bool AbstractInterface::removeConnection(ConnectionBase connection)
62{
63 return m_connections.removeOne(connection);
64}
65
66bool AbstractInterface::hasConnection()
67{
68 return m_connections.size() > 0;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72
73InputInterfaceBase::InputInterfaceBase(QString name, ComponentBase * component, QObject * parent)
[293]74 : AbstractInterface(name, component, parent)
[291]75{
76}
[182]77
78InputInterfaceBase::~InputInterfaceBase()
[291]79{
80}
[182]81
82// TODO for serialization prupose (not yet implemented !!!)
83void 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
95InputInterfaceBase::ReadingMode & InputInterfaceBase::readingMode()
96{
97 return m_readingMode;
98}
99
[185]100const InputInterfaceBase::ReadingMode & InputInterfaceBase::getReadingMode() const
[182]101{
102 return m_readingMode;
103}
104
105void InputInterfaceBase::setReadingMode(ReadingMode mode)
106{
107 m_readingMode = mode;
108}
109
110PacpusEvent * InputInterfaceBase::getEventTemplate()
111{
112 // TODO: check
113 return new PacpusEvent(GENERIC_EVENT);
114}
115
116////////////////////////////////////////////////////////////////////////////////
117
118QStringList 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
[206]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//}
Note: See TracBrowser for help on using the repository browser.