source: pacpusframework/branches/0.2.x/src/PacpusLib/InputOutputBase.cpp

Last change on this file 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
Line 
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
8using namespace pacpus;
9
10DECLARE_STATIC_LOGGER("pacpus.core.InputOutputInterface");
11
12////////////////////////////////////////////////////////////////////////////////
13
14AbstractInterface::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
22AbstractInterface::~AbstractInterface()
23{
24}
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)
74 : AbstractInterface(name, component, parent)
75{
76}
77
78InputInterfaceBase::~InputInterfaceBase()
79{
80}
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
100const InputInterfaceBase::ReadingMode & InputInterfaceBase::getReadingMode() const
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
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.