home *** CD-ROM | disk | FTP | other *** search
- #include "ocheaders.h"
- #include <LArray.h>
- #include "CConnectionPoint.h"
- #include "CEnumConnectionPoints.h"
- #include "CCPContainer.h"
-
- #define APPENDITEM 32000 // Large number to force appending to an array
-
-
- //
- // CCPContainer::CCPContainer
- //
- CCPContainer::CCPContainer(short NumConnections)
- {
- // Allocate memory for the connection points array
- m_ConnectionPoints = new LArray( (sizeof(IConnectionPoint*)) * NumConnections);
-
- }
-
-
- //
- // CCPContainer::~CCPContainer
- //
- CCPContainer::~CCPContainer(void)
- {
- // if we have connection points, release them
- if ( m_ConnectionPoints )
- {
- short i;
- IConnectionPoint* cp;
-
- // Release each connection point
- for ( i = 1; i <= m_ConnectionPoints->GetCount(); i++)
- {
- m_ConnectionPoints->FetchItemAt(i, &cp);
- cp->Release();
- }
-
- // Free the array
- delete m_ConnectionPoints;
- }
- }
-
-
- //
- // CCPContainer::AddConnectionPoint
- //
- STDMETHODIMP
- CCPContainer::AddConnectionPoint(IID InterfaceID)
- {
- #pragma unused (InterfaceID)
- IConnectionPoint* cp;
- CConnectionPoint* ConnectionPoint;
-
- // Create a new ConnectionPoint object
- ConnectionPoint = new CConnectionPoint((void*) this, InterfaceID);
-
- // Get the IConnectionPoint interface
- ConnectionPoint->QueryInterface(IID_IConnectionPoint, (void**) &cp);
-
- // Insert the IConnectionPoint* interface into the array
- m_ConnectionPoints->InsertItemsAt(1, APPENDITEM, &cp);
-
- // Add our reference to this connection point
- cp->AddRef();
-
- return ResultFromScode(S_OK);
- }
-
-
- //
- // CCPContainer::IUnknown::QueryInterface
- //
- // Returns a pointer to the specified interface on a component to which a
- // client currently holds an interface pointer.
- //
- STDMETHODIMP
- CCPContainer::QueryInterface(REFIID RefID, void** Obj)
- {
- void* pv = nil;
-
- if (RefID == IID_IUnknown )
- pv = (void*) this;
- else if (RefID == IID_IConnectionPointContainer)
- pv = (void*) (IConnectionPointContainer*) this;
-
- *Obj = pv;
-
- // if we got an interface, ref it and return ok
- if ( pv )
- {
- ((IUnknown*) pv)->AddRef();
- return ResultFromScode(S_OK);
- }
- else
- return ResultFromScode(E_NOINTERFACE);
- }
-
-
- //
- // CCPContainer::IUnknown::AddRef
- //
- // Increments the reference count for the calling interface.
- //
- STDMETHODIMP_(ULONG)
- CCPContainer::AddRef(void)
- {
- return ++m_RefCount;
- }
-
-
- //
- // CCPContainer::IUnknown::Release
- //
- // Decrements the reference count for the calling interface on a object. If
- // the reference count on the object falls to zero, the object is freed.
- //
- STDMETHODIMP_(ULONG)
- CCPContainer::Release(void)
- {
- if (--m_RefCount != 0)
- return m_RefCount;
-
- delete this;
- return 0;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CCPContainer::IConnectionPointContainer::EnumConnectionPoints
- //=--------------------------------------------------------------------------=
- STDMETHODIMP
- CCPContainer::EnumConnectionPoints(IEnumConnectionPoints** EnumCP)
- {
- CEnumConnectionPoints* EnumConnections;
-
- *EnumCP = nil;
-
- // Dont do this if we don't have any connections
- if ( m_ConnectionPoints && m_ConnectionPoints->GetCount() > 0 )
- {
- // Create the enumerator object from our connection points
- EnumConnections = new CEnumConnectionPoints(m_ConnectionPoints);
-
- // Get the enumerator interface and add reference
- if ( EnumConnections )
- {
- EnumConnections->QueryInterface(IID_IEnumConnectionPoints, (void**) EnumCP);
- }
- }
-
- return ResultFromScode(S_OK);
- }
-
-
- //=--------------------------------------------------------------------------=
- // CCPContainer::IConnectionPointContainer::FindConnectionPoint
- //=--------------------------------------------------------------------------=
- STDMETHODIMP
- CCPContainer::FindConnectionPoint(REFIID RefID, IConnectionPoint** ConnectionPoint)
- {
- short i;
- IID InterfaceID;
- IConnectionPoint* cp;
-
- // Look through all our connection points for the one specified by RefID
- for ( i = 1; i <= m_ConnectionPoints->GetCount(); i ++)
- {
- m_ConnectionPoints->FetchItemAt(i, &cp);
- cp->GetConnectionInterface(&InterfaceID);
-
- // if this is the one, query it for the connection point interface
- if ( InterfaceID == RefID )
- return cp->QueryInterface(IID_IConnectionPoint, (void**) ConnectionPoint);
- }
-
- return ResultFromScode(E_NOINTERFACE);
- }
-
-
-