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.

119 lines
3.0 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: IConnectionPoint implementation
  6. File: ConnPt.h
  7. Owner: DGottner
  8. Implementation of IConnectionPoint
  9. ===================================================================*/
  10. #ifndef _ConnPt_H
  11. #define _ConnPt_H
  12. /*
  13. * C C o n n e c t i o n P o i n t
  14. *
  15. * IConnectionPoint interface implementation for OLE objects
  16. *
  17. * This class contains the basic five IConnectionPoint members. The Big Three
  18. * (QueryInterface, AddRef, Release) are left as pure virtual, as this
  19. * class is designed as an intermediate class for further derivation.
  20. *
  21. * This also means that we no longer need a pointer to the controlling unknown.
  22. */
  23. #include "DblLink.h"
  24. /* ****************************************************************************
  25. Class: CConnectionPoint
  26. Synopsis: Provide a reusable implementation of IConnectionPoint
  27. NOTE: Linked list of sinks is used because we are expecting very
  28. few connections. (in fact only one (Caesars))
  29. */
  30. class CConnectionPoint : public IConnectionPoint
  31. {
  32. friend class CEnumConnections;
  33. private:
  34. struct CSinkElem : CDblLink
  35. {
  36. DWORD m_dwCookie; // cookie that we assigned the connection
  37. IUnknown * m_pUnkObj; // event sink
  38. CSinkElem(DWORD dwCookie, IUnknown *pUnkObj)
  39. {
  40. m_dwCookie = dwCookie;
  41. if ((m_pUnkObj = pUnkObj) != NULL) m_pUnkObj->AddRef();
  42. }
  43. ~CSinkElem()
  44. {
  45. if (m_pUnkObj) m_pUnkObj->Release();
  46. }
  47. };
  48. CDblLink m_listSinks; // list of event sinks
  49. DWORD m_dwCookieNext; // Next cookie
  50. protected:
  51. IUnknown * m_pUnkContainer; // pointer to parent container
  52. GUID m_uidEvent; // connection point interface
  53. public:
  54. CConnectionPoint(IUnknown *, const GUID &);
  55. ~CConnectionPoint();
  56. // IConnectionPoint members
  57. STDMETHODIMP GetConnectionInterface(GUID *);
  58. STDMETHODIMP GetConnectionPointContainer(IConnectionPointContainer **);
  59. STDMETHODIMP Advise(IUnknown *, DWORD *);
  60. STDMETHODIMP Unadvise(DWORD);
  61. STDMETHODIMP EnumConnections(IEnumConnections **);
  62. inline BOOL FIsEmpty() // quick way to check if list is empty w/o allocating enumerator
  63. {
  64. return m_listSinks.FIsEmpty();
  65. }
  66. };
  67. /* ****************************************************************************
  68. Class: CEnumConnections
  69. Synopsis: Provide the enumerator for CConnectionPoint
  70. */
  71. class CEnumConnections : public IEnumConnections
  72. {
  73. private:
  74. ULONG m_cRefs; // Reference count
  75. CDblLink * m_pElemCurr; // Current element
  76. CConnectionPoint * m_pCP; // pointer to iteratee
  77. public:
  78. CEnumConnections(CConnectionPoint *pCP);
  79. ~CEnumConnections(void);
  80. // The Big Three
  81. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  82. STDMETHODIMP_(ULONG) AddRef(void);
  83. STDMETHODIMP_(ULONG) Release(void);
  84. // IEnumConnections members
  85. STDMETHODIMP Next(ULONG, CONNECTDATA *, ULONG *);
  86. STDMETHODIMP Skip(ULONG);
  87. STDMETHODIMP Reset(void);
  88. STDMETHODIMP Clone(IEnumConnections **);
  89. };
  90. #endif _ConnPt_H_