Accessing interfaces from a mediator

Mediators can be associated with other mediators at runtime. When it is necessary to add an additional colleague to a specific mediator that is part of a collection, the GetMediator template function can be used to obtain a pointer to the desired mediator. GetMediator can also be used to retrieve pointers to specific interfaces. The GetMediator function is a member of the IPKIFMediator interface and is defined as follows:

 
template<class X> X* GetMediator() const;

 
The function takes one template parameter that identifies the mediator to retrieve.  When the requested mediator is not found NULL is returned.  The GetMediator function is used as follos:


CPKIFCryptoMediator2 cryptoMediator = new CPKIFCryptoMediator2();
CPKIFCacheMediator2 cacheMediator = 
new CPKIFCacheMediator2();
CPKIFRevocationStatusMediator2 revStatMed = 
new
 CPKIFRevocationStatusMediator2(); 


CPKIFPathProcessingMediator2 pathProcMediator;
pathProcMediator.Initialize();

pathProcMediator.AddMediator(cryptoMediator);
pathProcMediator.AddMediator(cacheMediator);
pathProcMediator.AddMediator(revStatMed);


//retrieve a pointer to the IPKIFCryptoKeyIDOperations interface to exercise functionality via that interface
IPKIFCryptoKeyIDOperations* cryptoKeyID = pathProcMediator.GetMediator<IPKIFCryptoKeyIDOperations>();

//retrieve a pointer to the CPKIFCacheMediator2 mediator to perform operations on the mediator object itself
CPKIFCacheMediator2* cacheMediator =  pathProcMediator.GetMediator<CPKIFCacheMediator2 >();

 

IMG00002.bmpIt is necessary to invoke the Initialize function on all mediators prior to use. Initialize will automatically invoke Initialize on all associated mediators.