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.

114 lines
4.5 KiB

  1. //==========================================================================;
  2. //
  3. // bcasteventimpl.h : additional infrastructure to support implementing IMSVidGraphSegment for
  4. // playback segments
  5. // nicely from c++
  6. // Copyright (c) Microsoft Corporation 1999.
  7. //
  8. /////////////////////////////////////////////////////////////////////////////
  9. #pragma once
  10. #ifndef BCASTEVENTIMPL_H
  11. #define BCASTEVENTIMPL_H
  12. namespace MSVideoControl {
  13. template<class T>
  14. class DECLSPEC_NOVTABLE IBroadcastEventImpl : public IBroadcastEvent {
  15. protected:
  16. PQBroadcastEvent m_pBcast;
  17. DWORD m_dwEventCookie;
  18. public:
  19. IBroadcastEventImpl<T>() : m_dwEventCookie(0) {}
  20. virtual ~IBroadcastEventImpl<T>() {}
  21. HRESULT RegisterService() {
  22. T* pT = static_cast<T*>(this);
  23. if (!pT->m_pGraph) {
  24. return E_UNEXPECTED;
  25. }
  26. if (!m_pBcast) {
  27. PQServiceProvider sp(pT->m_pGraph);
  28. if (!sp) {
  29. TRACELM(TRACE_ERROR, "BroadcastEventImpl::RegisterService() can't get service provider i/f");
  30. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  31. }
  32. HRESULT hr = sp->QueryService(SID_SBroadcastEventService, IID_IBroadcastEvent, reinterpret_cast<LPVOID*>(&m_pBcast));
  33. if (FAILED(hr) || !m_pBcast) {
  34. hr = m_pBcast.CoCreateInstance(CLSID_BroadcastEventService, 0, CLSCTX_INPROC_SERVER);
  35. if (FAILED(hr)) {
  36. TRACELM(TRACE_ERROR, "BroadcastEventImpl::RegisterService() can't create bcast service");
  37. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  38. }
  39. PQRegisterServiceProvider rsp(pT->m_pGraph);
  40. if (!sp) {
  41. TRACELM(TRACE_ERROR, "BroadcastEventImpl::RegisterService() can't get get register service provider i/f");
  42. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  43. }
  44. hr = rsp->RegisterService(SID_SBroadcastEventService, m_pBcast);
  45. if (FAILED(hr)) {
  46. TRACELSM(TRACE_ERROR, (dbgDump << "BroadcastEventImpl::RegisterService() can't get register service provider. hr = " << hexdump(hr)), "");
  47. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  48. }
  49. }
  50. }
  51. return NOERROR;
  52. }
  53. HRESULT BroadcastFire(GUID2& eventid) {
  54. HRESULT hr = RegisterService();
  55. if (FAILED(hr)) {
  56. return hr;
  57. }
  58. ASSERT(m_pBcast);
  59. return m_pBcast->Fire(eventid);
  60. }
  61. HRESULT BroadcastAdvise() {
  62. HRESULT hr = RegisterService();
  63. if (FAILED(hr)) {
  64. return hr;
  65. }
  66. ASSERT(m_pBcast);
  67. PQConnectionPoint cp(m_pBcast);
  68. if (!cp) {
  69. TRACELSM(TRACE_ERROR, (dbgDump << "BroadcastEventImpl::Advise() can't QI event notification for connection point i/f. hr = " << hexdump(hr)), "");
  70. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  71. }
  72. hr = cp->Advise(static_cast<IBroadcastEvent*>(this) /* IBroadcastEvent implementing event receiving object*/, &m_dwEventCookie);
  73. if (FAILED(hr)) {
  74. TRACELSM(TRACE_ERROR, (dbgDump << "BroadcastEventImpl::Advise() can't advise event notification. hr = " << hexdump(hr)), "");
  75. return ImplReportError(__uuidof(T), IDS_CANT_NOTIFY_CHANNEL_CHANGE, __uuidof(IBroadcastEvent), E_UNEXPECTED);
  76. }
  77. return NOERROR;
  78. }
  79. HRESULT BroadcastUnadvise() {
  80. if (m_pBcast && m_dwEventCookie) {
  81. PQConnectionPoint cp(m_pBcast);
  82. if (cp) {
  83. HRESULT hr = cp->Unadvise(m_dwEventCookie);
  84. if (FAILED(hr)) {
  85. TRACELSM(TRACE_ERROR, (dbgDump << "BroadcastEventImpl::Unadvise() can't unadvise event notification. hr = " << hexdump(hr)), "");
  86. }
  87. } else {
  88. TRACELM(TRACE_ERROR, "CMSVidBDATuner::Unload() can't QI event notification for connection point i/f.");
  89. }
  90. m_pBcast.Release();
  91. m_dwEventCookie = 0;
  92. }
  93. ASSERT(!m_pBcast && !m_dwEventCookie);
  94. return NOERROR;
  95. }
  96. };
  97. }; // namespace
  98. #endif
  99. // end of file - bcasteventimpl.h