CppMicroServices

C++ Micro Services: ServiceReference< S > Class Template Reference
ServiceReference< S > Class Template Reference

A reference to a service. More...

Inheritance diagram for ServiceReference< S >:
Collaboration diagram for ServiceReference< S >:

Public Types

typedef S ServiceType
 

Public Member Functions

 ServiceReference ()
 Creates an invalid ServiceReference object. More...
 
 ServiceReference (const ServiceReferenceBase &base)
 
- Public Member Functions inherited from ServiceReferenceBase
 ServiceReferenceBase (const ServiceReferenceBase &ref)
 
 operator bool_type () const
 Converts this ServiceReferenceBase instance into a boolean expression. More...
 
ServiceReferenceBaseoperator= (std::nullptr_t)
 Releases any resources held or locked by this ServiceReferenceBase and renders it invalid. More...
 
 ~ServiceReferenceBase ()
 
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 ServiceReferenceBase 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 ServiceReferenceBase object. More...
 
ModuleGetModule () const
 Returns the module that registered the service referenced by this ServiceReferenceBase object. More...
 
void GetUsingModules (std::vector< Module * > &modules) const
 Returns the modules that are using the service referenced by this ServiceReferenceBase object. More...
 
std::string GetInterfaceId () const
 Returns the interface identifier this ServiceReferenceBase object is bound to. More...
 
bool IsConvertibleTo (const std::string &interfaceid) const
 Checks wether this ServiceReferenceBase object can be converted to another ServiceReferenceBase object, which will be bound to the given interface identifier. More...
 
bool operator< (const ServiceReferenceBase &reference) const
 Compares this ServiceReferenceBase with the specified ServiceReferenceBase for order. More...
 
bool operator== (const ServiceReferenceBase &reference) const
 
ServiceReferenceBaseoperator= (const ServiceReferenceBase &reference)
 

Detailed Description

template<class S>
class ServiceReference< S >

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.

Template Parameters
SThe class type of the service interface
See also
ModuleContext::GetServiceReference
ModuleContext::GetServiceReferences
ModuleContext::GetService
Remarks
This class is thread safe.

Member Typedef Documentation

template<class S>
typedef S ServiceReference< S >::ServiceType

Constructor & Destructor Documentation

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

Creates an invalid ServiceReference object.

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