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.

97 lines
2.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // bcastevent.cpp : Implementation of CBroadcastEventService
  3. // Copyright (c) Microsoft Corporation 2001.
  4. #include "stdafx.h"
  5. #ifndef TUNING_MODEL_ONLY
  6. #include "bcastevent.h"
  7. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_BroadcastEventService, CBroadcastEventService)
  8. namespace BDATuningModel {
  9. bool CReflectionThread::GetNextEvent(GUID& g) {
  10. CAutoLock lock(&m_WorkerLock);
  11. if (!m_FiringQ.size()) {
  12. return false;
  13. }
  14. g = m_FiringQ.front();
  15. m_FiringQ.pop();
  16. return true;
  17. }
  18. void CReflectionThread::GetAdviseList(AdviseList& l) {
  19. CAutoLock lock(&m_WorkerLock);
  20. AdviseList::iterator i;
  21. for (i = m_AdviseList.begin(); i != m_AdviseList.end(); ++i) {
  22. l.push_back(*i);
  23. }
  24. ASSERT(m_AdviseList.size() == l.size());
  25. // TRACELSM(TRACE_DEBUG, (dbgDump << "CReflectionThread::GetAdviseList() m_al = " << m_AdviseList.size() << " l = " << l.size()), "");
  26. return;
  27. }
  28. HRESULT CReflectionThread::Fire(PQGIT& pGIT) {
  29. GUID g;
  30. AdviseList l;
  31. GetAdviseList(l);
  32. while (GetNextEvent(g)) {
  33. for (AdviseList::iterator i = l.begin(); i != l.end(); ++i) {
  34. PQBroadcastEvent e;
  35. HRESULT hr = pGIT->GetInterfaceFromGlobal(*i, IID_IBroadcastEvent, reinterpret_cast<LPVOID*>(&e));
  36. if (SUCCEEDED(hr) && e) {
  37. e->Fire(g);
  38. }
  39. }
  40. }
  41. return NOERROR;
  42. }
  43. HRESULT CReflectionThread::Advise(PUnknown& p, DWORD *pdwCookie) {
  44. if (!m_pGIT) {
  45. HRESULT hr = m_pGIT.CoCreateInstance(CLSID_StdGlobalInterfaceTable, 0, CLSCTX_INPROC_SERVER);
  46. if (FAILED(hr)) {
  47. TRACELSM(TRACE_ERROR, (dbgDump << "CReflectionThread::Advise() can't create GIT. hr = " << hr), "");
  48. return hr;
  49. }
  50. }
  51. ASSERT(m_pGIT);
  52. HRESULT hr = m_pGIT->RegisterInterfaceInGlobal(p, IID_IBroadcastEvent, pdwCookie);
  53. if (FAILED(hr)) {
  54. TRACELSM(TRACE_ERROR, (dbgDump << "CReflectionThread::Advise() can't register interface. hr = " << hr), "");
  55. return hr;
  56. }
  57. CAutoLock lock(&m_WorkerLock);
  58. m_AdviseList.push_back(*pdwCookie);
  59. return NOERROR;
  60. }
  61. HRESULT CReflectionThread::Unadvise(DWORD dwCookie) {
  62. if (!m_pGIT) {
  63. // if no GIT yet, then they can't have advised yet
  64. return E_INVALIDARG;
  65. }
  66. CAutoLock lock(&m_WorkerLock);
  67. AdviseList::iterator i = std::find(m_AdviseList.begin(), m_AdviseList.end(), dwCookie);
  68. if (i == m_AdviseList.end()) {
  69. return E_INVALIDARG;
  70. }
  71. m_AdviseList.erase(i);
  72. ASSERT(m_pGIT);
  73. HRESULT hr = m_pGIT->RevokeInterfaceFromGlobal(dwCookie);
  74. if (FAILED(hr)) {
  75. TRACELSM(TRACE_ERROR, (dbgDump << "CReflectionThread::Advise() can't register interface. hr = " << hr), "");
  76. return hr;
  77. }
  78. return NOERROR;
  79. }
  80. }; // namespace
  81. #endif //TUNING_MODEL_ONLY
  82. // end of file - tuningspacecontainer.cpp