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

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



OLECHAR *GetCaller(void)

{

OLECHAR *pwsz = 0;

HRESULT hr = CoQueryClientBlanket(0,0,0,0,0,(void**)&pwsz,0);

if (SUCCEEDED(hr))

return OLESTRDUP(pwsz);

else

return OLESTRDUP(OLESTR(«anonymous»));

}

// class ChatSession ///////////////////////////////

ChatSession::ChatSession(const OLECHAR *pwszSessionName,

bool bAllowAnonymousAccess)

: m_cRef(0),

m_bAllowAnonymousAccess(bAllowAnonymousAccess),

m_pHeadListeners(0)

{

wcscpy(m_wszSessionName, pwszSessionName);

InitializeCriticalSection(&m_csStatementLock);

InitializeCriticalSection(&m_csAdviseLock);

}

ChatSession::~ChatSession(void)

{

DeleteCriticalSection(&m_csStatementLock);

DeleteCriticalSection(&m_csAdviseLock);

// tear down connected listeners

while (m_pHeadListeners)

{

LISTENER *pThisNode = m_pHeadListeners;

if (pThisNode->pItf)

pThisNode->pItf->Release();

if (pThisNode->pwszUser)

CoTaskMemFree(pThisNode->pwszUser);

m_pHeadListeners = pThisNode->pNext;

delete pThisNode;

}

}

// helper methods ///////////

void ChatSession::Disconnect(void)

{

CoDisconnectObject(this, 0);

// tear down connected listeners

ALock();

while (m_pHeadListeners)

{

LISTENER *pThisNode = m_pHeadListeners;

if (pThisNode->pItf)

pThisNode->pItf->Release();

if (pThisNode->pwszUser)

CoTaskMemFree(pThisNode->pwszUser);

m_pHeadListeners = pThisNode->pNext;

delete pThisNode;

}

AUnlock();

}

// send the OnNewStatement event to all listeners

void

ChatSession::Fire_OnNewStatement(const OLECHAR *pwszUser,

const OLECHAR *pwszStatement)

{

ALock();

for (LISTENER *pNode = m_pHeadListeners;

pNode != 0; pNode = pNode->pNext)

{

if (pNode->pItf)

pNode->pItf->OnNewStatement(pwszUser, pwszStatement);

}

AUnlock();

}

// send the OnNewUser event to all listeners

void

ChatSession::Fire_OnNewUser(const OLECHAR *pwszUser)

{

ALock();

for (LISTENER *pNode = m_pHeadListeners;

pNode != 0; pNode = pNode->pNext)

{

if (pNode->pItf)

pNode->pItf->OnNewUser(pwszUser);

}

AUnlock();

}

// send the OnUs

|< Пред. 513 514 515 516 517 След. >|

Java книги

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