CppMicroServices

C++ Micro Services: ServiceReference Class Reference
ServiceReference Class Reference

A reference to a service. More...

Public Member Functions

 ServiceReference ()
 Creates an invalid ServiceReference object. More...
 
 ServiceReference (const ServiceReference &ref)
 
 operator bool () const
 Converts this ServiceReference instance into a boolean expression. More...
 
ServiceReferenceoperator= (int null)
 Releases any resources held or locked by this ServiceReference and renders it invalid. More...
 
 ~ServiceReference ()
 
Any GetProperty (const std::string &key) const
 Returns the property value to which the specified property key is mapped in the properties ServiceProperties object of the service referenced by this ServiceReference object. More...
 
void GetPropertyKeys (std::vector< std::string > &keys) const
 Returns a list of the keys in the ServiceProperties object of the service referenced by this ServiceReference object. More...
 
ModuleGetModule () const
 Returns the module that registered the service referenced by this ServiceReference object. More...
 
void GetUsingModules (std::vector< Module * > &modules) const
 Returns the modules that are using the service referenced by this ServiceReference object. More...
 
bool operator< (const ServiceReference &reference) const
 Compares this ServiceReference with the specified ServiceReference for order. More...
 
bool operator== (const ServiceReference &reference) const
 
ServiceReferenceoperator= (const ServiceReference &reference)
 

Detailed Description

A reference to a service.

The framework returns ServiceReference objects from the ModuleContext::GetServiceReference and ModuleContext::GetServiceReferences methods.

A ServiceReference object may be shared between modules and can be used to examine the properties of the service and to get the service object.

Every service registered in the framework has a unique ServiceRegistration object and may have multiple, distinct ServiceReference objects referring to it. ServiceReference objects associated with a ServiceRegistration are considered equal (more specifically, their operator==() method will return true when compared).

If the same service object is registered multiple times, ServiceReference objects associated with different ServiceRegistration objects are not equal.

See Also
ModuleContext::GetServiceReference
ModuleContext::GetServiceReferences
ModuleContext::GetService
Remarks
This class is thread safe.

Constructor & Destructor Documentation

ServiceReference::ServiceReference ( )

Creates an invalid ServiceReference object.

You can use this object in boolean expressions and it will evaluate to false.

ServiceReference::ServiceReference ( const ServiceReference ref)
ServiceReference::~ServiceReference ( )

Member Function Documentation

Module* ServiceReference::GetModule ( ) const

Returns the module that registered the service referenced by this ServiceReference object.

This method must return 0 when the service has been unregistered. This can be used to determine if the service has been unregistered.

Returns
The module that registered the service referenced by this ServiceReference object; 0 if that service has already been unregistered.
See Also
ModuleContext::RegisterService(const std::vector<std::string>&, US_BASECLASS_NAME*, const ServiceProperties&)
Any ServiceReference::GetProperty ( const std::string &  key) const

Returns the property value to which the specified property key is mapped in the properties ServiceProperties object of the service referenced by this ServiceReference object.

Property keys are case-insensitive.

This method continues to return property values after the service has been unregistered. This is so references to unregistered services can still be interrogated.

Parameters
keyThe property key.
Returns
The property value to which the key is mapped; an invalid Any if there is no property named after the key.
void ServiceReference::GetPropertyKeys ( std::vector< std::string > &  keys) const

Returns a list of the keys in the ServiceProperties object of the service referenced by this ServiceReference object.

This method will continue to return the keys after the service has been unregistered. This is so references to unregistered services can still be interrogated.

Parameters
keysA vector being filled with the property keys.
void ServiceReference::GetUsingModules ( std::vector< Module * > &  modules) const

Returns the modules that are using the service referenced by this ServiceReference object.

Specifically, this method returns the modules whose usage count for that service is greater than zero.

Parameters
modulesA list of modules whose usage count for the service referenced by this ServiceReference object is greater than zero.
ServiceReference::operator bool ( ) const

Converts this ServiceReference instance into a boolean expression.

If this instance was default constructed or the service it references has been unregistered, the conversion returns false, otherwise it returns true.

bool ServiceReference::operator< ( const ServiceReference reference) const

Compares this ServiceReference with the specified ServiceReference for order.

If this ServiceReference and the specified ServiceReference have the same service id they are equal. This ServiceReference is less than the specified ServiceReference if it has a lower service ranking and greater if it has a higher service ranking. Otherwise, if this ServiceReference and the specified ServiceReference have the same service ranking, this ServiceReference is less than the specified ServiceReference if it has a higher service id and greater if it has a lower service id.

Parameters
referenceThe ServiceReference to be compared.
Returns
Returns a false or true if this ServiceReference is less than or greater than the specified ServiceReference.
ServiceReference& ServiceReference::operator= ( int  null)

Releases any resources held or locked by this ServiceReference and renders it invalid.

ServiceReference& ServiceReference::operator= ( const ServiceReference reference)
bool ServiceReference::operator== ( const ServiceReference reference) const