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

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

Major: cleaned connection interfaces.

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