// Session.cpp: implementation of the CSession class. // ////////////////////////////////////////////////////////////////////// #include "Session.h" #include "Repository.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// extern CRepository g_DataCache; CSession::CSession() { m_Ref = 1; m_pISessionCache = NULL; g_DataCache.GetDBSession(IID_IOpenRowset, (void**)&m_pISessionCache); } CSession::CSession(CSession& Session) { m_Ref = 1; m_pISessionCache = Session.m_pISessionCache; if ( NULL != m_pISessionCache ){ m_pISessionCache->AddRef(); } } CSession::~CSession() { if ( NULL != m_pISessionCache ) m_pISessionCache->Release(); } CSession& CSession::operator=(CSession& Session) { //release previous allocated memory if ( NULL != m_pISessionCache ) m_pISessionCache->Release(); //copy Session m_pISessionCache = Session.m_pISessionCache; if ( NULL != m_pISessionCache ){ m_pISessionCache->AddRef(); } return *this; } STDMETHODIMP_(ULONG) CSession::AddRef(void) { return InterlockedIncrement(&m_Ref); } STDMETHODIMP_(ULONG) CSession::Release(void) { if ( 0 >= InterlockedDecrement(&m_Ref) ) delete this; return m_Ref; } STDMETHODIMP CSession::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppv) { if ( riid == IID_IUnknown || riid == IID_IOpenRowset ) *ppv = static_cast(this); /****** else if ( riid == IID_IRowsetInfo ) *ppv = static_cast(this); else if ( riid == IID_IRowsetUpdate ) *ppv = static_cast(this); else if ( riid == IID_IRowsetChange ) *ppv = static_cast(this); else if ( riid == IID_IRowsetIdentity ) *ppv = static_cast(this); else if ( riid == IID_IRowsetLocate ) *ppv = static_cast(this); else if ( riid == IID_IRowsetResynch ) *ppv = static_cast(this); else if ( riid == IID_IRowsetScroll ) *ppv = static_cast(this); else if ( riid == IID_IAccessor ) *ppv = static_cast(this); else if ( riid == IID_IColumnsInfo ) *ppv = static_cast(this); else if ( riid == IID_IColumnsRowset ) *ppv = static_cast(this); else if ( riid == IID_IConvertType ) *ppv = static_cast(this); // else if ( riid == IID_IConnecttionPointContainer ) // *ppv = static_cast(this); else if ( riid == IID_ISupportErrorInfo ) *ppv = static_cast(this); //add all exposed interfaces here else { *ppv = NULL; return E_NOINTERFACE; } *******/ return S_OK; } STDMETHODIMP CSession::GetCacheSession(REFIID riid, void __RPC_FAR *__RPC_FAR *pISession) { if ( NULL != m_pISessionCache ) return E_UNEXPECTED; return m_pISessionCache->QueryInterface(riid, pISession); }