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