00001 #ifndef SXPACKET_H_INCLUDED
00002 #define SXPACKET_H_INCLUDED
00003
00004 #include "sxPacketHeader.h"
00005 #include "sxPacketContent.h"
00006
00010 class SX_SDKEXPORT sxPacket
00011 {
00012 public:
00013 virtual ~sxPacket();
00014 sxPacket();
00015 explicit sxPacket(sxPacketHeader * h);
00016 sxPacket(sxPacketContent * c, sxPacketHeader * h);
00017
00018 void Serialize(QDataStream & ds) const;
00019 void Deserialize(QDataStream & ds);
00020 bool Append(const sxPacket& packet);
00021 void Drop();
00022 void DropContent();
00023 void DropHeader();
00024 void SetContentType(sx::DataType type);
00025 sx::DataType ContentType() const;
00026 sxPacketContent * CreateContent(sx::DataType type, bool attach);
00027 static sxPacketContent * CreateContent(sx::DataType type);
00028 sxPacket * Clone() const;
00029
00030 sxPacketHeader * Header() const;
00031 void AttachHeader(sxPacketHeader * h);
00032 void DetachHeader();
00033 sxPacketContent * Content() const;
00034 void AttachContent(sxPacketContent * c);
00035 void DetachContent();
00036 void Detach();
00037 bool IsEmpty() const;
00038 bool HasContent() const;
00039 bool HasHeader() const;
00040 private:
00041 sxPacketHeader * xHeader;
00042 sxPacketContent * xContent;
00043 };
00044
00046 typedef sxPacket* sxPacketPtr;
00047
00048
00049 inline sxPacketHeader * sxPacket::Header() const
00050 {
00051 return xHeader;
00052 }
00053 inline void sxPacket::AttachHeader(sxPacketHeader * h)
00054 {
00055 xHeader = h;
00056 }
00057 inline void sxPacket::DetachHeader()
00058 {
00059 xHeader = 0;
00060 }
00061 inline sxPacketContent * sxPacket::Content() const
00062 {
00063 return xContent;
00064 }
00065 inline void sxPacket::AttachContent(sxPacketContent * c)
00066 {
00067 xContent = c;
00068 }
00069 inline void sxPacket::DetachContent()
00070 {
00071 xContent = 0;
00072 }
00073 inline void sxPacket::Detach()
00074 {
00075 xHeader = 0;
00076 xContent = 0;
00077 }
00078 inline bool sxPacket::IsEmpty() const
00079 {
00080 return (xHeader == 0 && xContent == 0);
00081 }
00082 inline bool sxPacket::HasContent() const
00083 {
00084 return (xContent != 0);
00085 }
00086 inline bool sxPacket::HasHeader() const
00087 {
00088 return (xHeader != 0);
00089 }
00090 #endif // SXPACKET_H_INCLUDED