wg_message_server.h

00001 // wg_message_server.h
00002 //
00003 // CMessageServer interface
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 

Generated on Wed May 16 23:11:26 2007 for wGui by  doxygen 1.5.1