Files
Sun1602/Tools/SunUpdateManager/SunUpdateServer/ServerSessionFactory.cpp
T
2022-10-26 12:25:11 +08:00

87 lines
1.9 KiB
C++

#include "StdAfx.h"
#include "TempServerSession.h"
#include "AgentServerSession.h"
#include "MasterServerSession.h"
#include "ServerSessionFactory.h"
ServerSessionFactory::ServerSessionFactory(void)
{
m_pTempServerPool = new CMemoryPoolFactory<TempServerSession>;
m_pAgentServerPool = new CMemoryPoolFactory<AgentServerSession>;
m_pMasterServerPool = new CMemoryPoolFactory<MasterServerSession>;
}
ServerSessionFactory::~ServerSessionFactory(void)
{
SAFE_DELETE( m_pTempServerPool );
SAFE_DELETE( m_pAgentServerPool );
SAFE_DELETE( m_pMasterServerPool );
}
VOID ServerSessionFactory::Init( int nSize )
{
m_pTempServerPool->Initialize( nSize, nSize/2 );
m_pAgentServerPool->Initialize( nSize, nSize/2 );
m_pMasterServerPool->Initialize( nSize, nSize/2 );
}
ServerSession* ServerSessionFactory::AllocServerSession( eUPDATE_SERVER_TYPE eServerType )
{
ServerSession *pServerSession = NULL;
switch( eServerType )
{
case UPDATE_TEMP:
pServerSession = m_pTempServerPool->Alloc();
break;
case UPDATE_AGENT:
pServerSession = m_pAgentServerPool->Alloc();
break;
case UPDATE_MASTER:
pServerSession = m_pMasterServerPool->Alloc();
break;
default:
DISPMSG( "[ServerSessionFactory::AllocServerSession] 잘못된 서버 타입[%d]이다.\n", eServerType );
return NULL;
}
return pServerSession;
}
BOOL ServerSessionFactory::FreeServerSession( ServerSession *pServerSession )
{
if( !pServerSession ) return FALSE;
switch( pServerSession->GetServerType() )
{
case UPDATE_TEMP:
return m_pTempServerPool->Free( (TempServerSession *)pServerSession );
case UPDATE_AGENT:
return m_pAgentServerPool->Free( (AgentServerSession *)pServerSession );
case UPDATE_MASTER:
return m_pMasterServerPool->Free( (MasterServerSession *)pServerSession );
default:
{
DISPMSG( "[ServerSessionFactory::FreeServerSession] 잘못된 타입의 서버세션을 Free할 수 없다\n" );
}
}
return FALSE;
}