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.

92 lines
2.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: R U N D O W N . H
  7. //
  8. // Contents: RPC rundown support
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 12 Nov 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "upsync.h"
  17. #include "ulist.h"
  18. class CRundownHelperBase
  19. {
  20. public:
  21. virtual ~CRundownHelperBase() {}
  22. // Called on RPC disconnect
  23. virtual void OnRundown() = 0;
  24. // Do we match a RPC context handle
  25. virtual BOOL IsMatch(void * pvItem) = 0;
  26. };
  27. template <class Type>
  28. class CRundownHelper : public CRundownHelperBase
  29. {
  30. public:
  31. CRundownHelper(Type * pType) : m_pType(pType) {}
  32. CRundownHelper(const CRundownHelper & ref) : m_pType(ref.m_pType) {}
  33. CRundownHelper & operator=(const CRundownHelper & ref)
  34. {
  35. if(this != &ref)
  36. {
  37. m_pType = ref.m_pType;
  38. }
  39. return *this;
  40. }
  41. void OnRundown()
  42. {
  43. // Type must have a static void Type::OnRundown(Type *) method
  44. Type::OnRundown(m_pType);
  45. }
  46. BOOL IsMatch(void * pvItem)
  47. {
  48. return m_pType == pvItem;
  49. }
  50. private:
  51. Type * m_pType;
  52. };
  53. class CSsdpRundownSupport
  54. {
  55. public:
  56. ~CSsdpRundownSupport();
  57. static CSsdpRundownSupport & Instance();
  58. template <class Type> HRESULT HrAddRundownItem(Type * pType)
  59. {
  60. HRESULT hr = S_OK;
  61. CRundownHelperBase * pBase = new CRundownHelper<Type>(pType);
  62. if(!pBase)
  63. {
  64. return E_OUTOFMEMORY;
  65. }
  66. return HrAddItemInternal(pBase);
  67. }
  68. void RemoveRundownItem(void * pvItem);
  69. void DoRundown(void * pvItem);
  70. private:
  71. CSsdpRundownSupport();
  72. CSsdpRundownSupport(const CSsdpRundownSupport &);
  73. CSsdpRundownSupport & operator=(const CSsdpRundownSupport &);
  74. HRESULT HrAddItemInternal(CRundownHelperBase * pBase);
  75. static CSsdpRundownSupport s_instance;
  76. typedef CUList<CRundownHelperBase*> RundownList;
  77. CUCriticalSection m_critSec;
  78. RundownList m_rundownList;
  79. };