ServiceListenerHook¶
-
struct
cppmicroservices::
ServiceListenerHook
¶ - #include <cppmicroservices/ServiceListenerHook.h>
Service Listener Hook Service.
Bundles registering this service will be called during service listener addition and removal.
- Remark
- Implementations of this interface are required to be thread-safe.
Public Functions
-
virtual
~ServiceListenerHook
()¶
-
virtual void
Added
(const std::vector<ListenerInfo> &listeners) = 0¶ Added listeners hook method.
This method is called to provide the hook implementation with information on newly added service listeners. This method will be called as service listeners are added while this hook is registered. Also, immediately after registration of this hook, this method will be called to provide the current collection of service listeners which had been added prior to the hook being registered.
- Parameters
listeners
: A collection ofListenerInfo
objects for newly added service listeners which are now listening to service events.
-
virtual void
Removed
(const std::vector<ListenerInfo> &listeners) = 0¶ Removed listeners hook method.
This method is called to provide the hook implementation with information on newly removed service listeners. This method will be called as service listeners are removed while this hook is registered.
- Parameters
listeners
: A collection ofListenerInfo
objects for newly removed service listeners which are no longer listening to service events.
-
struct
ListenerInfo
¶ - #include <cppmicroservices/ServiceListenerHook.h>
Information about a Service Listener.
This class describes the bundle which added the Service Listener and the filter with which it was added.
- Remark
- This class is not intended to be implemented by clients.
Public Functions
-
ListenerInfo
()¶
-
ListenerInfo
(const ListenerInfo &other)¶
-
~ListenerInfo
()¶
-
ListenerInfo &
operator=
(const ListenerInfo &other)¶
-
bool
IsNull
() const¶ Can be used to check if this ListenerInfo instance is valid, or if it has been constructed using the default constructor.
- Return
true
if this listener object is valid,false
otherwise.
-
BundleContext
GetBundleContext
() const¶ Return the context of the bundle which added the listener.
- Return
- The context of the bundle which added the listener.
-
std::string
GetFilter
() const¶ Return the filter string with which the listener was added.
- Return
- The filter string with which the listener was added. This may be empty if the listener was added without a filter.
-
bool
IsRemoved
() const¶ Return the state of the listener for this addition and removal life cycle.
Initially this method will return
false
indicating the listener has been added but has not been removed. After the listener has been removed, this method must always returnstrue
.There is an extremely rare case in which removed notification to ServiceListenerHooks can be made before added notification if two threads are racing to add and remove the same service listener. Because ServiceListenerHooks are called synchronously during service listener addition and removal, the CppMicroServices library cannot guarantee in-order delivery of added and removed notification for a given service listener. This method can be used to detect this rare occurrence.
- Return
false
if the listener has not been been removed,true
otherwise.
-
bool
operator==
(const ListenerInfo &other) const¶ Compares this
ListenerInfo
to anotherListenerInfo
.Two
ListenerInfos
are equal if they refer to the same listener for a given addition and removal life cycle. If the same listener is added again, it will have a differentListenerInfo
which is not equal to thisListenerInfo
.- Return
true
if the other object is aListenerInfo
object and both objects refer to the same listener for a given addition and removal life cycle.- Parameters
other
: The object to compare against thisListenerInfo
.
Friends
-
friend
gr_servicelistenerhook::::std::hash< ServiceListenerHook::ListenerInfo >
-
template<>
structstd::
hash
<cppmicroservices::ServiceListenerHook::ListenerInfo>¶ - #include <cppmicroservices/ServiceListenerHook.h>
Hash functor specialization for ServiceListenerHook::ListenerInfo objects.