Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
ModuleContext Class Reference

#include <usModuleContext.h>

Public Member Functions

 ~ModuleContext ()
 
ModuleGetModule () const
 
ModuleGetModule (long id) const
 
ModuleGetModule (const std::string &name)
 
std::vector< Module * > GetModules () const
 
ServiceRegistrationU RegisterService (const InterfaceMap &service, const ServiceProperties &properties=ServiceProperties())
 
template<class S >
ServiceRegistration< S > RegisterService (S *service, const ServiceProperties &properties=ServiceProperties())
 
template<class I1 , class I2 , class Impl >
ServiceRegistration< I1, I2 > RegisterService (Impl *impl, const ServiceProperties &properties=ServiceProperties())
 
template<class I1 , class I2 , class I3 , class Impl >
ServiceRegistration< I1, I2, I3 > RegisterService (Impl *impl, const ServiceProperties &properties=ServiceProperties())
 
template<class S >
ServiceRegistration< S > RegisterService (ServiceFactory *factory, const ServiceProperties &properties=ServiceProperties())
 
template<class I1 , class I2 >
ServiceRegistration< I1, I2 > RegisterService (ServiceFactory *factory, const ServiceProperties &properties=ServiceProperties())
 
template<class I1 , class I2 , class I3 >
ServiceRegistration< I1, I2, I3 > RegisterService (ServiceFactory *factory, const ServiceProperties &properties=ServiceProperties())
 
std::vector< ServiceReferenceU > GetServiceReferences (const std::string &clazz, const std::string &filter=std::string())
 
template<class S >
std::vector< ServiceReference< S > > GetServiceReferences (const std::string &filter=std::string())
 
ServiceReferenceU GetServiceReference (const std::string &clazz)
 
template<class S >
ServiceReference< S > GetServiceReference ()
 
void * GetService (const ServiceReferenceBase &reference)
 
InterfaceMap GetService (const ServiceReferenceU &reference)
 
template<class S >
S * GetService (const ServiceReference< S > &reference)
 
template<class S >
ServiceObjects< S > GetServiceObjects (const ServiceReference< S > &reference)
 
bool UngetService (const ServiceReferenceBase &reference)
 
void AddServiceListener (const ServiceListener &delegate, const std::string &filter=std::string())
 
void RemoveServiceListener (const ServiceListener &delegate)
 
void AddModuleListener (const ModuleListener &delegate)
 
void RemoveModuleListener (const ModuleListener &delegate)
 
template<class R >
void AddServiceListener (R *receiver, void(R::*callback)(const ServiceEvent), const std::string &filter=std::string())
 
template<class R >
void RemoveServiceListener (R *receiver, void(R::*callback)(const ServiceEvent))
 
template<class R >
void AddModuleListener (R *receiver, void(R::*callback)(const ModuleEvent))
 
template<class R >
void RemoveModuleListener (R *receiver, void(R::*callback)(const ModuleEvent))
 
std::string GetDataFile (const std::string &filename) const
 

Detailed Description

A module's execution context within the framework. The context is used to grant access to other methods so that this module can interact with the Micro Services Framework.

ModuleContext methods allow a module to:

  • Subscribe to events published by the framework.
  • Register service objects with the framework service registry.
  • Retrieve ServiceReferences from the framework service registry.
  • Get and release service objects for a referenced service.
  • Get the list of modules loaded in the framework.
  • Get the Module object for a module.

A ModuleContext object will be created and provided to the module associated with this context when it is loaded using the ModuleActivator::Load method. The same ModuleContext object will be passed to the module associated with this context when it is unloaded using the ModuleActivator::Unload method. A ModuleContext object is generally for the private use of its associated module and is not meant to be shared with other modules in the module environment.

The Module object associated with a ModuleContext object is called the context module.

The ModuleContext object is only valid during the execution of its context module; that is, during the period when the context module is loaded. If the ModuleContext object is used subsequently, a std::logic_error is thrown. The ModuleContext object is never reused after its context module is unloaded.

The framework is the only entity that can create ModuleContext objects.

Remarks
This class is thread safe.

Definition at line 91 of file usModuleContext.h.

Constructor & Destructor Documentation

ModuleContext::~ModuleContext ( )

