}

Unlock();

CoTaskMemFree(pwszUser);

return hr;

}

STDMETHODIMP

ChatSessionClass::DeleteSession(const OLECHAR *pwszSessionName)

{

if (pwszSessionName == 0)

return E_INVALIDARG;

HRESULT hr = E_FAIL;

OLECHAR *pwszUser = GetCaller();

if (CheckAccess(pwszUser))

{

Lock();

SESSIONMAP::iterator it

= m_sessions.find(pwszSessionName);

if (it == m_sessions.end())

{

hr = E_FAIL;

}

else

{

(*it).second->Disconnect();

(*it).second->Release();

m_sessions.erase(it);

hr = S_OK;

}

Unlock();

}

else

hr = E_ACCESSDENIED;

CoTaskMemFree(pwszUser);

return hr;

}

// class SessionNamesEnumerator

vector<wstring>&

SessionNamesEnumerator::Strings(void)

{

if (m_pStrings)

return *m_pStrings;

else

return *(m_pCloneSource->m_pStrings);

}

void

SessionNamesEnumerator::Lock(void)

{

EnterCriticalSection(&m_csLock);

}

void

SessionNamesEnumerator::Unlock(void)

{

LeaveCriticalSection(&m_csLock);

}

SessionNamesEnumerator::SessionNamesEnumerator(

ChatSessionClass *pSessionClass)

: m_cRef(0),

m_pStrings(0),

m_pCloneSource(0)

{

typedef ChatSessionClass::SESSIONMAP::iterator iterator;

ChatSessionClass::SESSIONMAP &sessions

= pSessionClass->m_sessions;

m_pStrings = new vector<wstring>;

pSessionClass->Lock();

for (iterator it = sessions.begin();

it != sessions.end();

it++)

{

m_pStrings->push_back((*it).first);

}

pSessionClass->Unlock();

m_cursor = Strings().begin();

InitializeCriticalSection(&m_csLock);

}

SessionNamesEnumerator::SessionNamesEnumerator(

SessionNamesEnumerator *pCloneSource)

: m_cRef(0),

m_pStrings(0),

m_pCloneSource(pCloneSource)

{

m_pCloneSource->AddRef();

m_cursor = Strings().begin();

InitializeCriticalSection(&m_csLock);

}

SessionNamesEnumerator::~SessionNamesEnumerator(void)

{

if (m_pCloneSource)

m_pCloneSource->Release();

else if (m_pStrings)

delete m_pStrings;

DeleteCriticalSection(&m_csLock);

}

// IUnknown methods

STDMETHODIMP

SessionNamesEnumerator::QueryInterface(REFIID riid, void **ppv)

{

if (riid == IID_IUnknown)

*ppv = static_cast<IEnumString*>(this);

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату