ServiceRegistration¶
-
template<class I1, class ...Interfaces>
class ServiceRegistration : public cppmicroservices::ServiceRegistrationBase¶ - #include <cppmicroservices/ServiceRegistration.h>
A registered service.
The framework returns a
ServiceRegistration
object when aBundleContext::RegisterService()
method invocation is successful. TheServiceRegistration
object is for the private use of the registering bundle and should not be shared with other bundles.The
ServiceRegistration
object may be used to update the properties of the service or to unregister the service.See also
- Template Parameters:
I1 – Class type of the first service interface
Interfaces – Template parameter pack containing zero or more service interfaces
Public Functions
-
inline ServiceRegistration()¶
Creates an invalid ServiceRegistration object.
You can use this object in boolean expressions and it will evaluate to
false
.
-
template<class Interface>
inline ServiceReference<Interface> GetReference() const¶ Returns a
ServiceReference
object for a service being registered.The
ServiceReference
object may be shared with other bundles.- Throws:
std::logic_error – If this
ServiceRegistration
object has already been unregistered or if it is invalid.- Returns:
ServiceReference
object.
-
inline ServiceReference<I1> GetReference() const¶
Returns a
ServiceReference
object for a service being registered.The
ServiceReference
object refers to the first interface type and may be shared with other bundles.- Throws:
std::logic_error – If this
ServiceRegistration
object has already been unregistered or if it is invalid.- Returns:
ServiceReference
object.
-
ServiceRegistrationBase &operator=(std::nullptr_t)¶
Releases any resources held or locked by this
ServiceRegistrationBase
and renders it invalid.- Returns:
This ServiceRegistrationBase object.
-
ServiceRegistrationBase &operator=(ServiceRegistrationBase const ®istration)¶
-
ServiceRegistrationBase &operator=(ServiceRegistrationBase &®istration) noexcept¶
-
class ServiceRegistrationBase¶
- #include <cppmicroservices/ServiceRegistrationBase.h>
A registered service.
The framework returns a
ServiceRegistrationBase
object when aBundleContext::RegisterService()
method invocation is successful. TheServiceRegistrationBase
object is for the private use of the registering bundle and should not be shared with other bundles.The
ServiceRegistrationBase
object may be used to update the properties of the service or to unregister the service.See also
Note
This class is provided as public API for low-level service management only. In almost all cases you should use the template ServiceRegistration instead.
Subclassed by cppmicroservices::ServiceRegistration< void >, cppmicroservices::ServiceRegistration< cppmicroservices::HttpServlet >, cppmicroservices::ServiceRegistration< I1, Interfaces >
Public Functions
-
ServiceRegistrationBase(ServiceRegistrationBase const ®)¶
-
ServiceRegistrationBase(ServiceRegistrationBase &®) noexcept¶
-
explicit operator bool() const¶
A boolean conversion operator converting this ServiceRegistrationBase object to
true
if it is valid and tofalse
otherwise.A ServiceRegistrationBase object is invalid if it was default-constructed or was invalidated by assigning 0 to it.
See also
- Returns:
true
if this ServiceRegistrationBase object is valid,false
otherwise.
-
ServiceRegistrationBase &operator=(std::nullptr_t)¶
Releases any resources held or locked by this
ServiceRegistrationBase
and renders it invalid.- Returns:
This ServiceRegistrationBase object.
-
~ServiceRegistrationBase()¶
-
ServiceReferenceBase GetReference(std::string const &interfaceId = std::string()) const¶
Returns a
ServiceReferenceBase
object for a service being registered.The
ServiceReferenceBase
object may be shared with other bundles.- Throws:
std::logic_error – If this
ServiceRegistrationBase
object has already been unregistered or if it is invalid.- Returns:
ServiceReference
object.
-
void SetProperties(ServiceProperties const &properties)¶
Updates the properties associated with a service.
The Constants::OBJECTCLASS and Constants::SERVICE_ID keys cannot be modified by this method. These values are set by the framework when the service is registered in the environment.
The following steps are taken to modify service properties:
The service’s properties are replaced with the provided properties.
A service event of type ServiceEvent::SERVICE_MODIFIED is fired.
- Parameters:
properties – The properties for this service. See
ServiceProperties
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 this method should be called again.- Throws:
std::logic_error – If this
ServiceRegistrationBase
object has already been unregistered or if it is invalid.std::invalid_argument – If
properties
contains case variants of the same key name or if the number of the keys ofproperties
exceeds the value returned by std::numeric_limits<int>::max().
-
void SetProperties(ServiceProperties &&properties)¶
-
void Unregister()¶
Unregisters a service.
Remove a
ServiceRegistrationBase
object from the framework service registry. AllServiceRegistrationBase
objects associated with thisServiceRegistrationBase
object can no longer be used to interact with the service once unregistration is complete.The following steps are taken to unregister a service:
The service is removed from the framework service registry so that it can no longer be obtained.
A service event of type ServiceEvent::SERVICE_UNREGISTERING is fired so that bundles using this service can release their use of the service. Once delivery of the service event is complete, the
ServiceRegistrationBase
objects for the service may no longer be used to get a service object for the service.For each bundle whose use count for this service is greater than zero:
The bundle’s use count for this service is set to zero.
If the service was registered with a ServiceFactory object, theServiceFactory::UngetService
method is called to release the service object for the bundle.
- Throws:
std::logic_error – If this
ServiceRegistrationBase
object has already been unregistered or if it is invalid.
-
bool operator<(ServiceRegistrationBase const &o) const¶
Compare two ServiceRegistrationBase objects.
If both ServiceRegistrationBase objects are valid, the comparison is done using the underlying ServiceReference object. Otherwise, this ServiceRegistrationBase object is less than the other object if and only if this object is invalid and the other object is valid.
- Parameters:
o – The ServiceRegistrationBase object to compare with.
- Returns:
true
if this ServiceRegistrationBase object is less than the other object.
-
bool operator==(ServiceRegistrationBase const ®istration) const¶
-
ServiceRegistrationBase &operator=(ServiceRegistrationBase const ®istration)¶
-
ServiceRegistrationBase &operator=(ServiceRegistrationBase &®istration) noexcept¶
Friends
- friend struct ::std::hash< ServiceRegistrationBase >
-
ServiceRegistrationBase(ServiceRegistrationBase const ®)¶
-
template<>
struct hash<cppmicroservices::ServiceRegistrationBase>¶ - #include <ServiceRegistrationBase.h>
<cppmicroservices/ServiceRegistrationBase.h>
Hash functor specialization for ServiceRegistrationBase objects.