Definition at line 51 of file usModuleContext.cpp.

Member Function Documentation

void ModuleContext::AddModuleListener ( const ModuleListener delegate)

Definition at line 138 of file usModuleContext.cpp.

template<class R >
void ModuleContext::AddModuleListener ( R *  receiver,
void(R::*)(const ModuleEvent)  callback 
)
inline

Adds the specified callback to the context modules's list of listeners. Listeners are notified when a module has a lifecycle state change.

If the context module's list of listeners already contains a pair (r,c) of receiver and callback such that (r == receiver && c == callback), then this method does nothing.

Template Parameters
RThe type of the receiver (containing the member function to be called)
Parameters
receiverThe object to connect to.
callbackThe member function pointer to call.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
See also
ModuleEvent

Definition at line 786 of file usModuleContext.h.

void ModuleContext::AddServiceListener ( const ServiceListener delegate,
const std::string &  filter = std::string() 
)

Definition at line 127 of file usModuleContext.cpp.

template<class R >
void ModuleContext::AddServiceListener ( R *  receiver,
void(R::*)(const ServiceEvent)  callback,
const std::string &  filter = std::string() 
)
inline

Adds the specified callback with the specified filter to the context modules's list of listeners. See LDAPFilter for a description of the filter syntax. Listeners are notified when a service has a lifecycle state change.

You must take care to remove registered listeners befor the receiver object is destroyed. However, the Micro Services framework takes care of removing all listeners registered by this context module's classes after the module is unloaded.

If the context module's list of listeners already contains a pair (r,c) of receiver and callback such that (r == receiver && c == callback), then this method replaces that callback's filter (which may be empty) with the specified one (which may be empty).

The callback is called if the filter criteria is met. To filter based upon the class of the service, the filter should reference the ServiceConstants::OBJECTCLASS() property. If filter is empty, all services are considered to match the filter.

When using a filter, it is possible that the ServiceEvents for the complete lifecycle of a service will not be delivered to the callback. For example, if the filter only matches when the property x has the value 1, the callback will not be called if the service is registered with the property x not set to the value 1. Subsequently, when the service is modified setting property x to the value 1, the filter will match and the callback will be called with a ServiceEvent of type MODIFIED. Thus, the callback will not be called with a ServiceEvent of type REGISTERED.

Template Parameters
RThe type of the receiver (containing the member function to be called)
Parameters
receiverThe object to connect to.
callbackThe member function pointer to call.
filterThe filter criteria.
Exceptions
std::invalid_argumentIf filter contains an invalid filter string that cannot be parsed.
std::logic_errorIf this ModuleContext is no longer valid.
See also
ServiceEvent
RemoveServiceListener()

Definition at line 739 of file usModuleContext.h.

std::string ModuleContext::GetDataFile ( const std::string &  filename) const

Get the absolute path for a file or directory in the persistent storage area provided for the module. The returned path might be empty if no storage path has been set previously. If the path is non-empty, it is safe to assume that the path is writable.

See also
ModuleSettings::SetStoragePath(const std::string&)
Parameters
filenameA relative name to the file or directory to be accessed.
Returns
The absolute path to the persistent storage area for the given file name.

Definition at line 169 of file usModuleContext.cpp.

References filename.

Module * ModuleContext::GetModule ( ) const

Returns the Module object associated with this ModuleContext. This module is called the context module.

Returns
The Module object associated with this ModuleContext.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.

Definition at line 56 of file usModuleContext.cpp.

Referenced by mitk::EventConfig::AddConfig(), mitk::DICOMFileReaderSelector::AddConfigFromResource(), mitk::DICOMFileReaderSelector::AddConfigsFromResources(), mitk::EventConfig::EventConfig(), mitk::TrackingVolumeGenerator::GenerateData(), mitk::FillRegionTool::GetCursorIconResource(), mitk::EraseRegionTool::GetCursorIconResource(), mitk::DrawPaintbrushTool::GetCursorIconResource(), mitk::ErasePaintbrushTool::GetCursorIconResource(), mitk::AddContourTool::GetCursorIconResource(), mitk::LiveWireTool2D::GetCursorIconResource(), mitk::SubtractContourTool::GetCursorIconResource(), mitk::CorrectorTool2D::GetCursorIconResource(), mitk::RegionGrowingTool::GetCursorIconResource(), mitk::FastMarchingTool::GetCursorIconResource(), mitk::OtsuTool3D::GetIconResource(), mitk::FillRegionTool::GetIconResource(), mitk::EraseRegionTool::GetIconResource(), mitk::BinaryThresholdTool::GetIconResource(), mitk::BinaryThresholdULTool::GetIconResource(), mitk::DrawPaintbrushTool::GetIconResource(), mitk::ErasePaintbrushTool::GetIconResource(), mitk::PickingTool::GetIconResource(), mitk::AddContourTool::GetIconResource(), mitk::LiveWireTool2D::GetIconResource(), mitk::SubtractContourTool::GetIconResource(), mitk::CorrectorTool2D::GetIconResource(), mitk::RegionGrowingTool::GetIconResource(), mitk::AdaptiveRegionGrowingTool::GetIconResource(), mitk::WatershedTool::GetIconResource(), mitk::FastMarchingTool3D::GetIconResource(), mitk::FastMarchingTool::GetIconResource(), mitk::AbstractToFDeviceFactory::GetIntrinsicsResource(), mitk::OclBinaryThresholdImageFilter::GetModule(), mitk::StateMachineContainer::LoadBehavior(), SphereInterpolator::LoadLookuptables(), mitk::LevelWindowPreset::LoadPreset(), mitk::RigidRegistrationPreset::LoadPreset(), mitk::AnatomicalStructureColorPresets::LoadPreset(), mitkEventConfigTest(), and mitk::XML2EventParser::XML2EventParser().

Module * ModuleContext::GetModule ( long  id) const

Returns the module with the specified identifier.

Parameters
idThe identifier of the module to retrieve.
Returns
A Module object or 0 if the identifier does not match any previously loaded module.

Definition at line 61 of file usModuleContext.cpp.

Module * ModuleContext::GetModule ( const std::string &  name)

Get the module that with the specified module name.

Parameters
nameThe name of the module to get.
Returns
The requested Module or NULL.

Definition at line 66 of file usModuleContext.cpp.

std::vector< Module * > ModuleContext::GetModules ( ) const

Returns a list of all known modules.

This method returns a list of all modules loaded in the module environment at the time of the call to this method. This list will also contain modules which might already have been unloaded.

Returns
A std::vector of Module objects which will hold one object per known module.

Definition at line 71 of file usModuleContext.cpp.

void * ModuleContext::GetService ( const ServiceReferenceBase &  reference)

Returns the service object referenced by the specified ServiceReferenceBase object.

A module's use of a service is tracked by the module's use count of that service. Each time a service's service object is returned by GetService(const ServiceReference<S>&) the context module's use count for that service is incremented by one. Each time the service is released by UngetService(const ServiceReferenceBase&) the context module's use count for that service is decremented by one.

When a module's use count for a service drops to zero, the module should no longer use that service.

This method will always return 0 when the service associated with this reference has been unregistered.

The following steps are taken to get the service object:

  1. If the service has been unregistered, 0 is returned.
  2. The context module's use count for this service is incremented by one.
  3. If the context module's use count for the service is currently one and the service was registered with an object implementing the ServiceFactory interface, the ServiceFactory::GetService method is called to create a service object for the context module. This service object is cached by the framework. While the context module's use count for the service is greater than zero, subsequent calls to get the services's service object for the context module will return the cached service object.
    If the ServiceFactory object throws an exception, 0 is returned and a warning is logged.
  4. The service object for the service is returned.
Parameters
referenceA reference to the service.
Returns
A service object for the service associated with reference or 0 if the service is not registered or the ServiceFactory threw an exception.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
std::invalid_argumentIf the specified ServiceReferenceBase is invalid (default constructed).
See also
UngetService(const ServiceReferenceBase&)
ServiceFactory

Definition at line 103 of file usModuleContext.cpp.

Referenced by mitk::Tool::Activated(), mitk::SegTool2D::AddContourmarker(), mitk::OclFilter::CompileSource(), mitk::OclImage::CreateGPUImage(), mitk::Tool::Deactivated(), mitk::GetCurrentDICOMTagsOfInterest(), GetDescriptionsService(), GetPersistenceService(), mitk::ToFDeviceFactoryManager::GetRegisteredDeviceFactories(), mitk::OclFilter::Initialize(), mitk::TrackingVolumeGenerator::SetTrackingDevice(), mitk::TrackingVolumeGenerator::SetTrackingDeviceType(), SetUpBeforeTest(), mitk::OclBinaryThresholdImageFilter::Update(), and mitk::OclFilter::~OclFilter().

InterfaceMap ModuleContext::GetService ( const ServiceReferenceU &  reference)

Definition at line 112 of file usModuleContext.cpp.

template<class S >
S* ModuleContext::GetService ( const ServiceReference< S > &  reference)
inline

Returns the service object referenced by the specified ServiceReference object.

This is a convenience method which is identical to void* GetService(const ServiceReferenceBase&) except that it casts the service object to the supplied template argument type

Template Parameters
SThe type the service object will be cast to.
Returns
A service object for the service associated with reference or 0 if the service is not registered, the ServiceFactory threw an exception or the service could not be casted to the desired type.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
std::invalid_argumentIf the specified ServiceReference is invalid (default constructed).
See also
GetService(const ServiceReferenceBase&)
UngetService(const ServiceReferenceBase&)
ServiceFactory

Definition at line 612 of file usModuleContext.h.

template<class S >
ServiceObjects<S> ModuleContext::GetServiceObjects ( const ServiceReference< S > &  reference)
inline

Returns the ServiceObjects object for the service referenced by the specified ServiceReference object. The ServiceObjects object can be used to obtain multiple service objects for services with prototype scope. For services with singleton or module scope, the ServiceObjects::GetService() method behaves the same as the GetService(const ServiceReference<S>&) method and the ServiceObjects::UngetService(const ServiceReferenceBase&) method behaves the same as the UngetService(const ServiceReferenceBase&) method. That is, only one, use-counted service object is available from the ServiceObjects object.

Template Parameters
SType of Service.
Parameters
referenceA reference to the service.
Returns
A ServiceObjects object for the service associated with the specified reference or an invalid instance if the service is not registered.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
std::invalid_argumentIf the specified ServiceReference is invalid (default constructed or the service has been unregistered)
See also
PrototypeServiceFactory

Definition at line 639 of file usModuleContext.h.

ServiceReferenceU ModuleContext::GetServiceReference ( const std::string &  clazz)

Returns a ServiceReference object for a service that implements and was registered under the specified class.

The returned ServiceReference object is valid at the time of the call to this method. However as the Micro Services framework is a very dynamic environment, services can be modified or unregistered at any time.

This method is the same as calling ModuleContext::GetServiceReferences(const std::string&, const std::string&) with an empty filter expression. It is provided as a convenience for when the caller is interested in any service that implements the specified class.

If multiple such services exist, the service with the highest ranking (as specified in its ServiceConstants::SERVICE_RANKING() property) is returned.

If there is a tie in ranking, the service with the lowest service ID (as specified in its ServiceConstants::SERVICE_ID() property); that is, the service that was registered first is returned.

Parameters
clazzThe class name with which the service was registered.
Returns
A ServiceReference object, or an invalid ServiceReference if no services are registered which implement the named class.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf no service was registered under the given class name.
See also
GetServiceReferences(const std::string&, const std::string&)

Definition at line 98 of file usModuleContext.cpp.

Referenced by mitk::SegTool2D::AddContourmarker(), mitk::OclFilter::CompileSource(), mitk::OclImage::CreateGPUImage(), mitk::OclFilter::Initialize(), SetUpBeforeTest(), mitk::OclBinaryThresholdImageFilter::Update(), and mitk::OclFilter::~OclFilter().

template<class S >
ServiceReference<S> ModuleContext::GetServiceReference ( )
inline

Returns a ServiceReference object for a service that implements and was registered under the specified template class argument.

This method is identical to GetServiceReference(const std::string&) except that the class name for the service object is automatically deduced from the template argument.

Template Parameters
SThe type under which the requested service must have been registered.
Returns
A ServiceReference object, or an invalid ServiceReference if no services are registered which implement the type S.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIt no service was registered under the given class name.
See also
GetServiceReference(const std::string&)
GetServiceReferences(const std::string&)

Definition at line 530 of file usModuleContext.h.

std::vector< ServiceReferenceU > ModuleContext::GetServiceReferences ( const std::string &  clazz,
const std::string &  filter = std::string() 
)

Returns a list of ServiceReference objects. The returned list contains services that were registered under the specified class and match the specified filter expression.

The list is valid at the time of the call to this method. However since the Micro Services framework is a very dynamic environment, services can be modified or unregistered at any time.

The specified filter expression is used to select the registered services whose service properties contain keys and values which satisfy the filter expression. See LDAPFilter for a description of the filter syntax. If the specified filter is empty, all registered services are considered to match the filter. If the specified filter expression cannot be parsed, an std::invalid_argument will be thrown with a human readable message where the filter became unparsable.

The result is a list of ServiceReference objects for all services that meet all of the following conditions:

  • If the specified class name, clazz, is not empty, the service must have been registered with the specified class name. The complete list of class names with which a service was registered is available from the service's objectClass property.
  • If the specified filter is not empty, the filter expression must match the service.
Parameters
clazzThe class name with which the service was registered or an empty string for all services.
filterThe filter expression or empty for all services.
Returns
A list of ServiceReference objects or an empty list if no services are registered which satisfy the search.
Exceptions
std::invalid_argumentIf the specified filter contains an invalid filter expression that cannot be parsed.
std::logic_errorIf this ModuleContext is no longer valid.

Definition at line 84 of file usModuleContext.cpp.

Referenced by mitk::Tool::Activated(), mitk::GetCurrentDICOMTagsOfInterest(), GetDescriptionsService(), GetPersistenceService(), mitk::ToFDeviceFactoryManager::GetRegisteredDeviceFactories(), mitk::TrackingVolumeGenerator::SetTrackingDevice(), mitk::TrackingVolumeGenerator::SetTrackingDeviceType(), and mitk::ToFDeviceFactoryManager::ToFDeviceFactoryManager().

template<class S >
std::vector<ServiceReference<S> > ModuleContext::GetServiceReferences ( const std::string &  filter = std::string())
inline

Returns a list of ServiceReference objects. The returned list contains services that were registered under the interface id of the template argument S and match the specified filter expression.

This method is identical to GetServiceReferences(const std::string&, const std::string&) except that the class name for the service object is automatically deduced from the template argument.

Template Parameters
SThe type under which the requested service objects must have been registered.
Parameters
filterThe filter expression or empty for all services.
Returns
A list of ServiceReference objects or an empty list if no services are registered which satisfy the search.
Exceptions
std::invalid_argumentIf the specified filter contains an invalid filter expression that cannot be parsed.
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid.
See also
GetServiceReferences(const std::string&, const std::string&)

Definition at line 466 of file usModuleContext.h.

ServiceRegistrationU ModuleContext::RegisterService ( const InterfaceMap &  service,
const ServiceProperties &  properties = ServiceProperties() 
)

Registers the specified service object with the specified properties under the specified class names into the framework. A ServiceRegistration object is returned. The ServiceRegistration object is for the private use of the module registering the service and should not be shared with other modules. The registering module is defined to be the context module. Other modules can locate the service by using either the GetServiceReferences or GetServiceReference method.

A module can register a service object that implements the ServiceFactory or PrototypeServiceFactory interface to have more flexibility in providing service objects to other modules.

The following steps are taken when registering a service:

  1. The framework adds the following service properties to the service properties from the specified ServiceProperties (which may be omitted):
    A property named ServiceConstants::SERVICE_ID() identifying the registration number of the service
    A property named ServiceConstants::OBJECTCLASS() containing all the specified classes.
    A property named ServiceConstants::SERVICE_SCOPE() identifying the scope of the service.
    Properties with these names in the specified ServiceProperties will be ignored.
  2. The service is added to the framework service registry and may now be used by other modules.
  3. A service event of type ServiceEvent::REGISTERED is fired.
  4. A ServiceRegistration object for this registration is returned.
