ServiceReference¶
-
typedef ServiceReference<void> ServiceReferenceU¶
A service reference of unknown type, which is not bound to any interface identifier.
- US_Framework_EXPORT ServiceReferenceU ServiceReferenceFromService (std::shared_ptr< void > const &s)
A method to retrieve a
ServiceObject’s originalServiceReference<void>
A method to retrieve a
ServiceObject<T>’s originalServiceReference- Template Parameters:
T – The class type of the
ServiceObjectU – The class type of the
ServiceReference. Defaults toTif not specified.
-
std::ostream &operator<<(std::ostream &os, ServiceReferenceBase const &serviceRef)¶
Writes a string representation of
serviceRefto the streamos.
-
template<class S>
class ServiceReference : public cppmicroservices::ServiceReferenceBase¶ - #include <cppmicroservices/ServiceReference.h>
A reference to a service.
The framework returns
ServiceReferenceobjects from theBundleContext::GetServiceReferenceandBundleContext::GetServiceReferencesmethods.A
ServiceReferenceobject may be shared between bundles 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
ServiceRegistrationobject and may have multiple, distinctServiceReferenceobjects referring to it.ServiceReferenceobjects associated with aServiceRegistrationare considered equal (more specifically, theiroperator==()method will returntruewhen compared).If the same service object is registered multiple times,
ServiceReferenceobjects associated with differentServiceRegistrationobjects are not equal.See also
See also
See also
- Template Parameters:
S – The class type of the service interface
Public Functions
-
inline ServiceReference()¶
Creates an invalid ServiceReference object.
You can use this object in boolean expressions and it will evaluate to
false.
-
ServiceReference(ServiceReference const&) = default¶
-
ServiceReference &operator=(ServiceReference const&) = default¶
-
inline ServiceReference(ServiceReferenceBase const &base)¶
-
ServiceReferenceBase &operator=(std::nullptr_t)¶
Releases any resources held or locked by this
ServiceReferenceBaseand renders it invalid.
-
ServiceReferenceBase &operator=(ServiceReferenceBase const &reference)¶
-
bool operator==(ServiceReferenceBase const &reference) const¶
-
class ServiceReferenceBase¶
- #include <cppmicroservices/ServiceReferenceBase.h>
A reference to a service.
Note
This class is provided as public API for low-level service queries only. In almost all cases you should use the template ServiceReference instead.
Subclassed by cppmicroservices::ServiceReference< void >, cppmicroservices::ServiceReference< cppmicroservices::service::cm::ConfigurationAdmin >, cppmicroservices::ServiceReference< S >
Public Functions
-
ServiceReferenceBase(ServiceReferenceBase const &ref)¶
-
explicit operator bool() const¶
Converts this ServiceReferenceBase 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 returnstrue.
-
ServiceReferenceBase &operator=(std::nullptr_t)¶
Releases any resources held or locked by this
ServiceReferenceBaseand renders it invalid.
-
~ServiceReferenceBase()¶
-
Any GetProperty(std::string const &key) const¶
Returns the property value to which the specified property key is mapped in the properties
ServicePropertiesobject of the service referenced by thisServiceReferenceBaseobject.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:
key – The 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 GetPropertyKeys(std::vector<std::string> &keys) const¶
Returns a list of the keys in the
ServicePropertiesobject of the service referenced by thisServiceReferenceBaseobject.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.
- Deprecated:
Since 3.0, use GetPropertyKeys() instead.
- Parameters:
keys – A vector being filled with the property keys.
-
std::vector<std::string> GetPropertyKeys() const¶
Returns a list of the keys in the
ServicePropertiesobject of the service referenced by thisServiceReferenceBaseobject.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.
- Returns:
A vector being filled with the property keys.
-
Bundle GetBundle() const¶
Returns the bundle that registered the service referenced by this
ServiceReferenceBaseobject.This method must return an invalid bundle when the service has been unregistered. This can be used to determine if the service has been unregistered.
See also
BundleContext::RegisterService(const InterfaceMap&, const ServiceProperties&)
See also
- Returns:
The bundle that registered the service referenced by this
ServiceReferenceBaseobject; an invalid bundle if that service has already been unregistered.
-
std::vector<Bundle> GetUsingBundles() const¶
Returns the bundles that are using the service referenced by this
ServiceReferenceBaseobject.Specifically, this method returns the bundles whose usage count for that service is greater than zero.
- Returns:
A list of bundles whose usage count for the service referenced by this
ServiceReferenceBaseobject is greater than zero.
-
std::string GetInterfaceId() const¶
Returns the interface identifier this ServiceReferenceBase object is bound to.
A default constructed ServiceReferenceBase object is not bound to any interface identifier and calling this method will return an empty string.
- Returns:
The interface identifier for this ServiceReferenceBase object.
-
bool IsConvertibleTo(std::string const &interfaceid) const¶
Checks whether this ServiceReferenceBase object can be converted to another ServiceReferenceBase object, which will be bound to the given interface identifier.
ServiceReferenceBase objects can be converted if the underlying service implementation was registered under multiple service interfaces.
- Parameters:
interfaceid –
- Returns:
trueif this ServiceReferenceBase object can be converted,falseotherwise.
-
bool operator<(ServiceReferenceBase const &reference) const¶
Compares this
ServiceReferenceBasewith the specifiedServiceReferenceBasefor order.If this
ServiceReferenceBaseand the specifiedServiceReferenceBasehave the same service id they are equal. ThisServiceReferenceBaseis less than the specifiedServiceReferenceBaseif it has a lowerservice rankingand greater if it has a higher service ranking. Otherwise, if thisServiceReferenceBaseand the specifiedServiceReferenceBasehave the sameservice ranking, thisServiceReferenceBaseis less than the specifiedServiceReferenceBaseif it has a higherservice idand greater if it has a lower service id.- Parameters:
reference – The
ServiceReferenceBaseto be compared.- Returns:
Returns a false or true if this
ServiceReferenceBaseis less than or greater than the specifiedServiceReferenceBase.
-
bool operator==(ServiceReferenceBase const &reference) const¶
-
ServiceReferenceBase &operator=(ServiceReferenceBase const &reference)¶
Friends
- friend struct ::std::hash< ServiceReferenceBase >
-
ServiceReferenceBase(ServiceReferenceBase const &ref)¶
-
template<>
struct hash<cppmicroservices::ServiceReferenceBase>¶ - #include <ServiceReferenceBase.h>
<cppmicroservices/ServiceReferenceBase.h>
Hash functor specialization for ServiceReferenceBase objects.