Apache Celix
latest
Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming.
|
Go to the documentation of this file.
28 #include <unordered_map>
32 #include "celix_utils.h"
36 #include "celix/Properties.h"
37 #include "celix/Utils.h"
40 #include "celix/Filter.h"
76 cCtx{std::move(_cCtx)} {}
84 std::lock_guard<std::mutex> lck{
mutex};
92 std::lock_guard<std::mutex> lck{
mutex};
103 long localTrkId = -1;
105 std::lock_guard<std::mutex> lck{
mutex};
113 if (localTrkId >= 0) {
116 std::lock_guard<std::mutex> lck{
mutex};
130 virtual void open() = 0;
138 bool needWaitOpening =
false;
139 bool needWaitClosing =
false;
142 std::lock_guard<std::mutex> lck{
mutex};
145 needWaitOpening =
true;
147 needWaitClosing =
true;
150 if (needWaitOpening) {
153 if (needWaitClosing) {
170 return [](T *tracker) {
190 "celix::AbstractTracker delete callback",
202 const std::shared_ptr<celix_bundle_context_t>
cCtx;
221 std::string _svcVersionRange, celix::Filter _filter) :
AbstractTracker{std::move(_cCtx)},
svcName{std::move(_svcName)},
223 setupServiceTrackerOptions();
232 std::lock_guard<std::mutex> lck{
mutex};
276 void setupServiceTrackerOptions() {
277 opts.trackerCreatedCallbackData =
this;
281 std::lock_guard<std::mutex> callbackLock{trk->
mutex};
315 static std::shared_ptr<ServiceTracker<I>>
create(
316 std::shared_ptr<celix_bundle_context_t>
cCtx,
320 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,
321 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,
322 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) {
323 auto tracker = std::shared_ptr<ServiceTracker<I>>{
332 AbstractTracker::delCallback<ServiceTracker<I>>()};
347 std::shared_ptr<I> result{};
348 std::lock_guard<std::mutex> lck{
mutex};
366 std::vector<std::shared_ptr<I>> result{};
367 std::lock_guard<std::mutex> lck{
mutex};
368 result.reserve(
entries.size());
370 result.push_back(e->svc);
386 return this->
template useServicesInternal(
401 return this->
template useServicesInternal(
417 return this->
template useServicesInternal(
432 return this->
template useServiceInternal(
447 return this->
template useServiceInternal(
463 return this->
template useServiceInternal(
468 SvcEntry(
long _svcId,
long _svcRanking, std::shared_ptr<I> _svc,
469 std::shared_ptr<const celix::Properties> _properties,
470 std::shared_ptr<const celix::Bundle> _owner) : svcId(_svcId), svcRanking(_svcRanking),
471 svc(std::move(_svc)),
472 properties(std::move(_properties)),
473 owner(std::move(_owner)) {}
478 std::shared_ptr<const celix::Bundle>
owner;
482 ServiceTracker(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _svcName,
483 std::string _svcVersionRange, celix::Filter _filter,
484 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,
485 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,
486 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) :
487 GenericServiceTracker{std::move(_cCtx), std::move(_svcName), std::move(_svcVersionRange), std::move(_filter)},
491 setupServiceTrackerOptions();
494 static std::shared_ptr<SvcEntry>
createEntry(
void* voidSvc,
const celix_properties_t* cProps,
const celix_bundle_t* cBnd) {
495 long svcId = celix_properties_getAsLong(cProps, CELIX_FRAMEWORK_SERVICE_ID, -1L);
496 long svcRanking = celix_properties_getAsLong(cProps, CELIX_FRAMEWORK_SERVICE_RANKING, 0);
497 auto svc = std::shared_ptr<I>{
static_cast<I*
>(voidSvc), [](I*){}};
498 auto props = std::make_shared<const celix::Properties>(celix::Properties::wrap(cProps));
499 auto owner = std::make_shared<celix::Bundle>(
const_cast<celix_bundle_t*
>(cBnd));
500 return std::make_shared<SvcEntry>(svcId, svcRanking, svc, props, owner);
505 std::weak_ptr<void> svcObserve = entry->svc;
506 std::weak_ptr<const celix::Properties> propsObserve = entry->properties;
507 std::weak_ptr<const celix::Bundle> ownerObserve = entry->owner;
508 entry->svc =
nullptr;
509 entry->properties =
nullptr;
510 entry->owner =
nullptr;
513 waitForExpired(ownerObserve, entry->svcId,
"service bundle (owner)");
519 auto start = std::chrono::steady_clock::now();
520 while (!observe.expired()) {
521 auto now = std::chrono::steady_clock::now();
522 auto durationInMilli = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
524 celix_bundleContext_log(
cCtx.get(), CELIX_LOG_LEVEL_WARNING,
"Cannot remove %s associated with service.id %li, because it is still in use. Current shared_ptr use count is %i\n", objName, svcId, (
int)observe.use_count());
527 std::this_thread::sleep_for(std::chrono::milliseconds{50});
533 std::vector<std::shared_ptr<I>> updateVector{};
535 std::lock_guard<std::mutex> lck{
mutex};
536 updateVector.reserve(
entries.size());
537 for (
const auto &entry :
entries) {
538 updateVector.push_back(entry->svc);
546 std::vector<std::pair<std::shared_ptr<I>, std::shared_ptr<const celix::Properties>>> updateVector{};
547 updateVector.reserve(
entries.size());
549 std::lock_guard<std::mutex> lck{
mutex};
550 for (
const auto &entry :
entries) {
551 updateVector.emplace_back(entry->svc, entry->properties);
559 std::vector<std::tuple<std::shared_ptr<I>, std::shared_ptr<const celix::Properties>, std::shared_ptr<const celix::Bundle>>> updateVector{};
560 updateVector.reserve(
entries.size());
562 std::lock_guard<std::mutex> lck{
mutex};
563 for (
const auto &entry :
entries) {
564 updateVector.emplace_back(entry->svc, entry->properties, entry->owner);
575 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;
576 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;
577 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;
580 const std::vector<std::function<void(
const std::vector<std::shared_ptr<I>>)>>
updateCallbacks{};
581 const std::vector<std::function<void(
const std::vector<std::pair<std::shared_ptr<I>, std::shared_ptr<const celix::Properties>>>)>>
updateWithPropertiesCallbacks{};
582 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{};
585 bool operator() (
const std::shared_ptr<SvcEntry>& a,
const std::shared_ptr<SvcEntry>& b)
const {
586 int cmp = celix_utils_compareServiceIdsAndRanking(a->svcId, a->svcRanking, b->svcId, b->svcRanking);
597 void setupServiceTrackerOptions() {
601 opts.callbackHandle =
this;
602 opts.
addWithOwner = [](
void *handle,
void *voidSvc,
const celix_properties_t* cProps,
const celix_bundle_t* cBnd) {
606 std::lock_guard<std::mutex> lck{tracker->mutex};
607 tracker->entries.insert(entry);
608 tracker->cachedEntries[entry->svcId] = entry;
610 tracker->
svcCount.fetch_add(1, std::memory_order_relaxed);
611 for (
const auto& cb : tracker->addCallbacks) {
612 cb(entry->svc, entry->properties, entry->owner);
614 tracker->invokeUpdateCallbacks();
616 opts.
removeWithOwner = [](
void *handle,
void*,
const celix_properties_t* cProps,
const celix_bundle_t*) {
617 auto tracker =
static_cast<ServiceTracker<I>*
>(handle);
618 long svcId = celix_properties_getAsLong(cProps, CELIX_FRAMEWORK_SERVICE_ID, -1L);
619 std::shared_ptr<SvcEntry> entry{};
621 std::lock_guard<std::mutex> lck{tracker->
mutex};
622 auto it = tracker->cachedEntries.find(svcId);
623 assert(it != tracker->cachedEntries.end());
626 tracker->entries.erase(entry);
628 for (
const auto& cb : tracker->remCallbacks) {
629 cb(entry->svc, entry->properties, entry->owner);
631 tracker->invokeUpdateCallbacks();
632 tracker->svcCount.fetch_sub(1, std::memory_order_relaxed);
633 tracker->waitForExpiredSvcEntry(entry);
635 opts.
setWithOwner = [](
void *handle,
void *voidSvc,
const celix_properties_t *cProps,
const celix_bundle_t *cBnd) {
636 auto tracker =
static_cast<ServiceTracker<I>*
>(handle);
637 std::unique_lock<std::mutex> lck{tracker->mutex};
638 auto prevEntry = tracker->highestRankingServiceEntry;
640 tracker->highestRankingServiceEntry =
createEntry(voidSvc, cProps, cBnd);
642 tracker->highestRankingServiceEntry =
nullptr;
644 for (
const auto& cb : tracker->setCallbacks) {
645 if (tracker->highestRankingServiceEntry) {
646 auto& e = tracker->highestRankingServiceEntry;
647 cb(e->svc, e->properties, e->owner);
649 cb(
nullptr,
nullptr,
nullptr);
653 tracker->waitForExpiredSvcEntry(prevEntry);
658 size_t useServicesInternal(
const F& f) {
660 std::lock_guard<std::mutex> lck{
mutex};
665 f(svc, props, owner);
672 bool useServiceInternal(
const F& f) {
673 std::lock_guard<std::mutex> lck{
mutex};
678 f(svc, props, owner);
702 static std::shared_ptr<BundleTracker>
create(
703 std::shared_ptr<celix_bundle_context_t>
cCtx,
704 bool includeFrameworkBundle,
705 std::vector<std::function<
void(
const celix::Bundle&)>> onInstallCallbacks,
706 std::vector<std::function<
void(
const celix::Bundle&)>> onStartCallbacks,
707 std::vector<std::function<
void(
const celix::Bundle&)>> onStopCallbacks) {
709 auto tracker = std::shared_ptr<BundleTracker>{
712 includeFrameworkBundle,
713 std::move(onInstallCallbacks),
714 std::move(onStartCallbacks),
715 std::move(onStopCallbacks)},
716 AbstractTracker::delCallback<BundleTracker>()};
725 std::lock_guard<std::mutex> lck{
mutex};
737 std::shared_ptr<celix_bundle_context_t> _cCtx,
738 bool _includeFrameworkBundle,
739 std::vector<std::function<
void(
const celix::Bundle&)>> _onInstallCallbacks,
740 std::vector<std::function<
void(
const celix::Bundle&)>> _onStartCallbacks,
741 std::vector<std::function<
void(
const celix::Bundle&)>> _onStopCallbacks) :
743 includeFrameworkBundle{_includeFrameworkBundle},
744 onInstallCallbacks{std::move(_onInstallCallbacks)},
745 onStartCallbacks{std::move(_onStartCallbacks)},
746 onStopCallbacks{std::move(_onStopCallbacks)} {
749 opts.includeFrameworkBundle = includeFrameworkBundle;
750 opts.callbackHandle =
this;
751 opts.
onInstalled = [](
void *handle,
const celix_bundle_t *cBnd) {
752 auto tracker =
static_cast<BundleTracker *
>(handle);
754 for (
const auto& cb : tracker->onInstallCallbacks) {
758 opts.
onStarted = [](
void *handle,
const celix_bundle_t *cBnd) {
759 auto tracker =
static_cast<BundleTracker *
>(handle);
761 for (
const auto& cb : tracker->onStartCallbacks) {
765 opts.
onStopped = [](
void *handle,
const celix_bundle_t *cBnd) {
766 auto tracker =
static_cast<BundleTracker *
>(handle);
768 for (
const auto& cb : tracker->onStopCallbacks) {
772 opts.trackerCreatedCallbackData =
this;
774 auto* trk =
static_cast<BundleTracker*
>(data);
775 std::lock_guard<std::mutex> callbackLock{trk->mutex};
780 const bool includeFrameworkBundle;
781 const std::vector<std::function<void(
const celix::Bundle&)>> onInstallCallbacks;
782 const std::vector<std::function<void(
const celix::Bundle&)>> onStartCallbacks;
783 const std::vector<std::function<void(
const celix::Bundle&)>> onStopCallbacks;
829 static std::shared_ptr<MetaTracker>
create(
830 std::shared_ptr<celix_bundle_context_t>
cCtx,
831 std::string serviceName,
834 auto tracker = std::shared_ptr<MetaTracker>{
837 std::move(serviceName),
838 std::move(onTrackerCreated),
839 std::move(onTrackerDestroyed)},
840 AbstractTracker::delCallback<MetaTracker>()};
849 std::lock_guard<std::mutex> lck{
mutex};
856 serviceName.empty() ?
nullptr : serviceName.c_str(),
857 static_cast<void*
>(
this),
859 auto *trk = static_cast<MetaTracker *>(handle);
860 std::string svcName = cInfo->serviceName == nullptr ?
"" : cInfo->serviceName;
861 ServiceTrackerInfo info{svcName, celix::Filter::wrap(cInfo->filter), cInfo->bundleId};
862 for (
const auto& cb : trk->onTrackerCreated) {
868 std::string svcName = cInfo->serviceName ==
nullptr ?
"" : cInfo->serviceName;
869 ServiceTrackerInfo info{svcName, celix::Filter::wrap(cInfo->filter), cInfo->bundleId};
870 for (
const auto& cb : trk->onTrackerDestroyed) {
874 static_cast<void*
>(
this),
877 std::lock_guard<std::mutex> callbackLock{trk->
mutex};
888 std::shared_ptr<celix_bundle_context_t> _cCtx,
889 std::string _serviceName,
890 std::vector<std::function<
void(
const ServiceTrackerInfo&)>> _onTrackerCreated,
891 std::vector<std::function<
void(
const ServiceTrackerInfo&)>> _onTrackerDestroyed) :
892 AbstractTracker{std::move(_cCtx)},
893 serviceName{std::move(_serviceName)},
894 onTrackerCreated{std::move(_onTrackerCreated)},
895 onTrackerDestroyed{std::move(_onTrackerDestroyed)} {}
897 const std::string serviceName;
898 const std::vector<std::function<void(
const ServiceTrackerInfo&)>> onTrackerCreated;
899 const std::vector<std::function<void(
const ServiceTrackerInfo&)>> onTrackerDestroyed;
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.
Definition: Trackers.h:315
const std::chrono::milliseconds warningTimoutForNonExpiredSvcObject
Definition: Trackers.h:573
std::set< std::shared_ptr< SvcEntry >, SvcEntryCompare > entries
Definition: Trackers.h:592
const std::string serviceName
The service name the service tracker is tracking.
Definition: Trackers.h:797
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_waitForAsyncTracker(celix_bundle_context_t *ctx, long trackerId)
Wait, if able, for (async) creation of a tracker.
~GenericServiceTracker() override=default
void(* addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) CELIX_OPTS_INIT
The optional addWithOwner callback is handled as the add callback, but with the addition that the ser...
Definition: celix_bundle_context.h:680
bool useServiceWithProperties(const F &f)
Applies the provided function to the highest ranking service being tracked, along with its properties...
Definition: Trackers.h:446
void open() override
Definition: Trackers.h:231
const std::vector< std::function< void(const std::vector< std::pair< std::shared_ptr< I >, std::shared_ptr< const celix::Properties >>>)> > updateWithPropertiesCallbacks
Definition: Trackers.h:581
Definition: Trackers.h:467
A trivial struct containing information about a service tracker.
Definition: Trackers.h:791
const celix::Filter filter
Definition: Trackers.h:271
size_t useServices(const F &f)
Applies the provided function to each service being tracked.
Definition: Trackers.h:385
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
Definition: Trackers.h:577
celix_service_tracking_options opts
Definition: Trackers.h:272
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_trackServiceTrackersAsync(celix_bundle_context_t *ctx, const char *serviceName, void *callbackHandle, void(*trackerAdd)(void *handle, const celix_service_tracker_info_t *info), void(*trackerRemove)(void *handle, const celix_service_tracker_info_t *info), void *doneCallbackData, void(*doneCallback)(void *doneCallbackData))
Track the service tracker targeting the provided service name.
bool operator()(const std::shared_ptr< SvcEntry > &a, const std::shared_ptr< SvcEntry > &b) const
Definition: Trackers.h:585
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
Definition: Trackers.h:575
static std::function< void(T *)> delCallback()
Definition: Trackers.h:169
static std::shared_ptr< SvcEntry > createEntry(void *voidSvc, const celix_properties_t *cProps, const celix_bundle_t *cBnd)
Definition: Trackers.h:494
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)
Definition: Trackers.h:482
void(* trackerCreatedCallback)(void *trackerCreatedCallbackData) CELIX_OPTS_INIT
The callback called when the tracker has ben created (and is active) when using the track bundles asc...
Definition: celix_bundle_context.h:1282
The Service Bundle Tracking options can be used to fine tune the requested bundle tracker options.
Definition: celix_bundle_context.h:1226
Celix Tracker Exception.
Definition: FrameworkExceptions.h:36
size_t useServicesWithOwner(const F &f)
Applies the provided function to each service being tracked, along with its properties and owner bund...
Definition: Trackers.h:416
CELIX_FRAMEWORK_EXPORT celix_bundle_t * celix_bundleContext_getBundle(const celix_bundle_context_t *ctx)
Returns the bundle for this bundle context.
void waitForExpired(std::weak_ptr< U > observe, long svcId, const char *objName)
Definition: Trackers.h:518
GenericServiceTracker(std::shared_ptr< celix_bundle_context_t > _cCtx, std::string _svcName, std::string _svcVersionRange, celix::Filter _filter)
Definition: Trackers.h:220
void open() override
Definition: Trackers.h:724
const std::string & getServiceRange() const
The service version range tracked by this service tracker.
Definition: Trackers.h:252
void waitForExpiredSvcEntry(std::shared_ptr< SvcEntry > &entry)
Definition: Trackers.h:503
TrackerState state
Definition: Trackers.h:206
const celix::Filter & getFilter() const
The additional filter for services tracked by this service tracker.
Definition: Trackers.h:260
virtual void open()=0
Open the tracker (if the state is not OPEN or OPENING).
std::shared_ptr< I > getHighestRankingService()
Get the current highest ranking service tracked by this tracker.
Definition: Trackers.h:345
CELIX_FRAMEWORK_EXPORT long celix_framework_fireGenericEvent(celix_framework_t *fw, long eventId, long bndId, const char *eventName, void *processData, void(*processCallback)(void *data), void *doneData, void(*doneCallback)(void *doneData))
Fire a generic event. The event will be added to the event loop and handled on the event loop thread.
const long trackerOwnerBundleId
The bundle id of the owner of the service tracker.
Definition: Trackers.h:807
std::shared_ptr< const celix::Bundle > owner
Definition: Trackers.h:478
he GenericServiceTracker class is a specialization of the AbstractTracker for managing a service trac...
Definition: Trackers.h:218
std::size_t getServiceCount() const
The nr of services currently tracked by this tracker.
Definition: Trackers.h:265
size_t useServicesWithProperties(const F &f)
Applies the provided function to each service being tracked, along with its properties.
Definition: Trackers.h:400
bool useService(const F &f)
Applies the provided function to the highest ranking service being tracked.
Definition: Trackers.h:431
std::shared_ptr< const celix::Properties > properties
Definition: Trackers.h:477
The ServiceTracker class tracks services.
Definition: Trackers.h:301
std::atomic< size_t > svcCount
Definition: Trackers.h:273
bool useServiceWithOwner(const F &f)
Applies the provided function to the highest ranking service being tracked, along with its properties...
Definition: Trackers.h:462
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_stopTracker(celix_bundle_context_t *ctx, long trackerId)
Stop the tracker with the provided track id.
void(* trackerCreatedCallback)(void *trackerCreatedCallbackData) CELIX_OPTS_INIT
The callback called when the tracker has ben created (and is active) when using a async call.
Definition: celix_bundle_context.h:719
The BundleTracker class tracks bundles.
Definition: Trackers.h:689
void(* removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) CELIX_OPTS_INIT
The optional removeWithOwner callback is handled as the remove callback, but with the addition that t...
Definition: celix_bundle_context.h:704
std::unordered_map< long, std::shared_ptr< SvcEntry > > cachedEntries
Definition: Trackers.h:593
CELIX_FRAMEWORK_EXPORT bool celix_framework_isCurrentThreadTheEventLoop(celix_framework_t *fw)
Returns whether the current thread is the Celix framework event loop thread.
void waitIfAble() const
Wait (if not on the Celix event thread) for the tracker to be OPEN or CLOSED.
Definition: Trackers.h:161
Definition: Trackers.h:584
Service Tracker Options used to fine tune which services to track and the callback to be used for the...
Definition: celix_bundle_context.h:627
An installed bundle in the Celix framework.
Definition: Bundle.h:49
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_waitForAsyncStopTracker(celix_bundle_context_t *ctx, long trackerId)
Wait, if able, for (async) stopping of tracking.
std::mutex mutex
Definition: Trackers.h:591
std::mutex mutex
Definition: Trackers.h:204
TrackerState getState() const
Get the current state of the tracker.
Definition: Trackers.h:91
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
Definition: Trackers.h:582
static std::shared_ptr< BundleTracker > create(std::shared_ptr< celix_bundle_context_t > cCtx, bool includeFrameworkBundle, std::vector< std::function< void(const celix::Bundle &)>> onInstallCallbacks, std::vector< std::function< void(const celix::Bundle &)>> onStartCallbacks, std::vector< std::function< void(const celix::Bundle &)>> onStopCallbacks)
Creates a new bundle tracker and opens the tracker.
Definition: Trackers.h:702
void wait() const
Wait until a service tracker is completely OPEN or CLOSED.
Definition: Trackers.h:137
void(* onStarted)(void *handle, const celix_bundle_t *bundle) CELIX_OPTS_INIT
Tracker callback when a bundle is started.
Definition: celix_bundle_context.h:1246
const std::string svcName
Definition: Trackers.h:269
TrackerState
The tracker state.
Definition: Trackers.h:48
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_log(const celix_bundle_context_t *ctx, celix_log_level_e level, const char *format,...) __attribute__((format(printf
Logs a message to Celix framework logger with the provided log level.
void(* onInstalled)(void *handle, const celix_bundle_t *bundle) CELIX_OPTS_INIT
Tracker callback when a bundle is installed.
Definition: celix_bundle_context.h:1238
std::shared_ptr< I > svc
Definition: Trackers.h:476
long svcId
Definition: Trackers.h:474
void invokeUpdateCallbacks()
Definition: Trackers.h:531
CELIX_FRAMEWORK_EXPORT long celix_bundle_getId(const celix_bundle_t *bnd)
Return the bundle id.
long svcRanking
Definition: Trackers.h:475
AbstractTracker(std::shared_ptr< celix_bundle_context_t > _cCtx)
Definition: Trackers.h:75
bool isOpen() const
Check if the tracker is open (state == OPEN)
Definition: Trackers.h:83
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_trackServicesWithOptionsAsync(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts)
Tracks services using the provided tracker options.
long trkId
Definition: Trackers.h:205
const std::shared_ptr< celix_bundle_context_t > cCtx
Definition: Trackers.h:202
const std::string & getServiceName() const
The service name tracked by this service tracker.
Definition: Trackers.h:247
Service Tracker Info provided to the service tracker tracker callbacks.
Definition: celix_bundle_context.h:1365
void(* setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner) CELIX_OPTS_INIT
The optional setWithOwner callback is handled as the set callback, but with the addition that the ser...
Definition: celix_bundle_context.h:659
virtual ~AbstractTracker() noexcept=default
void(* onStopped)(void *handle, const celix_bundle_t *bundle) CELIX_OPTS_INIT
Tracker callback when a bundle is stopped.
Definition: celix_bundle_context.h:1254
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_trackBundlesWithOptionsAsync(celix_bundle_context_t *ctx, const celix_bundle_tracking_options_t *opts)
Tracks bundles using the provided bundle tracker options.
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
Definition: Trackers.h:576
void close()
Close the tracker (of the state is not CLOSED or CLOSING).
Definition: Trackers.h:102
const std::string svcVersionRange
Definition: Trackers.h:270
celix::Properties Properties
Definition: Properties.h:25
The AbstractTracker class is the base of all C++ Celix trackers.
Definition: Trackers.h:73
CELIX_FRAMEWORK_EXPORT celix_framework_t * celix_bundleContext_getFramework(const celix_bundle_context_t *ctx)
std::vector< std::shared_ptr< I > > getServices()
Get a vector of all the currently found services for this tracker.
Definition: Trackers.h:364
const celix::Filter filter
The service filter the service tracker is using for tracking.
Definition: Trackers.h:802
std::shared_ptr< SvcEntry > highestRankingServiceEntry
Definition: Trackers.h:594
const std::vector< std::function< void(const std::vector< std::shared_ptr< I >>)> > updateCallbacks
Definition: Trackers.h:580
SvcEntry(long _svcId, long _svcRanking, std::shared_ptr< I > _svc, std::shared_ptr< const celix::Properties > _properties, std::shared_ptr< const celix::Bundle > _owner)
Definition: Trackers.h:468