Сущность технологии СОМ. Библиотека программиста   ::   Бокс Дональд

Страница: 519 из 528

c_str()))

{

m_cursor++;

cActual++;

}

else // allocation error, unwind

{

while (cActual > 0)

{

cActual–;

CoTaskMemFree(rgElems[cActual]);

rgElems[cActual] = 0;

}

break;

}

}

Unlock();

if (pcFetched)

*pcFetched = cActual;

return cElems == cActual ? S_OK : S_FALSE;

}

STDMETHODIMP

StatementEnumerator::Skip(ULONG cElems)

{

Lock();

ULONG cActual = 0;

while (cActual < cElems

&& m_cursor != m_pThis->m_statements.end())

{

m_cursor++;

cActual++;

}

Unlock();

return cElems == cActual ? S_OK : S_FALSE;

}

STDMETHODIMP

StatementEnumerator::Reset(void)

{

Lock();

m_cursor = m_pThis->m_statements.begin();

Unlock();

return S_OK;

}

STDMETHODIMP

StatementEnumerator::Clone(IEnumString **ppes)

{

if (ppes == 0)

return E_INVALIDARG;

if (*ppes = new StatementEnumerator(m_pThis))

return S_OK;

return E_OUTOFMEMORY;

}

// class ChatSessionClass /////////////////////

ChatSessionClass::ChatSessionClass(void)

: m_cStrongLocks(0)

{

InitializeCriticalSection(&m_csSessionLock);

}

ChatSessionClass::~ChatSessionClass(void)

{

DeleteCriticalSection(&m_csSessionLock);

}

void

ChatSessionClass::Lock(void)

{

EnterCriticalSection(&m_csSessionLock);

}

void

ChatSessionClass::Unlock(void)

{

LeaveCriticalSection(&m_csSessionLock);

}

// helper method to protect access to DeleteSession

// to only allow COMChat Admins to delete groups

bool

ChatSessionClass::CheckAccess(const OLECHAR *pwszUser)

{

if (wcscmp(pwszUser, L"anonymous") == 0)

return false;

TRUSTEEW trustee = {

0, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_NAME,

TRUSTEE_IS_USER, const_cast(pwszUser)

};

BOOL bIsAllowed;

HRESULT hr = g_pacAdmins->IsAccessAllowed(&trustee,0,

COM_RIGHTS_EXECUTE,

&bIsAllowed);

if (FAILED(hr))

bIsAllowed = false;

return SUCCEEDED(hr) && bIsAllowed != FALSE;

}

// IUnknown methods

STDMETHODIMP

ChatSessionClass::Query

|< Пред. 517 518 519 520 521 След. >|

Java книги

Контакты: [email protected]