00001
00002 Copyright (c) 2001, Lee Patterson & Ant Works Software
00003 http://ssobjects.sourceforge.net
00004
00005 filename : packetmessageque.h
00006 author : Lee Patterson (lee@antws.com)
00007
00008 purpose : This que is used to hold incoming messages. Each message
00009 contains a pointer to the incoming packet, and a pointer to
00010 the socket that input came from. Output will normally be
00011 sent to this socket.
00012 *********************************************************************/
00013
00014 #ifndef PACKETMESSAGEQUE_H
00015 #define PACKETMESSAGEQUE_H
00016
00017 #include "mcl.h"
00018 #include "generalexception.h"
00019 #include "packetbuffer.h"
00020 #include "threadutils.h"
00021 #include "socketinstance.h"
00022 #include "linkedlist.h"
00023
00024 #define throwPacketMessageException(m) (throw PacketMessageException(m,__FILE__,__LINE__))
00025
00026
00027 namespace ssobjects
00028 {
00029
00033 class PacketMessageException : public GeneralException
00034 {
00035 public:
00036 PacketMessageException(char* pchMessage,const char* pFname,const int iLine)
00037 : GeneralException(pchMessage,pFname,iLine){};
00038 };
00039
00049 class PacketMessage
00050 {
00051 public:
00052 PacketMessage(SocketInstance* const s,PacketBuffer* const p);
00053 virtual ~PacketMessage();
00054
00055 public:
00056 PacketBuffer* packet() const
00057 {return m_pPacket;}
00058
00059 SocketInstance* socket() const
00060 {return m_pSocket;}
00061
00062 uint id() const
00063
00064 {return m_nID;}
00065
00066 private:
00067 static unsigned32 m_nUniqueID;
00068 static Lock m_lockID;
00069 unsigned32 uniqueID();
00070
00071 private:
00072 unsigned32 m_nID;
00073 bool m_bUsed;
00074 SocketInstance* m_pSocket;
00075 PacketBuffer* m_pPacket;
00076
00077 private:
00078
00079 PacketMessage(const PacketMessage&);
00080 PacketMessage& operator=(const PacketMessage&);
00081 };
00082
00083 #define throwPacketMessageQueException(m) (throw PacketMessageQueException(m,__FILE__,__LINE__))
00084
00088 class MsgQueException : public GeneralException
00089 {
00090 public:
00091 MsgQueException(char* pchMessage,const char* pFname,const int iLine)
00092 : GeneralException(pchMessage,pFname,iLine){};
00093 };
00094
00095
00120 class PacketMessageQue
00121 {
00122 private:
00123 bool m_bSetEvents;
00124 LinkedList<PacketMessage> m_listMsgs;
00125 Lock m_lock;
00126 Event m_event;
00127
00128 public:
00129 PacketMessageQue(bool bSetEvents=true);
00130 virtual ~PacketMessageQue();
00131
00132 public:
00133 void add(PacketMessage *);
00134 PacketMessage* get();
00135 bool isEmpty();
00136 void purge();
00137 #if 0
00138
00139 bool signal();
00140 bool reset();
00141 bool pulse();
00142 unsigned32 wait(uint nMilliseconds=INFINITE);
00143 #endif
00144 private:
00145
00146 PacketMessageQue(const PacketMessageQue&);
00147 PacketMessageQue& operator=(const PacketMessageQue&);
00148 };
00149
00150 };
00151 #endif