00001
00004 #ifndef SXPORT_H_INCLUDED
00005 #define SXPORT_H_INCLUDED
00006
00007 #include "sxConnection.h"
00008
00009 class sxComponent;
00010 class sxPacket;
00011
00015 class SX_SDKEXPORT sxPort : public sxCaptionItem
00016 {
00017 public:
00018 virtual ~sxPort();
00019
00020 virtual bool Open();
00021 virtual bool Close();
00022 virtual sxPacket * Read();
00023 virtual sxConnection * MakeConnection(sxPort * with, const QString& name);
00024
00025 virtual void Clear() = 0;
00027 virtual void Write(sxPacket * packet) = 0;
00028
00030 virtual void RemoveConnection(sxConnection * con) = 0;
00032 virtual void AddConnection(sxConnection * con) = 0;
00034 virtual sxConnection * Connection(unsigned int idx = 0) const = 0;
00036 virtual bool IsConnectable(sxPort * p = 0) const = 0;
00037 protected:
00038 virtual bool SaveCustom(QDomElement & portNode);
00039 virtual bool LoadCustom(const QDomElement & portNode);
00040 virtual bool SaveGui(QDomElement & portNode);
00041 virtual bool LoadGui(const QDomElement & portNode);
00042
00043 public:
00044 enum Direction {
00045 Input = 0x01,
00046 Output = 0x02
00047 };
00048 sxComponent * Component() const;
00049 void SetComponent(sxComponent * comp);
00050 QString PortId() const;
00051 void UpdatePortId();
00052 bool IsOutput() const;
00053 bool IsInput() const;
00054 bool IsConnected() const;
00055 bool IsOpen() const;
00056 bool Save(QDomElement & portsNode);
00057 bool Load(const QDomElement & portNode);
00058
00059
00060 static sxPort * findPort(const QList<sxPort*> & portList, const QString & sid);
00061
00062 protected:
00063 sxPort(const QString& nm, sxComponent * comp, Direction dir);
00064 void SetPortId(const QString& str);
00065 void SetPortId(quintptr id);
00066
00067 private:
00068 class PrivateData;
00069
00070 PrivateData * d_p;
00071 SX_DISABLE_COPY(sxPort)
00072 };
00073
00077 class SX_SDKEXPORT sxInPort : public sxPort
00078 {
00079 public:
00080 virtual ~sxInPort();
00081
00082 sxInPort(const QString& cap = QString(), sxComponent * comp = 0);
00083
00084 void RemoveConnection(sxConnection * con);
00085 void AddConnection(sxConnection * con);
00086 sxConnection * Connection(unsigned int idx = 0) const;
00087 bool IsConnectable(sxPort * p = 0) const;
00088
00089 void Clear();
00090 bool Open();
00091 bool Close();
00092 void Write(sxPacket * packet);
00093 sxPacket * Read();
00094 sxPacket * ReadConfiguration();
00095 sxPacket * TryRead();
00096 size_t PendingPacketsCount() const;
00097 private:
00098 SX_DISABLE_COPY(sxInPort)
00099
00100 class PrivateData;
00101 PrivateData * d_p;
00102 };
00103
00107 class SX_SDKEXPORT sxOutPort : public sxPort
00108 {
00109 public:
00110 virtual ~sxOutPort();
00111
00112 sxOutPort(const QString& cap = QString(), sxComponent * comp = 0);
00113
00114 void RemoveConnection(sxConnection * con);
00115 void AddConnection(sxConnection * con);
00116 sxConnection * Connection(unsigned int idx = 0) const;
00117 bool IsConnectable(sxPort * p = 0) const;
00118 sx::DataType DataType() const;
00119 void SetDataType(sx::DataType type);
00120
00121 void Clear();
00122 bool Open();
00123 bool Close();
00124 void Write(sxPacket * packet);
00125 private:
00126 SX_DISABLE_COPY(sxOutPort)
00127
00128 class PrivateData;
00129 PrivateData * d_p;
00130
00131 bool SaveCustom(QDomElement & portNode);
00132 bool LoadCustom(const QDomElement & portNode);
00133 };
00134
00135 #endif // SXPORT_H_INCLUDED