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.

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