#include "StdAfx.h" #include "TempUser.h" #include "User.h" #include "UserSessionfactory.h" UserSessionFactory::UserSessionFactory(void) { m_pTempUserPool = new util::CMemoryPoolFactory; m_pUserPool = new util::CMemoryPoolFactory; } UserSessionFactory::~UserSessionFactory(void) { SAFE_DELETE(m_pTempUserPool); SAFE_DELETE(m_pUserPool); } VOID UserSessionFactory::Init( DWORD dwMaxUserCount ) { m_pTempUserPool->Initialize( dwMaxUserCount, dwMaxUserCount/2 ); m_pUserPool->Initialize( dwMaxUserCount, dwMaxUserCount/2 ); } VOID UserSessionFactory::Release() { m_pTempUserPool->Release(); m_pUserPool->Release(); } UserSession* UserSessionFactory::AllocUser( eUSER_TYPE type ) { UserSession *pUser = NULL; if( type == UT_TEMP_USER ) { pUser = m_pTempUserPool->Alloc(); } else if( type == UT_USER ) { pUser = m_pUserPool->Alloc(); } else return NULL; pUser->Init(); pUser->SetUserType( type ); return pUser; } VOID UserSessionFactory::FreeUser( UserSession *pUser ) { if( pUser->GetUserType() == UT_TEMP_USER ) { m_pTempUserPool->Free( (TempUser *)pUser ); } else if( pUser->GetUserType() == UT_USER ) { m_pUserPool->Free( (User *)pUser ); } }