⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wg_message_server.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_message_server.cpp//// CMessageServer class implementation////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui_include_config.h"#include "wg_message_server.h"#include "std_ex.h"#include "wg_message_client.h"#include "wg_error.h"#include "wg_debug.h"namespace wGui{CMessageServer* CMessageServer::m_pInstance = 0;CMessageServer::CMessageServer(void){	m_pSemaphore = SDL_CreateSemaphore(0);}CMessageServer::~CMessageServer(void){}CMessageServer& CMessageServer::Instance(void){	if (!m_pInstance)	{		m_pInstance = new CMessageServer;		if (!m_pInstance)		{			throw(Wg_Ex_App("CMessageServer::Instance : Unable to instantiate Message Server!"));		}	}	return *m_pInstance;}void CMessageServer::RegisterMessageClient(CMessageClient* pClient, CMessage::EMessageType eMessageType, unsigned char Priority){	m_MessageClients[eMessageType].insert(std::make_pair(Priority, std::make_pair(pClient, false)));}void CMessageServer::DeregisterMessageClient(CMessageClient* pClient, CMessage::EMessageType eMessageType){	t_MessageClientPriorityMap& PriorityMap = m_MessageClients[eMessageType];	t_MessageClientPriorityMap::iterator iter = PriorityMap.begin();	while (iter != PriorityMap.end())	{		if (iter->second.first == pClient)		{			PriorityMap.erase(iter);			iter = PriorityMap.begin();		}		else		{			++iter;		}	}}void CMessageServer::DeregisterMessageClient(CMessageClient* pClient){	for (t_MessageClientMap::iterator iter = m_MessageClients.begin(); iter != m_MessageClients.end(); ++iter)	{		t_MessageClientPriorityMap::iterator iter2 = iter->second.begin();		while (iter2 != iter->second.end())		{			if (iter2->second.first == pClient)			{				iter->second.erase(iter2);				iter2 = iter->second.begin();			}			else			{				++iter2;			}		}	}}void CMessageServer::DeliverMessage(void){	if (m_MessageQueue.size() > 0)	{		CMessage* pMessage = m_MessageQueue.front();		t_MessageClientPriorityMap& PriorityMap = m_MessageClients[pMessage->MessageType()];		for (t_MessageClientPriorityMap::iterator iter = PriorityMap.begin(); iter != PriorityMap.end(); ++iter)		{			iter->second.second = true;		}		bool bFinished = false;		while (! bFinished)		{			t_MessageClientPriorityMap::iterator iter = PriorityMap.begin();			for (; iter != PriorityMap.end(); ++iter)			{				if (iter->second.second)				{				iter->second.second = false;				bFinished = iter->second.first->HandleMessage(pMessage);				break;				}			}			if (iter == PriorityMap.end())			{				bFinished = true;			}		}		m_MessageQueue.pop_front();		delete pMessage;	}}void CMessageServer::QueueMessage(CMessage* pMessage){	m_MessageQueue.push_back(pMessage);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -