Pol  Revision:3cfda13
packetinterface.h
Go to the documentation of this file.
1 #ifndef __PACKETINTERFACE_H
2 #define __PACKETINTERFACE_H
3 
4 #include "../../clib/rawtypes.h"
5 #include <boost/noncopyable.hpp>
6 #include <map>
7 #include <queue>
8 
9 namespace Pol
10 {
11 namespace Network
12 {
13 // interface for packets
15 {
16 public:
17  PacketInterface() : offset( 0 ){};
18  virtual ~PacketInterface(){};
19  u16 offset;
20  virtual void ReSetBuffer(){};
21  virtual char* getBuffer() { return NULL; };
22  virtual inline u8 getID() const { return 0; };
23  virtual inline u16 getSize() const { return 0; };
24  virtual inline u16 getSubID() const { return 0; };
25  virtual size_t estimateSize() const { return 0; }
26 };
27 
28 typedef std::queue<PacketInterface*> PacketInterfaceQueue;
29 typedef std::map<u16, PacketInterfaceQueue> PacketInterfaceQueueMap;
30 typedef std::pair<u16, PacketInterfaceQueue> PacketInterfaceQueuePair;
31 
32 // interface for the two different types of packetqueues ("normal" packets
33 // and packets with subs)
35 {
36 public:
38  virtual ~PacketQueue(){};
39 
40 public:
41  virtual PacketInterface* GetNext( u8 id, u16 sub = 0 )
42  {
43  (void)id;
44  (void)sub; /* unused variables */
45 
46  return NULL;
47  };
48  virtual void Add( PacketInterface* pkt ) { (void)pkt; /*do nothing*/ };
49  virtual size_t Count() const { return 0; };
50  virtual bool HasSubs() const { return false; };
51  virtual PacketInterfaceQueueMap* GetSubs() { return NULL; };
52  virtual size_t estimateSize() const = 0;
53 };
54 
55 
56 typedef std::pair<u8, PacketQueue*> PacketQueuePair;
57 typedef std::map<u8, PacketQueue*> PacketQueueMap;
58 
59 // singleton "holder" of packets !EntryPoint!
60 class PacketsSingleton : boost::noncopyable
61 {
62 public:
65 
66 private:
67  PacketQueueMap packets;
68 
69 public:
70  PacketInterface* getPacket( u8 id, u16 sub = 0 );
71  void ReAddPacket( PacketInterface* pkt );
72  PacketQueueMap* getPackets() { return &packets; };
73  size_t estimateSize() const;
74 };
75 }
76 }
77 #endif
unsigned char u8
Definition: rawtypes.h:25
std::queue< PacketInterface * > PacketInterfaceQueue
std::map< u8, PacketQueue * > PacketQueueMap
virtual void Add(PacketInterface *pkt)
virtual PacketInterfaceQueueMap * GetSubs()
std::map< u16, PacketInterfaceQueue > PacketInterfaceQueueMap
unsigned short u16
Definition: rawtypes.h:26
virtual bool HasSubs() const
void ReAddPacket(PacketInterface *msg)
Definition: packethelper.h:25
std::pair< u16, PacketInterfaceQueue > PacketInterfaceQueuePair
virtual u16 getSubID() const
virtual size_t estimateSize() const
virtual size_t Count() const
virtual u16 getSize() const
virtual PacketInterface * GetNext(u8 id, u16 sub=0)
std::pair< u8, PacketQueue * > PacketQueuePair
Definition: berror.cpp:12