Note
This is a low-level method and should normally not be used directly. Use one of the templated RegisterService methods instead.
Parameters
serviceThe service object, which is a map of interface identifiers to raw service pointers.
propertiesThe properties for this service. The keys in the properties object must all be std::string objects. See ServiceConstants for a list of standard service property keys. Changes should not be made to this object after calling this method. To update the service's properties the ServiceRegistration::SetProperties method must be called. The set of properties may be omitted if the service has no properties.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::invalid_argumentIf one of the following is true:
  • service is 0.
  • properties contains case variants of the same key name.
std::logic_errorIf this ModuleContext is no longer valid.
See also
ServiceRegistration
ServiceFactory
PrototypeServiceFactory

Definition at line 78 of file usModuleContext.cpp.

Referenced by mitk::ToolManager::ActivateTool(), mitk::ToolManager::RegisterClient(), and mitk::BaseDataCompare::RegisterCoreEquals().

template<class S >
ServiceRegistration<S> ModuleContext::RegisterService ( S *  service,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service object with the specified properties using the specified template argument with the framework.

This method is provided as a convenience when service will only be registered under a single class name whose type is available to the caller. It is otherwise identical to RegisterService(const InterfaceMap&, const ServiceProperties&) but should be preferred since it avoids errors in the string literal identifying the class name or interface identifier.

Example usage:

class MyService : public InterfaceA
{};
MyService* myService = new MyService;
context->RegisterService<InterfaceA>(myService);
Template Parameters
SThe type under which the service can be located.
Parameters
serviceThe service object or a ServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 232 of file usModuleContext.h.

template<class I1 , class I2 , class Impl >
ServiceRegistration<I1,I2> ModuleContext::RegisterService ( Impl *  impl,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service object with the specified properties using the specified template argument with the framework.

This method is provided as a convenience when registering a service under two interface classes whose type is available to the caller. It is otherwise identical to RegisterService(const InterfaceMap&, const ServiceProperties&) but should be preferred since it avoids errors in the string literal identifying the class name or interface identifier.

Example usage:

class MyService2 : public InterfaceA, public InterfaceB
{};
MyService2* myService = new MyService2;
context->RegisterService<InterfaceA, InterfaceB>(myService);
Template Parameters
I1The first interface type under which the service can be located.
I2The second interface type under which the service can be located.
Parameters
implThe service object or a ServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 266 of file usModuleContext.h.

template<class I1 , class I2 , class I3 , class Impl >
ServiceRegistration<I1,I2,I3> ModuleContext::RegisterService ( Impl *  impl,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service object with the specified properties using the specified template argument with the framework.

This method is identical to the RegisterService<I1,I2,Impl>(Impl*, const ServiceProperties&) method except that it supports three service interface types.

Template Parameters
I1The first interface type under which the service can be located.
I2The second interface type under which the service can be located.
I3The third interface type under which the service can be located.
Parameters
implThe service object or a ServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 295 of file usModuleContext.h.

template<class S >
ServiceRegistration<S> ModuleContext::RegisterService ( ServiceFactory *  factory,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service factory as a service with the specified properties using the specified template argument as service interface type with the framework.

This method is provided as a convenience when factory will only be registered under a single class name whose type is available to the caller. It is otherwise identical to RegisterService(const InterfaceMap&, const ServiceProperties&) but should be preferred since it avoids errors in the string literal identifying the class name or interface identifier.

Example usage:

class MyService : public InterfaceA
{};
class MyServiceFactory : public ServiceFactory
{
virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) override
{
MyService* myService = new MyService;
return MakeInterfaceMap<InterfaceA>(myService);
}
virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/,
const InterfaceMap& service) override
{
delete ExtractInterface<InterfaceA>(service);
}
};
MyServiceFactory* myServiceFactory = new MyServiceFactory;
context->RegisterService<InterfaceA>(myServiceFactory);
Template Parameters
SThe type under which the service can be located.
Parameters
factoryThe ServiceFactory or PrototypeServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service factory object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 328 of file usModuleContext.h.

template<class I1 , class I2 >
ServiceRegistration<I1,I2> ModuleContext::RegisterService ( ServiceFactory *  factory,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service factory as a service with the specified properties using the specified template argument as service interface type with the framework.

This method is identical to the RegisterService<S>(ServiceFactory*, const ServiceProperties&) method except that it supports two service interface types.

Example usage:

class MyService2 : public InterfaceA, public InterfaceB
{};
class MyServiceFactory : public ServiceFactory
{
virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) override
{
MyService2* myService = new MyService2;
return MakeInterfaceMap<InterfaceA,InterfaceB>(myService);
}
virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/,
const InterfaceMap& service) override
{
delete ExtractInterface<InterfaceA>(service);
}
};
MyServiceFactory* myServiceFactory = new MyServiceFactory;
context->RegisterService<InterfaceA,InterfaceB>(static_cast<ServiceFactory*>(myServiceFactory));
Template Parameters
I1The first interface type under which the service can be located.
I2The second interface type under which the service can be located.
Parameters
factoryThe ServiceFactory or PrototypeServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service factory object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 360 of file usModuleContext.h.

template<class I1 , class I2 , class I3 >
ServiceRegistration<I1,I2,I3> ModuleContext::RegisterService ( ServiceFactory *  factory,
const ServiceProperties &  properties = ServiceProperties() 
)
inline

Registers the specified service factory as a service with the specified properties using the specified template argument as service interface type with the framework.

This method is identical to the RegisterService<S>(ServiceFactory*, const ServiceProperties&) method except that it supports three service interface types.

Template Parameters
I1The first interface type under which the service can be located.
I2The second interface type under which the service can be located.
I3The third interface type under which the service can be located.
Parameters
factoryThe ServiceFactory or PrototypeServiceFactory object.
propertiesThe properties for this service.
Returns
A ServiceRegistration object for use by the module registering the service to update the service's properties or to unregister the service.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
ServiceExceptionIf the service type S is invalid or the service factory object is NULL.
See also
RegisterService(const InterfaceMap&, const ServiceProperties&)

Definition at line 389 of file usModuleContext.h.

void ModuleContext::RemoveModuleListener ( const ModuleListener delegate)

Definition at line 143 of file usModuleContext.cpp.

template<class R >
void ModuleContext::RemoveModuleListener ( R *  receiver,
void(R::*)(const ModuleEvent)  callback 
)
inline

Removes the specified callback from the context module's list of listeners.

If the (receiver,callback) pair is not contained in this context module's list of listeners, this method does nothing.

Template Parameters
RThe type of the receiver (containing the member function to be removed)
Parameters
receiverThe object from which to disconnect.
callbackThe member function pointer to remove.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
See also
AddModuleListener()

Definition at line 808 of file usModuleContext.h.

void ModuleContext::RemoveServiceListener ( const ServiceListener delegate)

Definition at line 133 of file usModuleContext.cpp.

template<class R >
void ModuleContext::RemoveServiceListener ( R *  receiver,
void(R::*)(const ServiceEvent)  callback 
)
inline

Removes the specified callback from the context module's list of listeners.

If the (receiver,callback) pair is not contained in this context module's list of listeners, this method does nothing.

Template Parameters
RThe type of the receiver (containing the member function to be removed)
Parameters
receiverThe object from which to disconnect.
callbackThe member function pointer to remove.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
See also
AddServiceListener()

Definition at line 762 of file usModuleContext.h.

bool ModuleContext::UngetService ( const ServiceReferenceBase &  reference)

Releases the service object referenced by the specified ServiceReference object. If the context module's use count for the service is zero, this method returns false. Otherwise, the context modules's use count for the service is decremented by one.

The service's service object should no longer be used and all references to it should be destroyed when a module's use count for the service drops to zero.

The following steps are taken to unget the service object:

  1. If the context module's use count for the service is zero or the service has been unregistered, false is returned.
  2. The context module's use count for this service is decremented by one.
  3. If the context module's use count for the service is currently zero and the service was registered with a ServiceFactory object, the ServiceFactory::UngetService method is called to release the service object for the context module.
  4. true is returned.
Parameters
referenceA reference to the service to be released.
Returns
false if the context module's use count for the service is zero or if the service has been unregistered; true otherwise.
Exceptions
std::logic_errorIf this ModuleContext is no longer valid.
See also
GetService
ServiceFactory

Definition at line 121 of file usModuleContext.cpp.


The documentation for this class was generated from the following files: