18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VISUAL C++<br />

Outbound interface—This is an interface of methods that a COM object will<br />

fire at various times. For example, the Map coclass will fire an event on the<br />

IActiveViewEvents in response to changes in the map.<br />

Event source—The source COM object will fire events to an outbound interface<br />

when certain actions occur. For example, the Map coclass is a source of<br />

IActiveViewEvents and will fire the IActiveViewEvents::ItemAdded event when a<br />

new layer is added to the map. The source object can have any number of clients,<br />

or event sink objects, listening to events. Also, a source object may have more than<br />

one outbound interface; for example, the Map coclass also fires events on an<br />

IMapEvents interface. An event source will typically declare its outbound interfaces<br />

in IDL with the [source] tag.<br />

Event sink—A COM object that listens to events is said to be a sink for events.<br />

The sink object implements the outbound interface; this is not always advertised<br />

in the type libraries because the sink may listen to events internally. An event sink<br />

typically uses the connection point mechanism to register its interest in the events of<br />

a source object.<br />

Connection point—COM objects that are the source of events typically use the<br />

connection point mechanism to allow sinks to hook up to a source. The connection<br />

point interfaces are the standard COM interfaces IConnectionPointContainer and<br />

IConnectionPoint.<br />

Fire event—When a source object needs to inform all the sinks of a particular<br />

action, the source is said to fire an event. This results in the source iterating all<br />

the sinks and making the same method call on each. For example, when a layer is<br />

added to a map, the Map coclass is said to fire the ItemAdded event. So all the<br />

objects listening to the Map’s outbound IActiveViewEvents interface will be called<br />

on their implementation of the ItemAdded method.<br />

Advise and unadvise events—To begin receiving events, a sink object is said<br />

to advise a source object that it needs to receive events. When events are no<br />

longer required, the sink will unadvise the source.<br />

The ConnectionPoint mechanism<br />

The source object implements the IConnectionPointContainer interface to allow sinks<br />

to query a source for a specific outbound interface. The following steps are<br />

performed to begin listening to an event. ATL implements this with the AtlAdvise<br />

method.<br />

1. The sink will QI the source object’s IConnectionPointContainer and call<br />

FindConnectionPoint to supply an interface ID for outbound interfaces. To be<br />

able to receive events, the sink object must implement this interface.<br />

2. The source may implement many outbound interfaces and will return a pointer<br />

to a specific connection point object implementing IConnectionPoint to represent<br />

one outbound interface.<br />

3. The sink calls IConnectionPoint::Advise, passing a pointer to its own IUnknown<br />

implementation. The source will store this with any other sinks that may be<br />

listening to events. If the call to Advise was successful, the sink will be given<br />

an identifier—a simple unsigned long value called a cookie—to give back to<br />

the source at a later point when it no longer needs to listen to events.<br />

Chapter 4 • <strong>Developer</strong> environments • 129

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!