Сущность технологии СОМ. Библиотека программиста :: Бокс Дональд
Страница:
521 из 528
end())
{
if (bDontCreate)
hr = E_FAIL;
else if (!bAllowAnonymousAccess
&& wcscmp(pwszUser, L"anonymous") == 0)
hr = E_ACCESSDENIED;
else
{
ChatSession *pNew =
new ChatSession(pwszSessionName,
bAllowAnonymousAccess != FALSE);
if (pNew)
{
pNew->AddRef();
m_sessions.insert(
pair
ChatSession*>(pwszSessionName,
pNew));
(*ppcs = pNew)->AddRef();
hr = S_OK;
}
else
hr = E_OUTOFMEMORY;
}
}
else
{
(*ppcs = (*it).second)->AddRef();
hr = S_OK;
}
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&
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;
pSessionClass->Lock();
for (iterator it = sessions.begin();
it != sessions.end();
it++)
{
m_pStrings->push_back((*it).first);
}
pSessionClass->Unlock();
m_cursor = Strings().
|< Пред. 519 520 521 522 523 След. >|