source: pacpusframework/trunk/include/Pacpus/kernel/InputOutputBase.h@ 184

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

Fixed: dependencies in InputOutputBase, ConnectionBase.

  • Property svn:executable set to *
File size: 3.3 KB
Line 
1#ifndef IN_OUT_BASE_H
2#define IN_OUT_BASE_H
3
4#include <Pacpus/kernel/ConnectionBase.h>
5#include <Pacpus/kernel/Log.h>
6#include <Pacpus/kernel/pacpus.h>
7#include <Pacpus/kernel/PacpusEvent.h>
8
9#include <QApplication>
10#include <QList>
11#include <QString>
12#include <QStringList>
13#include <typeinfo>
14
15namespace pacpus {
16
17class ComponentBase;
18
19class PACPUSLIB_API AbstractInterface
20 : public QObject
21{
22 Q_OBJECT
23
24protected:
25 AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0);
26 virtual ~AbstractInterface();
27
28public:
29 QString getSignature() const;
30 QString getName() const;
31 virtual QString getDataType() = 0;
32
33 void addConnection(ConnectionBase connection);
34 bool removeConnection(ConnectionBase connection);
35 bool hasConnection();
36
37protected:
38 QList<ConnectionBase> & connections();
39 const QList<ConnectionBase> & getConnections() const;
40
41 ComponentBase * component();
42 const ComponentBase * getComponent() const;
43
44private:
45 QString m_name;
46 ComponentBase * m_component;
47 QList<ConnectionBase> m_connections;
48};
49
50class PACPUSLIB_API InputInterfaceBase
51 : public AbstractInterface
52{
53 Q_OBJECT
54
55protected:
56 // TODO: add ctor with function pointer
57 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0);
58
59public:
60 enum ReadingMode {
61 NeverSkip,
62 TimeBounded,
63 GetLast
64 };
65
66 virtual ~InputInterfaceBase();
67
68 virtual void customEvent(QEvent* e);
69
70 ReadingMode & readingMode();
71 const ReadingMode & readingMode() const;
72 void setReadingMode(ReadingMode mode);
73
74 virtual PacpusEvent * getEventTemplate();
75
76private:
77 ReadingMode m_readingMode;
78
79 // metode(QByteArray)
80 //QQueue jobQueue_;
81};
82
83class PACPUSLIB_API OutputInterfaceBase
84 : public AbstractInterface
85{
86 Q_OBJECT
87
88public:
89 OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0)
90 : AbstractInterface(name, component, parent)
91 {}
92
93 virtual ~OutputInterfaceBase()
94 {}
95
96 QStringList getInputConnectedList();
97
98 // TODO for serialization prupose (not yet implemented !!!)
99 void send(/*const*/ QByteArray & data);
100};
101
102namespace {
103
104bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode = InputInterfaceBase::GetLast);
105
106bool connectInterface(OutputInterfaceBase * out, InputInterfaceBase * in, int priority, InputInterfaceBase::ReadingMode mode)
107{
108 if (out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
109 // Add connection
110 out->addConnection(ConnectionBase(in, priority)); // TODO make connect function
111 in->addConnection(ConnectionBase(out, priority));
112 in->setReadingMode(mode);
113 //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
114 return true;
115 } else {
116 //LOG_WARN("connecting " << out->getSignature() << ":" << out->getDataType() << " to " << in->getSignature() << ":" << in->getDataType() << " failled : DataType incompatible " << QString(typeid(QByteArray).name()));
117 return false;
118 }
119}
120
121} // namespace
122
123} // namespace pacpus
124
125#endif // IN_OUT_BASE_H
Note: See TracBrowser for help on using the repository browser.