ServiceListenerHook¶
-
struct 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(std::vector<ListenerInfo> const &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 of
ListenerInfo
objects for newly added service listeners which are now listening to service events.
-
virtual void Removed(std::vector<ListenerInfo> const &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 of
ListenerInfo
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(ListenerInfo const &other)¶
-
~ListenerInfo()¶
-
ListenerInfo &operator=(ListenerInfo const &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.
- Returns:
true
if this listener object is valid,false
otherwise.
-
BundleContext GetBundleContext() const¶
Return the context of the bundle which added the listener.
- Returns:
The context of the bundle which added the listener.
-
std::string GetFilter() const¶
Return the filter string with which the listener was added.
- Returns:
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
ServiceListenerHook
s can be made before added notification if two threads are racing to add and remove the same service listener. BecauseServiceListenerHook
s 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.- Returns:
false
if the listener has not been been removed,true
otherwise.
-
bool operator==(ListenerInfo const &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
.- Parameters:
other – The object to compare against this
ListenerInfo
.- Returns:
true
if the other object is aListenerInfo
object and both objects refer to the same listener for a given addition and removal life cycle.
Friends
- friend struct ::std::hash< ServiceListenerHook::ListenerInfo >
-
ListenerInfo()¶
-
virtual ~ServiceListenerHook()¶
-
template<>
struct hash<cppmicroservices::ServiceListenerHook::ListenerInfo>¶ - #include <ServiceListenerHook.h>
<cppmicroservices/ServiceListenerHook.h>
Hash functor specialization for ServiceListenerHook::ListenerInfo objects.