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.

207 lines
3.8 KiB

  1. // SrvcCall.cpp
  2. // Code to implement the INmCallNotify interface for the remote control service
  3. #include "precomp.h"
  4. #include "srvcutil.h"
  5. #include "srvccall.h"
  6. CSrvcCall::CSrvcCall(INmCall * pNmCall) :
  7. m_pCall (pNmCall),
  8. m_pszName (NULL),
  9. m_pszAddr (NULL),
  10. m_addrType (NM_ADDR_UNKNOWN),
  11. m_fSelectedConference (FALSE),
  12. m_pos (NULL),
  13. m_cRef (1),
  14. m_dwCookie (0)
  15. {
  16. HRESULT hr;
  17. TRACE_OUT(("CSrvcCall: Created %08X (INmCall=%08X)", this, pNmCall));
  18. ASSERT(NULL != m_pCall);
  19. m_pCall->AddRef();
  20. // Get the display name
  21. BSTR bstr;
  22. hr = m_pCall->GetName(&bstr);
  23. if (SUCCEEDED(hr))
  24. {
  25. hr = BSTR_to_LPTSTR(&m_pszName, bstr);
  26. SysFreeString(bstr);
  27. }
  28. if (FEmptySz(m_pszName))
  29. {
  30. // Default to "another person" if no name available in the call data
  31. m_pszName = TEXT("Somebody");
  32. }
  33. hr = m_pCall->GetAddr(&bstr, &m_addrType);
  34. if (SUCCEEDED(hr))
  35. {
  36. hr = BSTR_to_LPTSTR(&m_pszAddr, bstr);
  37. SysFreeString(bstr);
  38. }
  39. // These should never change
  40. m_fIncoming = (m_pCall->IsIncoming() == S_OK);
  41. m_dwTick = ::GetTickCount();
  42. Update();
  43. NmAdvise(m_pCall, this, IID_INmCallNotify, &m_dwCookie);
  44. }
  45. VOID CSrvcCall::RemoveCall(void)
  46. {
  47. NmUnadvise(m_pCall, IID_INmCallNotify, m_dwCookie);
  48. }
  49. CSrvcCall::~CSrvcCall()
  50. {
  51. delete m_pszName;
  52. delete m_pszAddr;
  53. ASSERT(NULL != m_pCall);
  54. m_pCall->Release();
  55. }
  56. // IUnknown methods
  57. STDMETHODIMP_(ULONG) CSrvcCall::AddRef(void)
  58. {
  59. return ++m_cRef;
  60. }
  61. STDMETHODIMP_(ULONG) CSrvcCall::Release(void)
  62. {
  63. ASSERT(m_cRef > 0);
  64. if (m_cRef > 0)
  65. {
  66. m_cRef--;
  67. }
  68. ULONG cRef = m_cRef;
  69. if (0 == cRef)
  70. {
  71. delete this;
  72. }
  73. return cRef;
  74. }
  75. STDMETHODIMP CSrvcCall::QueryInterface(REFIID riid, PVOID *ppv)
  76. {
  77. HRESULT hr = S_OK;
  78. if ((riid == IID_INmCallNotify) || (riid == IID_IUnknown))
  79. {
  80. *ppv = (INmCallNotify *)this;
  81. // ApiDebugMsg(("CCall::QueryInterface()"));
  82. }
  83. else
  84. {
  85. hr = E_NOINTERFACE;
  86. *ppv = NULL;
  87. // ApiDebugMsg(("CCall::QueryInterface(): Called on unknown interface."));
  88. }
  89. if (S_OK == hr)
  90. {
  91. AddRef();
  92. }
  93. return hr;
  94. }
  95. // INmCallNotify methods
  96. STDMETHODIMP CSrvcCall::NmUI(CONFN uNotify)
  97. {
  98. return S_OK;
  99. }
  100. STDMETHODIMP CSrvcCall::StateChanged(NM_CALL_STATE uState)
  101. {
  102. // REVIEW: This check should be done outside of this routine
  103. if (uState == m_State)
  104. {
  105. // Don't bother the UI when nothing changes!
  106. return S_OK;
  107. }
  108. Update();
  109. return S_OK;
  110. }
  111. STDMETHODIMP CSrvcCall::Failed(ULONG uError)
  112. {
  113. return S_OK;
  114. }
  115. STDMETHODIMP CSrvcCall::Accepted(INmConference *pConference)
  116. {
  117. return S_OK;
  118. }
  119. // INmCallNotify3 methods
  120. STDMETHODIMP CSrvcCall::CallError(UINT cns)
  121. {
  122. return S_OK;
  123. }
  124. STDMETHODIMP CSrvcCall::VersionConflict(HRESULT Status, BOOL *pfContinue)
  125. {
  126. return S_OK;
  127. }
  128. STDMETHODIMP CSrvcCall::RemoteConference(BOOL fMCU, BSTR *pwszConfNames, BSTR *pbstrConfToJoin)
  129. {
  130. return S_OK;
  131. }
  132. STDMETHODIMP CSrvcCall::RemotePassword(BSTR bstrConference, BSTR *pbstrPassword, BYTE *pb, DWORD cb, BOOL fIsService)
  133. {
  134. return S_OK;
  135. }
  136. /* U P D A T E */
  137. /*-------------------------------------------------------------------------
  138. %%Function: Update
  139. Update the cached information about the call
  140. -------------------------------------------------------------------------*/
  141. VOID CSrvcCall::Update(void)
  142. {
  143. m_pCall->GetState(&m_State);
  144. // TRACE_OUT(("CCall: New State=%0d for call=%08X", m_State, this));
  145. switch (m_State)
  146. {
  147. case NM_CALL_ACCEPTED:
  148. case NM_CALL_REJECTED:
  149. case NM_CALL_CANCELED:
  150. RemoveCall();
  151. Release();
  152. break;
  153. case NM_CALL_RING:
  154. m_pCall->Accept();
  155. break;
  156. default:
  157. ERROR_OUT(("CCall::Update: Unknown state %08X", m_State));
  158. case NM_CALL_INVALID:
  159. case NM_CALL_INIT:
  160. case NM_CALL_SEARCH:
  161. case NM_CALL_WAIT:
  162. break;
  163. }
  164. }