74 lines
1.2 KiB
C++
74 lines
1.2 KiB
C++
#include "StdAfx.h"
|
|
#include "TempUser.h"
|
|
#include "User.h"
|
|
#include "UserSessionfactory.h"
|
|
|
|
|
|
UserSessionFactory::UserSessionFactory(void)
|
|
{
|
|
m_pTempUserPool = new util::CMemoryPoolFactory<TempUser>;
|
|
m_pUserPool = new util::CMemoryPoolFactory<User>;
|
|
}
|
|
|
|
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 );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|