base commit
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@12865 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
51
dev/SocketsBase/protocol_manager.cpp
Normal file
51
dev/SocketsBase/protocol_manager.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "protocol_manager.hpp"
|
||||
|
||||
#include "protocol.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
ProtocolManager::ProtocolManager() : ProtocolListener()
|
||||
{
|
||||
}
|
||||
|
||||
ProtocolManager::~ProtocolManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ProtocolManager::messageReceived(uint8_t* data)
|
||||
{
|
||||
assert(data);
|
||||
m_messagesToProcess.push_back(data);
|
||||
}
|
||||
|
||||
void ProtocolManager::runProtocol(Protocol* protocol)
|
||||
{
|
||||
m_protocols.push_back(protocol);
|
||||
protocol->setup();
|
||||
protocol->start();
|
||||
}
|
||||
void ProtocolManager::stopProtocol(Protocol* protocol)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ProtocolManager::update()
|
||||
{
|
||||
// before updating, notice protocols that they have received information
|
||||
int size = m_messagesToProcess.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
uint8_t* data = m_messagesToProcess.back();
|
||||
PROTOCOL_TYPE searchedProtocol = (PROTOCOL_TYPE)(data[0]);
|
||||
for (unsigned int i = 0; i < m_protocols.size() ; i++)
|
||||
{
|
||||
if (m_protocols[i]->getProtocolType() == searchedProtocol)
|
||||
m_protocols[i]->messageReceived(data+1);
|
||||
}
|
||||
m_messagesToProcess.pop_back();
|
||||
}
|
||||
// now update all protocols
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
m_protocols[i]->update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user