source: pacpusframework/branches/2.0-beta1/include/Pacpus/kernel/inputOutputBase.h@ 102

Last change on this file since 102 was 102, checked in by morasjul, 11 years ago

beta : correct reading mode

  • Property svn:executable set to *
File size: 3.8 KB
RevLine 
[89]1#ifndef IN_OUT_BASE_H
2#define IN_OUT_BASE_H
3
[95]4#include <Pacpus/kernel/pacpus.h>
[89]5#include <Pacpus/kernel/ConnectionBase.h>
[96]6#include <Pacpus/kernel/PacpusEvent.h>
[89]7
[96]8#include <QApplication>
[89]9#include <typeinfo>
10#include <QList>
11#include <QStringList>
12
13namespace pacpus {
14
15class ComponentBase;
16
[94]17class PACPUSLIB_API AbstractInterface : public QObject
[89]18{
19 Q_OBJECT
20protected:
21 AbstractInterface(QString name, ComponentBase * component, QObject * parent = 0):_name(name),_component(component),QObject(parent) {}
22 ~AbstractInterface(){}
23public:
24 QString getSignature();
25 QString getName() {return _name;}
26 virtual QString getDataType() = 0;
[96]27 ComponentBase * getComponent() {return _component;}
[89]28
[96]29 void addConnection(ConnectionBase connection) { _connection.append(connection);}
30 bool removeConnection(ConnectionBase connection) { return _connection.removeOne(connection);}
31
[100]32 bool hasConnection() { return _connection.size() > 0;}
33
[89]34protected:
35 QString _name;
36 ComponentBase * _component;
[96]37 QList<ConnectionBase> _connection;
[89]38};
39
[94]40class PACPUSLIB_API InputInterfaceBase : public AbstractInterface
[89]41{
42 Q_OBJECT
[96]43protected:
44 InputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
45
[89]46public:
[96]47 //InputInterfaceBase(QString name, ComponentBase * component,int a, QObject * parent = 0):AbstractInterface(name,component,parent) {} // TODO add ctor with function pointer
48
[102]49 enum ReadingMode {
50 NeverSkip,
51 TimeBounded,
52 GetLast
53 };
54
[89]55 virtual ~InputInterfaceBase(){}
56
[96]57 virtual void customEvent(QEvent* e) {
[89]58
[96]59 //if(event->type())
60 //TODO get event Type anf call callback function
61
62 QByteArray buf;
63 QDataStream out(&buf,QIODevice::WriteOnly);
64 out << e;
65 // Callback QByteArray
66 }
67
[102]68 void setReadingMode(ReadingMode mode) { readingMode_ = mode;}
[96]69 virtual PacpusEvent getEventTemplate() {return PacpusEvent(GENERIC_EVENT);} // TODO check ??
[102]70protected:
71 ReadingMode readingMode_;
[89]72};
73
[94]74class PACPUSLIB_API OutputInterfaceBase: public AbstractInterface
[89]75{
76 Q_OBJECT
[96]77
[89]78public:
79 OutputInterfaceBase(QString name, ComponentBase * component, QObject * parent = 0):AbstractInterface(name,component,parent) {}
[96]80
[89]81 virtual ~OutputInterfaceBase(){}
82
83 QStringList getInputConnectedList() {
84 QStringList list;
85 for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
[96]86 list.append(it->getInterface()->getName());
[89]87 return list;
88 }
89
[96]90 void send(/*const*/ QByteArray & data) {
[89]91
[96]92 // TODo getEvent
93 //PacpusEvent& event = _connection.at(0).getInterface()->
94 QDataStream in(&data,QIODevice::ReadOnly);
95 //in >> event;
96
97 //for(QList<ConnectionBase>::iterator it = _connection.begin(); it!=_connection.end(); ++it)
98 // QApplication::postEvent(it->getInterface(),&event,it->getPriority());
99
100
101 }
102
[89]103};
104
[96]105static bool connectInterface(OutputInterfaceBase* out, InputInterfaceBase * in, int priority)
106{
107 if(out->getDataType() == in->getDataType() || out->getDataType() == QString(typeid(QByteArray).name()) || in->getDataType() == QString(typeid(QByteArray).name())) {
108
109 // Add connection
110 out->addConnection(ConnectionBase(in,priority)); // TODO make connect function
111 in->addConnection(ConnectionBase(out,priority));
112 //LOG_INFO("connection : Output " << out->getSignature() << " => Input " << in->getSignature());
[102]113 in->setReadingMode(InputInterfaceBase::NeverSkip);
[96]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
[89]121} // namespace pacpus
122
123#endif // IN_OUT_BASE_H
Note: See TracBrowser for help on using the repository browser.