Source code of Windows XP (NT5)
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.

272 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. CallHub.h
  5. Abstract:
  6. Declaration of the CCallHub Class
  7. Author:
  8. mquinton 11-21-97
  9. Notes:
  10. Revision History:
  11. --*/
  12. #ifndef __CALLHUB_H_
  13. #define __CALLHUB_H_
  14. #include "resource.h" // main symbols
  15. #include "tapiobj.h"
  16. extern CHashTable * gpCallHubHashTable;
  17. // loword of flags is type
  18. //
  19. // careful because even though it's a bitfield
  20. // only one of these should be selected
  21. //
  22. #define CALLHUBTYPE_CALLHUB 0x00000002
  23. #define CALLHUBTYPE_NONE 0x00000004
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CCallHub
  26. class CCallHub :
  27. public CTAPIComObjectRoot<CCallHub>,
  28. public CComDualImpl<ITCallHub, &IID_ITCallHub, &LIBID_TAPI3Lib>,
  29. public CObjectSafeImpl
  30. {
  31. public:
  32. CCallHub(): m_hCallHub(NULL),
  33. m_pTAPI(NULL),
  34. m_pRootCall(NULL),
  35. m_pConferenceControllerCall(NULL),
  36. m_dwFlags(0),
  37. m_pPrivate(NULL),
  38. m_pAddress(NULL),
  39. m_bReleased(FALSE)
  40. {}
  41. DECLARE_DEBUG_ADDREF_RELEASE(CCallHub)
  42. DECLARE_QI()
  43. DECLARE_MARSHALQI(CCallHub)
  44. DECLARE_TRACELOG_CLASS(CCallHub)
  45. BEGIN_COM_MAP(CCallHub)
  46. COM_INTERFACE_ENTRY2(IDispatch, ITCallHub)
  47. COM_INTERFACE_ENTRY(ITCallHub)
  48. COM_INTERFACE_ENTRY(IObjectSafety)
  49. COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_pPrivate)
  50. COM_INTERFACE_ENTRY_FUNC(IID_IMarshal, 0, IMarshalQI)
  51. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pFTM)
  52. END_COM_MAP()
  53. BOOL ExternalFinalRelease();
  54. protected:
  55. HCALLHUB m_hCallHub;
  56. CallInfoArrayNR m_CallArray;
  57. CTAPI * m_pTAPI;
  58. CALLHUB_STATE m_State;
  59. CCall * m_pRootCall;
  60. CCall * m_pConferenceControllerCall;
  61. DWORD m_dwFlags;
  62. IUnknown * m_pPrivate;
  63. CAddress * m_pAddress;
  64. #if DBG
  65. PWSTR m_pDebug;
  66. #endif
  67. BOOL m_bReleased;
  68. public:
  69. HRESULT Initialize(
  70. CTAPI * pTapi,
  71. HCALLHUB hCallHub,
  72. DWORD dwFlags
  73. );
  74. CCall * GetRootCall(){ return m_pRootCall; }
  75. void RemoveCall(CCall * pCall);
  76. void AddCall(CCall * pCall);
  77. HRESULT FindExistingTapisrvCallhubCalls();
  78. HRESULT FindCallsDisconnected( BOOL * fAllCallsDisconnected );
  79. static HRESULT CreateTapisrvCallHub(
  80. CTAPI * pTAPI,
  81. HCALLHUB hCallHub,
  82. CCallHub ** ppCallHub
  83. );
  84. static HRESULT CreateFakeCallHub(
  85. CTAPI * pTAPI,
  86. CCall * pCall,
  87. CCallHub ** ppCallHub
  88. );
  89. HRESULT Initialize(CTAPI * pTAPI, HCALLHUB hCallHub, CCall * pCall);
  90. CCall * FindCallByHandle(HCALL hCall);
  91. void SetState( CALLHUB_STATE chs );
  92. void CheckForIdle();
  93. CTAPI * GetTapi(){ return m_pTAPI;}
  94. HCALLHUB GetCallHub(){ return m_hCallHub;}
  95. void ClearCallHub();
  96. HRESULT CreateConferenceControllerCall(HCALL hCall, CAddress * pAddress );
  97. CCall * GetConferenceControllerCall();
  98. // itcallhub
  99. STDMETHOD(Clear)();
  100. STDMETHOD(EnumerateCalls)(IEnumCall ** ppEnumCall);
  101. STDMETHOD(get_Calls)(VARIANT * pCalls);
  102. STDMETHOD(get_NumCalls)(long * plCalls);
  103. STDMETHOD(get_State)(CALLHUB_STATE * pState);
  104. STDMETHOD_(ULONG, InternalAddRef)()
  105. {
  106. DWORD dwR;
  107. dwR = InterlockedIncrement(&m_dwRef);;
  108. #if DBG
  109. LogDebugAddRef(m_dwRef);
  110. #endif
  111. return dwR;
  112. }
  113. STDMETHOD_(ULONG, InternalRelease)()
  114. {
  115. DWORD dwR;
  116. LOG((TL_INFO, "InternalRelease - m_dwRef %d",m_dwRef ));
  117. Lock();
  118. gpCallHubHashTable->Lock();
  119. dwR = InterlockedDecrement(&m_dwRef);
  120. // if ref count is 1 (means we entered function with 2) then we final release
  121. if (1 == dwR)
  122. {
  123. // make sure we only call ExternalFinalRelease & delete once
  124. if(m_bReleased == FALSE)
  125. {
  126. m_bReleased = TRUE;
  127. LOG((TL_TRACE, "InternalRelease - final" ));
  128. // remove from the hash table, so any more messages
  129. // from tapisrv are ignored
  130. if ( NULL != m_hCallHub )
  131. {
  132. gpCallHubHashTable->Remove( (ULONG_PTR)m_hCallHub );
  133. }
  134. gpCallHubHashTable->Unlock();
  135. ExternalFinalRelease();
  136. dwR = m_dwRef = 0;
  137. Unlock();
  138. LOG((TL_INFO, "InternalRelease - final OK dwR %d",dwR ));
  139. LOG((TL_TRACE, "InternalRelease - final OK dwR %d",dwR ));
  140. }
  141. else
  142. {
  143. gpCallHubHashTable->Unlock();
  144. Unlock();
  145. LOG((TL_INFO, "InternalRelease - final failed dwR %d",dwR ));
  146. }
  147. }
  148. else
  149. {
  150. gpCallHubHashTable->Unlock();
  151. Unlock();
  152. LOG((TL_INFO, "InternalRelease - not final dwR %d",dwR ));
  153. }
  154. #if DBG
  155. LogDebugRelease( dwR );
  156. #endif
  157. return dwR;
  158. }
  159. };
  160. class CCallHubEvent :
  161. public CTAPIComObjectRoot<CCallHubEvent, CComMultiThreadModelNoCS>, // no need for a cs
  162. public CComDualImpl<ITCallHubEvent, &IID_ITCallHubEvent, &LIBID_TAPI3Lib>,
  163. public CObjectSafeImpl
  164. {
  165. public:
  166. CCallHubEvent(){}
  167. DECLARE_MARSHALQI(CCallHubEvent)
  168. DECLARE_TRACELOG_CLASS(CCallHubEvent)
  169. BEGIN_COM_MAP(CCallHubEvent)
  170. COM_INTERFACE_ENTRY2(IDispatch, ITCallHubEvent)
  171. COM_INTERFACE_ENTRY(ITCallHubEvent)
  172. COM_INTERFACE_ENTRY(IObjectSafety)
  173. COM_INTERFACE_ENTRY_FUNC(IID_IMarshal, 0, IMarshalQI)
  174. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pFTM)
  175. END_COM_MAP()
  176. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) = 0;
  177. virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
  178. virtual ULONG STDMETHODCALLTYPE Release() = 0;
  179. static HRESULT FireEvent(
  180. CALLHUB_EVENT Event,
  181. ITCallHub * pCallHub,
  182. ITCallInfo * pCallInfo,
  183. CTAPI * pTapi
  184. );
  185. void FinalRelease();
  186. protected:
  187. CALLHUB_EVENT m_Event;
  188. ITCallHub * m_pCallHub;
  189. ITCallInfo * m_pCall;
  190. #if DBG
  191. PWSTR m_pDebug;
  192. #endif
  193. public:
  194. STDMETHOD(get_Event)(CALLHUB_EVENT * pEvent);
  195. STDMETHOD(get_CallHub)(ITCallHub ** ppCallHub);
  196. STDMETHOD(get_Call)(ITCallInfo ** ppCall);
  197. };
  198. #endif