Ejemplo n.º 1
0
STDMETHODIMP CHostProxy::CreateSession(ISession **ppSession)
{
	HRESULT	hRes = S_OK;
 	
	ObjectLock lock(this);

    if ( !m_dwHostCoreCookie )
	{
		if(m_bIsStopManually && g_ServiceMonitor.GetTransportStatus() != SERVICE_RUNNING)
		    return Error(L"Transport service stopped.", IID_IHostProxy, E_FAIL);
		else
		{
			Unlock();
			hRes = _AttachToTransport();
			Lock();
			if(FAILED(hRes))
				return hRes;
		}

	}

	if(!m_dwHostCoreCookie)
	    return Error(L"Can't access Transport service.", IID_IHostProxy, E_FAIL);

	CComObject<CSessionProxy>* pSessionPrx;
	hRes = CComObject<CSessionProxy>::CreateInstance(&pSessionPrx);

	if(FAILED(hRes))
		return Error(L"Transport proxy internal error.", IID_IHostProxy, hRes);

	pSessionPrx->AddRef();
	pSessionPrx->SetHost(this);

	hRes = pSessionPrx->AttachToTransport();
	if(FAILED(hRes))
		return Error(L"Transport proxy internal error.", IID_IHostProxy, hRes);

	*ppSession = pSessionPrx;

	m_mapSessions.insert(CSessionMap::value_type(pSessionPrx,CSubjectsSet()));

	return hRes;

}