The ServiceTracker class tracks services.
More...
#include <Trackers.h>
|
std::shared_ptr< I > | getHighestRankingService () |
| Get the current highest ranking service tracked by this tracker. More...
|
|
std::vector< std::shared_ptr< I > > | getServices () |
| Get a vector of all the currently found services for this tracker. More...
|
|
template<typename F > |
size_t | useServices (const F &f) |
| Applies the provided function to each service being tracked. More...
|
|
template<typename F > |
size_t | useServicesWithProperties (const F &f) |
| Applies the provided function to each service being tracked, along with its properties. More...
|
|
template<typename F > |
size_t | useServicesWithOwner (const F &f) |
| Applies the provided function to each service being tracked, along with its properties and owner bundle. More...
|
|
template<typename F > |
bool | useService (const F &f) |
| Applies the provided function to the highest ranking service being tracked. More...
|
|
template<typename F > |
bool | useServiceWithProperties (const F &f) |
| Applies the provided function to the highest ranking service being tracked, along with its properties. More...
|
|
template<typename F > |
bool | useServiceWithOwner (const F &f) |
| Applies the provided function to the highest ranking service being tracked, along with its properties and owner bundle. More...
|
|
| GenericServiceTracker (std::shared_ptr< celix_bundle_context_t > _cCtx, std::string _svcName, std::string _svcVersionRange, celix::Filter _filter) |
|
| ~GenericServiceTracker () override=default |
|
void | open () override |
|
const std::string & | getServiceName () const |
| The service name tracked by this service tracker. More...
|
|
const std::string & | getServiceRange () const |
| The service version range tracked by this service tracker. More...
|
|
const celix::Filter & | getFilter () const |
| The additional filter for services tracked by this service tracker. More...
|
|
std::size_t | getServiceCount () const |
| The nr of services currently tracked by this tracker. More...
|
|
| AbstractTracker (std::shared_ptr< celix_bundle_context_t > _cCtx) |
|
virtual | ~AbstractTracker () noexcept=default |
|
bool | isOpen () const |
| Check if the tracker is open (state == OPEN) More...
|
|
TrackerState | getState () const |
| Get the current state of the tracker. More...
|
|
void | close () |
| Close the tracker (of the state is not CLOSED or CLOSING). More...
|
|
void | wait () const |
| Wait until a service tracker is completely OPEN or CLOSED. More...
|
|
|
static std::shared_ptr< ServiceTracker< I > > | create (std::shared_ptr< celix_bundle_context_t > cCtx, std::string svcName, std::string svcVersionRange, celix::Filter filter, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> setCallbacks, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> addCallbacks, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> remCallbacks) |
| Creates a new service tracker and opens the tracker. More...
|
|
|
| ServiceTracker (std::shared_ptr< celix_bundle_context_t > _cCtx, std::string _svcName, std::string _svcVersionRange, celix::Filter _filter, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> _setCallbacks, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> _addCallbacks, std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)>> _remCallbacks) |
|
void | waitForExpiredSvcEntry (std::shared_ptr< SvcEntry > &entry) |
|
template<typename U > |
void | waitForExpired (std::weak_ptr< U > observe, long svcId, const char *objName) |
|
void | invokeUpdateCallbacks () |
|
void | waitIfAble () const |
| Wait (if not on the Celix event thread) for the tracker to be OPEN or CLOSED. More...
|
|
|
static std::shared_ptr< SvcEntry > | createEntry (void *voidSvc, const celix_properties_t *cProps, const celix_bundle_t *cBnd) |
|
template<typename T > |
static std::function< void(T *)> | delCallback () |
|
|
const std::chrono::milliseconds | warningTimoutForNonExpiredSvcObject {1000} |
|
const std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> > | setCallbacks |
|
const std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> > | addCallbacks |
|
const std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> > | remCallbacks |
|
const std::vector< std::function< void(const std::vector< std::shared_ptr< I >>)> > | updateCallbacks {} |
|
const std::vector< std::function< void(const std::vector< std::pair< std::shared_ptr< I >, std::shared_ptr< const celix::Properties >>>)> > | updateWithPropertiesCallbacks {} |
|
const std::vector< std::function< void(const std::vector< std::tuple< std::shared_ptr< I >, std::shared_ptr< const celix::Properties >, std::shared_ptr< const celix::Bundle >>>)> > | updateWithOwnerCallbacks {} |
|
std::mutex | mutex {} |
|
std::set< std::shared_ptr< SvcEntry >, SvcEntryCompare > | entries {} |
|
std::unordered_map< long, std::shared_ptr< SvcEntry > > | cachedEntries {} |
|
std::shared_ptr< SvcEntry > | highestRankingServiceEntry {} |
|
const std::string | svcName |
|
const std::string | svcVersionRange |
|
const celix::Filter | filter |
|
celix_service_tracking_options | opts {} |
|
std::atomic< size_t > | svcCount {0} |
|
const std::shared_ptr< celix_bundle_context_t > | cCtx |
|
std::mutex | mutex {} |
|
long | trkId {-1L} |
|
TrackerState | state {TrackerState::CLOSED} |
|
template<typename I>
class celix::ServiceTracker< I >
The ServiceTracker class tracks services.
Tracking in this case means that the ServiceTracker maintains and informs
- through the use of callbacks - a set services matching the service tracking criteria (matches the service name, fits int the optional service version range and matches with the LDAP filter).
- Note
- Thread safe.
- Template Parameters
-
I | The service type to track |
◆ ServiceTracker()
template<typename I >
celix::ServiceTracker< I >::ServiceTracker |
( |
std::shared_ptr< celix_bundle_context_t > |
_cCtx, |
|
|
std::string |
_svcName, |
|
|
std::string |
_svcVersionRange, |
|
|
celix::Filter |
_filter, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
_setCallbacks |
, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
_addCallbacks |
, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
_remCallbacks |
|
|
) |
| |
|
inlineprotected |
◆ create()
template<typename I >
static std::shared_ptr<ServiceTracker<I> > celix::ServiceTracker< I >::create |
( |
std::shared_ptr< celix_bundle_context_t > |
cCtx, |
|
|
std::string |
svcName, |
|
|
std::string |
svcVersionRange, |
|
|
celix::Filter |
filter, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
setCallbacks |
, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
addCallbacks |
, |
|
|
std::vector< std::function< void(const std::shared_ptr< I > &, const std::shared_ptr< const celix::Properties > &, const std::shared_ptr< const celix::Bundle > &)> |
, |
|
|
remCallbacks |
|
|
) |
| |
|
inlinestatic |
Creates a new service tracker and opens the tracker.
- Parameters
-
cCtx | The c bundle context. |
svcName | The service name to filter for. |
svcVersionRange | The optional service range to filter for. |
filter | The optional (and additional with respect to svcName and svcVersionRange) LDAP filter to filter for. |
setCallbacks | The callback which is called when a new service needs te be set which matches the trackers filter. |
addCallbacks | The callback which is called when a new service is added to the Celix framework which matches the trackers filter. |
remCallbacks | The callback which is called when a service is removed from the Celix framework which matches the trackers filter. |
- Returns
- The new service tracker as shared ptr.
- Exceptions
-
◆ createEntry()
template<typename I >
static std::shared_ptr<SvcEntry> celix::ServiceTracker< I >::createEntry |
( |
void * |
voidSvc, |
|
|
const celix_properties_t * |
cProps, |
|
|
const celix_bundle_t * |
cBnd |
|
) |
| |
|
inlinestaticprotected |
◆ getHighestRankingService()
Get the current highest ranking service tracked by this tracker.
Note that this can be a nullptr if there are no services found.
The return shared ptr should not be stored and only be used shortly, otherwise the framework can hangs during service un-registrations.
◆ getServices()
Get a vector of all the currently found services for this tracker.
This vector is ordered by service ranking (descending, highest ranking service first).
The returned result not be stored and only be used shortly, otherwise the framework can hangs during service un-registrations.
◆ invokeUpdateCallbacks()
◆ useService()
template<typename I >
template<typename F >
Applies the provided function to the highest ranking service being tracked.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to the highest ranking service. |
- Returns
- True if the function was applied to a service, false otherwise.
◆ useServices()
template<typename I >
template<typename F >
Applies the provided function to each service being tracked.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to each service. |
- Returns
- The number of services to which the function was applied.
◆ useServicesWithOwner()
template<typename I >
template<typename F >
Applies the provided function to each service being tracked, along with its properties and owner bundle.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc, const celix::Properties& props, const celix::Bundle& bnd) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to each service. |
- Returns
- The number of services to which the function was applied.
◆ useServicesWithProperties()
template<typename I >
template<typename F >
Applies the provided function to each service being tracked, along with its properties.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc, const celix::Properties& props) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to each service. |
- Returns
- The number of services to which the function was applied.
◆ useServiceWithOwner()
template<typename I >
template<typename F >
Applies the provided function to the highest ranking service being tracked, along with its properties and owner bundle.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc, const celix::Properties& props, const celix::Bundle& bnd) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to the highest ranking service. |
- Returns
- True if the function was applied to a service, false otherwise.
◆ useServiceWithProperties()
template<typename I >
template<typename F >
Applies the provided function to the highest ranking service being tracked, along with its properties.
- Template Parameters
-
F | A function or callable object type. The function signature should be equivalent to the following: void func(I& svc, const celix::Properties& props) where I is the service type being tracked. |
- Parameters
-
f | The function or callable object to apply to the highest ranking service. |
- Returns
- True if the function was applied to a service, false otherwise.
◆ waitForExpired()
template<typename I >
template<typename U >
void celix::ServiceTracker< I >::waitForExpired |
( |
std::weak_ptr< U > |
observe, |
|
|
long |
svcId, |
|
|
const char * |
objName |
|
) |
| |
|
inlineprotected |
◆ waitForExpiredSvcEntry()
◆ addCallbacks
template<typename I >
const std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)> > celix::ServiceTracker< I >::addCallbacks |
|
protected |
◆ cachedEntries
◆ entries
◆ highestRankingServiceEntry
◆ mutex
◆ remCallbacks
template<typename I >
const std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)> > celix::ServiceTracker< I >::remCallbacks |
|
protected |
◆ setCallbacks
template<typename I >
const std::vector<std::function<void(const std::shared_ptr<I>&, const std::shared_ptr<const celix::Properties>&, const std::shared_ptr<const celix::Bundle>&)> > celix::ServiceTracker< I >::setCallbacks |
|
protected |
◆ updateCallbacks
template<typename I >
const std::vector<std::function<void(const std::vector<std::shared_ptr<I>>)> > celix::ServiceTracker< I >::updateCallbacks {} |
|
protected |
◆ updateWithOwnerCallbacks
template<typename I >
const std::vector<std::function<void(const std::vector<std::tuple<std::shared_ptr<I>, std::shared_ptr<const celix::Properties>, std::shared_ptr<const celix::Bundle>>>)> > celix::ServiceTracker< I >::updateWithOwnerCallbacks {} |
|
protected |
◆ updateWithPropertiesCallbacks
template<typename I >
const std::vector<std::function<void(const std::vector<std::pair<std::shared_ptr<I>, std::shared_ptr<const celix::Properties>>>)> > celix::ServiceTracker< I >::updateWithPropertiesCallbacks {} |
|
protected |
◆ warningTimoutForNonExpiredSvcObject
The documentation for this class was generated from the following file: