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

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

UserLength = wcslen(wszUserName);

pcai = &cai;

}

}

if (action == ACTION_NONE)

return Usage();

HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);

if (FAILED(hr))

return hr;

// allow anonymous callbacks from chat server

hr = CoInitializeSecurity(0, -1, 0, 0,

RPC_C_AUTHN_LEVEL_NONE,

RPC_C_IMP_LEVEL_ANONYMOUS,

0, EOAC_NONE, 0);

if (SUCCEEDED(hr))

{

// grab the requested session manager

IChatSessionManager *pcsm = 0;

hr = CoGetClassObject(CLSID_ChatSession, CLSCTX_ALL,

pcsi, IID_IChatSessionManager,

(void**)&pcsm);

if (SUCCEEDED(hr))

{

// apply security blanket if desired

if (!bAnonymous)

hr = CoSetProxyBlanket(pcsm, RPC_C_AUTHN_WINNT,

RPC_C_AUTHZ_NONE, 0,

RPC_C_AUTHN_LEVEL_PKT,

RPC_C_IMP_LEVEL_IDENTIFY,

pcai, EOAC_NONE);

// dispatch request

switch (action)

{

case ACTION_CHAT:

Chat(wszSessionName, pcsm, pcai, bAnonymous);

break;

case ACTION_DELETE_SESSION:

Delete(wszSessionName, pcsm);

break;

case ACTION_LIST_SESSION_NAMES:

List(pcsm);

break;

default:

Usage();

}

// release session manager

pcsm->Release();

}

}

CoUninitialize();

return hr;

}

ChatSession.h



/////////////////////////////////////////////////////

//

// ChatSession.h

//

// Copyright 1997, Don Box/Addison Wesley

//

// This code accompanies the book "The Component

// Object Model" from Addison Wesley. Blah blah blah

//

//

#ifndef _CHATSESSION_H

#define _CHATSESSION_H

// this pragma shuts up the compiler warnings due to

// the pre MSC11SP1 debugger choking on long template names.

#pragma warning(disable:4786)

#define _WIN32_WINNT 0x403

#include

#include

#include

#include

using namespace std;

// bring in IDL-generated interface definitions

#include «..\include\COMChat.h»

// this class models a particular chat session

class ChatSession : public IChatSession

{

friend class StatementEnumerator;

LONG m_cRef;

CRITICAL_SECTION m_csStatementLock;

CRITICAL_SECTION m_csAdviseLock;

OLECHAR m_wszSessionName[1024];

bool m_bIsDeleted;

bool m_bAllowAnonymousAccess;

vector m_statements;

struct LISTENER

{

LISTENER *pPrev;

LISTENER *pNext;

OLECHAR *pwszUser;

IChatSessionEvents *pItf;

};

LISTENER *m_pHeadListeners;

void SLock(void);

void SUnlock(void);

void ALock(void);

void AUnlock(void);

bool CheckAccess(const OLECHAR *pwszUser);

protected:

virtual ~ChatSession(void);

void Fire_OnNewStatement(const OLECHAR *pwszUser,

const OLECHAR *pwszStatement);

void Fire_OnNewUser(const OLECHAR *pwszUser);

void Fire_OnUserLeft(const OLECHAR *pwszUser);

public:

ChatSession(const OLECHAR *pwszSessionName,

bool bAllowAnonymousAccess);

void Disconnect(void);

// IUnknown methods

STDMETHODIMP QueryInterface(REFIID riid, void **ppv);

STDMETHODIMP_(ULONG) AddRef(void);

STDMETHODIMP_(ULONG) Release(void);

// IChatSession methods

STDMETHODIMP get_SessionName(OLECHAR **ppwsz); <

|< Пред. 510 511 512 513 514 След. >|

Java книги

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