Files
2022-10-26 12:25:11 +08:00

98 lines
2.1 KiB
C++

#include "StdAfx.h"
#include ".\serversessionmanager.h"
#include <algorithm>
#include "ServerSession.h"
#ifdef _NA_006543_20130318_HEARTBEAT
#include "AgentServerSession.h"
#endif
ServerSessionManager::ServerSessionManager(void)
{
}
ServerSessionManager::~ServerSessionManager(void)
{
}
VOID ServerSessionManager::AddSession( ServerSession* pSession )
{
m_mapSession.insert( std::make_pair( pSession->GetSessionIndex(), pSession ) );
}
//메모리상의 해제는 팩토리에서 한다. 여기서는 요소의 삭제만 한다.
VOID ServerSessionManager::DelSession( DWORD dwSessionIndex )
{
SERVER_SESSION_MAP_ITER iter = m_mapSession.find( dwSessionIndex );
if( iter != m_mapSession.end() ) //존재
m_mapSession.erase( iter );
}
ServerSession* ServerSessionManager::Find( DWORD dwSessionIndex )
{
SERVER_SESSION_MAP_ITER iter = m_mapSession.find( dwSessionIndex );
if( iter != m_mapSession.end() ) //존재
{
ServerSession* pSession = iter->second;
if( pSession )
return pSession;
}
return NULL;
}
ServerSession* ServerSessionManager::FindAgentSession( DWORD dwAgentKey )
{
SERVER_SESSION_MAP_ITER iter;
for( iter = m_mapSession.begin(); iter != m_mapSession.end(); ++iter )
{
ServerSession* pSession = iter->second;
if( pSession )
{
if( pSession->GetServerKey() == dwAgentKey )
return pSession;
}
}
return NULL;
}
VOID ServerSessionManager::Release()
{
m_mapSession.clear();
}
ServerSession* ServerSessionManager::FindMasterSession()
{
SERVER_SESSION_MAP_ITER iter;
for( iter = m_mapSession.begin(); iter != m_mapSession.end(); ++iter )
{
ServerSession* pSession = iter->second;
if( pSession )
{
if( pSession->GetServerType() == UPDATE_MASTER )
return pSession;
}
}
return NULL;
}
#ifdef _NA_006543_20130318_HEARTBEAT
VOID ServerSessionManager::update( )
{
SERVER_SESSION_MAP_ITER iter = m_mapSession.begin();
for (; iter != m_mapSession.end(); ++iter)
{
ServerSession* const session = iter->second;
if (session && session->GetServerType() == UPDATE_AGENT )
static_cast<AgentServerSession*>(session)->update();
}
}
#endif