00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _WG_MESSAGE_SERVER_H_
00026 #define _WG_MESSAGE_SERVER_H_
00027
00028
00029 #include "wgui_include_config.h"
00030 #include "wg_message.h"
00031 #include <deque>
00032 #include <map>
00033 #include "SDL.h"
00034 #include "SDL_thread.h"
00035
00036
00037 namespace wGui
00038 {
00039
00040 class CMessageClient;
00041
00043 struct s_MessageClientActive
00044 {
00048 s_MessageClientActive(CMessageClient* pC, bool bW) :
00049 pClient(pC), bWaitingForMessage(bW)
00050 { }
00051
00052 CMessageClient* pClient;
00053 bool bWaitingForMessage;
00054 };
00055
00057 typedef std::multimap<unsigned char, s_MessageClientActive, std::greater<unsigned char> > t_MessageClientPriorityMap;
00058
00060 typedef std::map<wGui::CMessage::EMessageType, t_MessageClientPriorityMap> t_MessageClientMap;
00061
00062
00064
00068
00069 class CMessageServer
00070 {
00071 protected:
00073 CMessageServer(void);
00074
00076 virtual ~CMessageServer(void);
00077
00078
00079 public:
00081 enum EClientPriority
00082 {
00083 PRIORITY_LAST = 0,
00084 PRIORITY_LOW = 50,
00085 PRIORITY_NORMAL = 100,
00086 PRIORITY_HIGH = 150,
00087 PRIORITY_FIRST = 255
00088 };
00089
00092 static CMessageServer& Instance(void);
00093
00098 void RegisterMessageClient(CMessageClient* pClient, CMessage::EMessageType eMessageType, unsigned char Priority = PRIORITY_NORMAL);
00099
00103 void DeregisterMessageClient(CMessageClient* pClient, CMessage::EMessageType eMessageType);
00104
00107 void DeregisterMessageClient(CMessageClient* pClient);
00108
00110 void DeliverMessage(void);
00111
00114 void QueueMessage(CMessage* pMessage);
00115
00118 bool MessageAvailable(void) { return m_MessageQueue.size() > 0; }
00119
00122 void IgnoreAllNewMessages(bool bIgnore) { m_bIgnoreAllNewMessages = bIgnore; }
00123
00124
00125 protected:
00126 static CMessageServer* m_pInstance;
00127 std::deque<CMessage*> m_MessageQueue;
00128 t_MessageClientMap m_MessageClients;
00129 SDL_sem* m_pSemaphore;
00130 bool m_bIgnoreAllNewMessages;
00131 };
00132
00133 }
00134
00135
00136 #include "unit_tests/wg_message_server_unittests.h"
00137
00138 #endif // _WG_MESSAGE_SERVER_H_
00139