Apache Celix
2.3.0
An implementation of the OSGi specification adapted to C and C++
|
The ServiceTracker class tracks services. More...
#include <Trackers.h>
Classes | |
struct | SvcEntry |
struct | SvcEntryCompare |
Public Member Functions | |
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... | |
Public Member Functions inherited from celix::GenericServiceTracker | |
GenericServiceTracker (std::shared_ptr< celix_bundle_context_t > _cCtx, std::string_view _svcName, std::string_view _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... | |
Public Member Functions inherited from celix::AbstractTracker | |
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 Public Member Functions | |
static std::shared_ptr< ServiceTracker< I > > | create (std::shared_ptr< celix_bundle_context_t > cCtx, std::string_view svcName, std::string_view 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... | |
Protected Member Functions | |
ServiceTracker (std::shared_ptr< celix_bundle_context_t > _cCtx, std::string_view _svcName, std::string_view _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 () |
Protected Member Functions inherited from celix::AbstractTracker | |
void | waitIfAble () const |
Wait (if not on the Celix event thread) for the tracker to be OPEN or CLOSED. More... | |
Static Protected Member Functions | |
static std::shared_ptr< SvcEntry > | createEntry (void *voidSvc, const celix_properties_t *cProps, const celix_bundle_t *cBnd) |
Static Protected Member Functions inherited from celix::AbstractTracker | |
template<typename T > | |
static std::function< void(T *)> | delCallback () |
Protected Attributes | |
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 {} |
Protected Attributes inherited from celix::GenericServiceTracker | |
const std::string | svcName |
const std::string | svcVersionRange |
const celix::Filter | filter |
celix_service_tracking_options | opts {} |
std::atomic< size_t > | svcCount {0} |
Protected Attributes inherited from celix::AbstractTracker | |
const std::shared_ptr< celix_bundle_context_t > | cCtx |
std::mutex | mutex {} |
long | trkId {-1L} |
TrackerState | state {TrackerState::CLOSED} |
The ServiceTracker class tracks services.
Tracking in this case means that the ServiceTracker maintains and informs
I | The service type to track |
|
inlineprotected |
|
inlinestatic |
Creates a new service tracker and opens the tracker.
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. |
celix::Exception |
|
inlinestaticprotected |
|
inline |
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.
|
inline |
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.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |