Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
6.4 KiB

  1. /**********************************************************
  2. (C) 2001 Microsoft Corp.
  3. ***********************************************************/
  4. #include "stdafx.h"
  5. #include "mdisp.h"
  6. #include "mdispid.h"
  7. #include "rcbdyctl.h"
  8. #include "IMSession.h"
  9. #include "SessMgrEvnt.h"
  10. #include "utils.h"
  11. //****************************************************************************
  12. //
  13. // CSessionMgrEvent::CSessionMgrEvent()
  14. // Constructor
  15. //
  16. //****************************************************************************
  17. CSessionMgrEvent::CSessionMgrEvent(CIMSession *pIMSession)
  18. : m_dwCookie(0), m_iid(/*DIID_DMsgrSessionManagerEvents*/)
  19. {
  20. m_pIMSession = pIMSession;
  21. m_dwRefCount = 0;
  22. m_pCP = NULL;
  23. }
  24. CSessionMgrEvent::~CSessionMgrEvent()
  25. {
  26. }
  27. //
  28. // This method is used by CIMSession to release the Sink from the
  29. // ConnectionPoint (the CLSID_MsgrSessionManager object)
  30. //
  31. HRESULT CSessionMgrEvent::Unadvise()
  32. {
  33. HRESULT hr = S_OK;
  34. if (m_pCP)
  35. {
  36. if (m_dwCookie)
  37. m_pCP->Unadvise(m_dwCookie);
  38. m_pCP->Release();
  39. // Set the pointer to it's parent to NULL so that no calls are made to it
  40. m_pIMSession = NULL;
  41. }
  42. return hr;
  43. }
  44. //****************************************************************************
  45. //
  46. // STDMETHODIMP CSessionMgrEvent::QueryInterface( REFIID riid, void **ppv )
  47. //
  48. //
  49. //****************************************************************************
  50. STDMETHODIMP CSessionMgrEvent::QueryInterface( REFIID riid, void **ppv )
  51. {
  52. // Alway initialize out components to NULL
  53. *ppv = NULL;
  54. if( (IID_IUnknown == riid) || (m_iid == riid) || (IID_IDispatch == riid) )
  55. {
  56. *ppv = this;
  57. }
  58. if( NULL == *ppv )
  59. {
  60. return( E_NOINTERFACE );
  61. }
  62. else
  63. {
  64. ((IUnknown *)(*ppv))->AddRef();
  65. return( S_OK );
  66. }
  67. }
  68. //****************************************************************************
  69. //
  70. // STDMETHODIMP CSessionMgrEvent::GetTypeInfoCount(UINT* pcTypeInfo)
  71. //
  72. // should always return NOERROR
  73. //
  74. //****************************************************************************
  75. STDMETHODIMP CSessionMgrEvent::GetTypeInfoCount(UINT* pcTypeInfo)
  76. {
  77. *pcTypeInfo = 0 ;
  78. return NOERROR ;
  79. }
  80. //****************************************************************************
  81. //
  82. // STDMETHODIMP CSessionMgrEvent::GetTypeInfo(
  83. //
  84. // should always return E_NOTIMPL
  85. //
  86. //****************************************************************************
  87. STDMETHODIMP CSessionMgrEvent::GetTypeInfo(UINT iTypeInfo,
  88. LCID, // This object does not support localization.
  89. ITypeInfo** ppITypeInfo)
  90. {
  91. *ppITypeInfo = NULL ;
  92. if(iTypeInfo != 0)
  93. {
  94. return DISP_E_BADINDEX ;
  95. }
  96. else
  97. {
  98. return E_NOTIMPL;
  99. }
  100. }
  101. //****************************************************************************
  102. //
  103. // STDMETHODIMP CSessionMgrEvent::GetIDsOfNames(
  104. // const IID& iid,
  105. // OLECHAR** arrayNames,
  106. // UINT countNames,
  107. // LCID, // Localization is not supported.
  108. // DISPID* arrayDispIDs)
  109. //
  110. // should always return E_NOTIMPL
  111. //
  112. //****************************************************************************
  113. STDMETHODIMP CSessionMgrEvent::GetIDsOfNames(const IID& iid,
  114. OLECHAR** arrayNames,
  115. UINT countNames,
  116. LCID, // Localization is not supported.
  117. DISPID* arrayDispIDs)
  118. {
  119. HRESULT hr;
  120. if (iid != IID_NULL)
  121. {
  122. return DISP_E_UNKNOWNINTERFACE ;
  123. }
  124. hr = E_NOTIMPL;
  125. return hr ;
  126. }
  127. //****************************************************************************
  128. //
  129. // STDMETHODIMP CSessionMgrEvent::Invoke(
  130. //
  131. //
  132. //****************************************************************************
  133. STDMETHODIMP CSessionMgrEvent::Invoke(DISPID dispidMember,
  134. const IID& iid,
  135. LCID, // Localization is not supported.
  136. WORD wFlags,
  137. DISPPARAMS* pDispParams,
  138. VARIANT* pvarResult,
  139. EXCEPINFO* pExcepInfo,
  140. UINT* pArgErr)
  141. {
  142. HRESULT hr=E_FAIL;
  143. HRESULT hrRet=E_FAIL;
  144. _ASSERTE(iid == IID_NULL);
  145. switch (dispidMember)
  146. {
  147. case DISPID_ONINVITATION:
  148. case DISPID_ONAPPREGISTERED:
  149. case DISPID_ONAPPUNREGISTERED:
  150. break; // None of these are handled
  151. case DISPID_ONLOCKCHALLENGE:
  152. if (m_pIMSession)
  153. m_pIMSession->OnLockChallenge(V_BSTR(&pDispParams->rgvarg[0]), V_I4(&pDispParams->rgvarg[1]));
  154. break;
  155. case DISPID_ONLOCKRESULT:
  156. if (m_pIMSession)
  157. m_pIMSession->OnLockResult(V_BOOL(&pDispParams->rgvarg[0]), V_I4(&pDispParams->rgvarg[1]));
  158. break;
  159. case DISPID_ONLOCKENABLE:
  160. //OutMessageBox(_T("Lock is enabled"));
  161. break;
  162. case DISPID_ONAPPSHUTDOWN:
  163. if (m_pIMSession)
  164. m_pIMSession->DoSessionStatus(RA_IM_APPSHUTDOWN);
  165. break;
  166. default:
  167. OutMessageBox(_T("got unknown Event from COM object: %d\r\n"), dispidMember);
  168. break;
  169. }
  170. return NOERROR;
  171. }
  172. HRESULT CSessionMgrEvent::Advise(IConnectionPoint* pCP)
  173. {
  174. HRESULT hr = S_OK;
  175. if (!pCP)
  176. {
  177. hr = E_INVALIDARG;
  178. goto done;
  179. }
  180. if (m_pCP && m_dwCookie)
  181. {
  182. m_pCP->Unadvise(m_dwCookie);
  183. m_dwCookie = 0;
  184. m_pCP->Release();
  185. }
  186. m_pCP = pCP;
  187. m_pCP->AddRef();
  188. hr = m_pCP->Advise((IUnknown*)this, &m_dwCookie);
  189. if (FAILED_HR(_T("CSessionMgrEvent:Advise failed %s"), hr))
  190. goto done;
  191. done:
  192. return hr;
  193. }