text: /*++
  
  Copyright (c) 1997  Microsoft Corporation
  
  Module Name:
  
      connect.h
  
  Abstract:
  
      defines for event/sink interface for IIS DCOM Admin.
  
  Author:
  
      Sophia Chung (sophiac)   14-Jan-97
  
  Revision History:
  
  --*/
  
  #if !defined(CONNECT_H)
  #define CONNECT_H
  
  #ifdef __cplusplus
  
  // Types that should be in OLE2.H
  #ifndef PPVOID
  typedef LPVOID* PPVOID;
  #endif
  
  enum
  {
    // A constant for the number of connections to add to the allocation
    // of the dynamic connection array.
    ALLOC_CONNECTIONS = 8,
  
    // The start value for the connection key (cookie) counter.
    COOKIE_START_VALUE = 500
  };
  
  
  /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
    ObjectClass: COEnumConnectionPoints
  
    Summary:     COM object class for enumerating the Connection Points
                 offered by a connectable object.
  
    Interfaces:  IUnknown
                   Standard interface providing COM object features.
                 IEnumConnectionPoints
                   Interface for connection point enumeration.
  
    Aggregation: COEnumConnectionPoints COM Objects are not aggregatable.
  O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  class COEnumConnectionPoints : public IEnumConnectionPoints
  {
    public:
      // Main Object Constructor & Destructor.
      COEnumConnectionPoints(IUnknown* pHostObj);
      ~COEnumConnectionPoints(void);
  
      // A general method for initializing this newly created object.
      // Creates any subordinate arrays, structures, or objects.
      HRESULT Init(
                ULONG cConnPts,
                IConnectionPoint** paConnPts,
                ULONG iEnumIndex);
  
      // IUnknown methods. Main object, non-delegating.
      STDMETHODIMP         QueryInterface(REFIID, PPVOID);
      STDMETHODIMP_(ULONG) AddRef(void);
      STDMETHODIMP_(ULONG) Release(void);
  
      // IEnumConnectionPoints methods.
      STDMETHODIMP         Next(ULONG, IConnectionPoint**, ULONG*);
      STDMETHODIMP         Skip(ULONG);
      STDMETHODIMP         Reset(void);
      STDMETHODIMP         Clone(IEnumConnectionPoints**);
  
    private:
      // Private data of COEnumConnectionPoints COM objects.
  
      // Main Object reference count.
      ULONG              m_cRefs;
  
      // IUnknown pointer to host COM object being enumerated.
      IUnknown*          m_pHostObj;
  
      // Connection Point index variable.
      ULONG              m_iEnumIndex;
  
      // Number of Connection Points being enumerated.
      ULONG              m_cConnPts;
  
      // Allocated array of Connection Point interface pointers.
      IConnectionPoint** m_paConnPts;
  };
  
  typedef COEnumConnectionPoints* PCOEnumConnectionPoints;
  
  
  /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
    ObjectClass: COConnectionPoint
  
    Summary:     Connection Point COM object class. Implements a native
                 IConnectionPoint interface. The Advise, Unadvise, and
                 EnumConnections methods use the CThreaded OwnThis mechanism
                 to provide thread-safe mutually exclusive access to this
                 connection point object.
  
    Interfaces:  IUnknown
                   Standard interface providing COM object features.
                 IConnectionPoint
                   Interface for connection point features.
  
    Aggregation: COConnectionPoint COM Objects are not aggregatable.
  O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  class COConnectionPoint : public IConnectionPoint
  {
    public:
      // Main Object Constructor & Destructor.
      COConnectionPoint();
      ~COConnectionPoint(void);
  
      // A general method for initializing this newly created object.
      // Creates any subordinate arrays, structures, or objects.
      HRESULT Init(IUnknown* pHostObj, REFIID riid);
  
      // IUnknown methods. Main object, non-delegating.
      STDMETHODIMP         QueryInterface(REFIID, PPVOID);
      STDMETHODIMP_(ULONG) AddRef(void);
      STDMETHODIMP_(ULONG) Release(void);
  
      // IConnectionPoint methods.
      STDMETHODIMP    GetConnectionInterface(IID*);
      STDMETHODIMP    GetConnectionPointContainer(IConnectionPointContainer**);
      STDMETHODIMP    Advise(IUnknown*, DWORD*);
      STDMETHODIMP    Unadvise(DWORD);
      STDMETHODIMP    EnumConnections(IEnumConnections**);
  
      // Our own methods
      STDMETHODIMP    ListenersPresent(VOID);
      STDMETHODIMP    Terminate(VOID);
      STDMETHODIMP    Disable(VOID);
      STDMETHODIMP    InternalEnumSinks(
          CONNECTDATA         **prgConnections,
          ULONG               *pcConnections);
  
    private:
      // Private utility methods of COConnectionPoint.
      STDMETHODIMP    Unadvise_Worker(DWORD dwCookie);
      HRESULT GetSlot(UINT* puiFreeSlot);
      HRESULT FindSlot(DWORD dwCookie, UINT* puiSlot);
  
      // Private data of COConnectionPoint COM objects.
  
      // Used to protect access to the member data.
      CReaderWriterLock3  m_Lock;
  
      // IUnknown pointer to host COM object offering this connection point.
      IUnknown*           m_pHostObj;
  
      // The IID of the sink interface associated with this connection point.
      IID                 m_iidSink;
  
      // The current number of live sink connections to this connection point.
      UINT                m_cConnections;
  
      // The current maximum index into the dynamic connection array.
      UINT                m_uiMaxIndex;
  
      // The dynamic array of sink connections to this connection point.
      CONNECTDATA*        m_paConnections;
  
      // Determines whether the host object is shuting down and force terminated us
      volatile BOOL       m_bTerminated;
  
      BOOL                m_bEnabled;
  
      IGlobalInterfaceTable* m_pGIT;
  
  };
  
  typedef COConnectionPoint* PCOConnectionPoint;
  
  
  /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
    ObjectClass: COEnumConnections
  
    Summary:     COM object class for enumerating the connections of a
                 connection point of a connectable object.
  
    Interfaces:  IUnknown
                   Standard interface providing COM object features.
                 IEnumConnections
                   Interface for connection enumeration features.
  
    Aggregation: COEnumConnections COM Objects are not aggregatable.
  O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  class COEnumConnections : public IEnumConnections
  {
    public:
      // Main Object Constructor & Destructor.
      COEnumConnections(IUnknown* pHostObj);
      ~COEnumConnections(void);
  
      // A general method for initializing this newly created object.
      // Creates any subordinate arrays, structures, or objects.
      HRESULT Init(
                ULONG cConnections,
                CONNECTDATA* paConnections,
                ULONG iEnumIndex,
                IGlobalInterfaceTable* pGIT = NULL
                );
  
      // IUnknown methods. Main object, non-delegating.
      STDMETHODIMP         QueryInterface(REFIID, PPVOID);
      STDMETHODIMP_(ULONG) AddRef(void);
      STDMETHODIMP_(ULONG) Release(void);
  
      // IEnumConnections methods.
      STDMETHODIMP         Next(ULONG, CONNECTDATA*, ULONG*);
      STDMETHODIMP         Skip(ULONG);
      STDMETHODIMP         Reset(void);
      STDMETHODIMP         Clone(IEnumConnections**);
  
    private:
      // Private data of COEnumConnections COM objects.
  
      // Main Object reference count.
      ULONG            m_cRefs;
  
      // IUnknown pointer to host connection point COM object being
      // enumerated.
      IUnknown*        m_pHostObj;
  
      // Connection index variable.
      ULONG            m_iEnumIndex;
  
      // Number of Connections being enumerated.
      ULONG            m_cConnections;
  
      // Allocated array of live Connections only.
      CONNECTDATA*     m_paConnections;
  
  };
  
  typedef COEnumConnections* PCOEnumConnections;
  
  HRESULT SetSinkCallbackSecurityBlanket(
      IUnknown            * pUnkSink);
  
  #endif // __cplusplus
  
  #endif // CONNECT_H
  