Skip to content

Commit

Permalink
Merge pull request #729 from apache/feature/87-add-additional-svc-tra…
Browse files Browse the repository at this point in the history
…cker-bundle-context-funtions

Feature/87 add additional svc tracker bundle context funtions
  • Loading branch information
pnoltes authored Feb 27, 2024
2 parents e6dc3ca + 8ca876d commit 6c2b839
Show file tree
Hide file tree
Showing 22 changed files with 1,632 additions and 702 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ limitations under the License.
- the celix_arrayList_add function no longer accepts a NULL value.
- version.h and version_range.h are removed and no longer supported. Use celix_version.h and celix_version_range.h
instead.
- The signature of `celix_bundleContext_trackServices` has changed. The signature is now simpler to better support
the use-case of using a service tracker with the `celix_bundleContext_useTrackedService*` functions.
The `celix_bundleContext_trackServicesWithOptions` is still available for more advanced use-cases.
- Function `celix_bundle_destroyServiceTrackerList` is removed. The returned array list from
`celix_bundle_listServiceTrackers` is now configured to destroy the service trackers info entries.

## New Features

Expand Down
6 changes: 3 additions & 3 deletions bundles/logging/log_admin/gtest/src/LogAdminTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ TEST_F(LogBundleTestSuite, NrOfLogServices) {
EXPECT_EQ(1, control->nrOfLogServices(control->handle, nullptr)); //default the framework log services is available

//request "default" log service
long trkId1 = celix_bundleContext_trackService(ctx.get(), CELIX_LOG_SERVICE_NAME, nullptr, nullptr);
long trkId1 = celix_bundleContext_trackServices(ctx.get(), CELIX_LOG_SERVICE_NAME);
EXPECT_EQ(2, control->nrOfLogServices(control->handle, nullptr));

//request "default" log service -> already created
long trkId2 = celix_bundleContext_trackService(ctx.get(), CELIX_LOG_SERVICE_NAME, nullptr, nullptr);
long trkId2 = celix_bundleContext_trackServices(ctx.get(), CELIX_LOG_SERVICE_NAME);
EXPECT_EQ(2, control->nrOfLogServices(control->handle, nullptr));

//request a 'logger1' log service
Expand Down Expand Up @@ -221,7 +221,7 @@ TEST_F(LogBundleTestSuite, SinkLogControl) {

TEST_F(LogBundleTestSuite, LogServiceControl) {
//request "default" log service
long trkId1 = celix_bundleContext_trackService(ctx.get(), CELIX_LOG_SERVICE_NAME, nullptr, nullptr);
long trkId1 = celix_bundleContext_trackServices(ctx.get(), CELIX_LOG_SERVICE_NAME);
celix_framework_waitForEmptyEventQueue(fw.get());
EXPECT_EQ(2, control->nrOfLogServices(control->handle, nullptr));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,25 @@ class RsaDfiDynamicIpServerTestSuite : public ::testing::Test {
void TestRemoteCalculator(void (*testBody)(tst_service_t* testSvc), const char* serverIp = "127.0.0.1") {
remote_service_admin_service_t* serverRsaSvc{nullptr};
remote_service_admin_service_t* clientRsaSvc{nullptr};
serverRsaTrkId = celix_bundleContext_trackService(serverCtx.get(), CELIX_RSA_REMOTE_SERVICE_ADMIN,
&serverRsaSvc, [](void* handle, void* svc){
auto rsaSvc = static_cast<remote_service_admin_service_t **>(handle);
*rsaSvc = static_cast<remote_service_admin_service_t*>(svc);
});

celix_service_tracking_options_t trackintOpts{};
trackintOpts.filter.serviceName = CELIX_RSA_REMOTE_SERVICE_ADMIN;
trackintOpts.callbackHandle = &serverRsaSvc;
trackintOpts.set = [](void* handle, void* svc) {
auto rsaSvc = static_cast<remote_service_admin_service_t**>(handle);
*rsaSvc = static_cast<remote_service_admin_service_t*>(svc);
};
serverRsaTrkId = celix_bundleContext_trackServicesWithOptions(serverCtx.get(), &trackintOpts);
EXPECT_GE(serverRsaTrkId, 0);
clientRsaTrkId = celix_bundleContext_trackService(clientCtx.get(), CELIX_RSA_REMOTE_SERVICE_ADMIN,
&clientRsaSvc, [](void* handle, void* svc){
auto rsaSvc = static_cast<remote_service_admin_service_t **>(handle);
*rsaSvc = static_cast<remote_service_admin_service_t*>(svc);
});

trackintOpts.callbackHandle = &clientRsaSvc;
trackintOpts.set = [](void* handle, void* svc){
auto rsaSvc = static_cast<remote_service_admin_service_t **>(handle);
*rsaSvc = static_cast<remote_service_admin_service_t*>(svc);
};
clientRsaTrkId = celix_bundleContext_trackServicesWithOptions(clientCtx.get(), &trackintOpts);
EXPECT_GE(clientRsaTrkId, 0);

long calcId = celix_bundleContext_findService(serverCtx.get(), CALCULATOR_SERVICE);
ASSERT_TRUE(calcId >= 0L);
ASSERT_TRUE(clientRsaSvc != nullptr);
Expand Down
9 changes: 6 additions & 3 deletions bundles/shell/shell/gtest/src/ShellTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ static void callCommand(std::shared_ptr<celix_bundle_context_t>& ctx, const char
data.cmdLine = cmdLine;
data.cmdShouldSucceed = cmdShouldSucceed;
data.context = ctx.get();
data.tracker = celix_bundleContext_trackService(ctx.get(), CELIX_SHELL_SERVICE_NAME,
static_cast<void*>(&data), [](void * handle, void * svc) {
celix_service_tracking_options_t opts{};
opts.filter.serviceName = CELIX_SHELL_SERVICE_NAME;
opts.callbackHandle = &data;
opts.set = [](void * handle, void * svc) {
if (svc == nullptr) {
return;
}
Expand All @@ -93,7 +95,8 @@ static void callCommand(std::shared_ptr<celix_bundle_context_t>& ctx, const char
}
celix_bundleContext_stopTracker(d->context, d->tracker);
d->barrier.set_value();
});
};
data.tracker = celix_bundleContext_trackServicesWithOptions(ctx.get(), &opts);
data.barrier.get_future().wait();
}

Expand Down
2 changes: 1 addition & 1 deletion bundles/shell/shell/src/query_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void queryCommand_callback(void *handle, const celix_bundle_t *bnd) {
}
}
}
celix_bundle_destroyServiceTrackerList(trackers);
celix_arrayList_destroy(trackers);
}

if (printBundleCalled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ static celix_status_t activator_start(activator_data_t *data, celix_bundle_conte
data->trkId = -1L;

printf("Starting service tracker\n");
data->trkId = celix_bundleContext_trackServices(data->ctx, EXAMPLE_CALC_NAME, data, (void*)addSvc, (void*)removeSvc);
celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
opts.filter.serviceName = EXAMPLE_CALC_NAME;
opts.callbackHandle = data;
opts.addWithProperties = (void*)addSvc;
opts.remove = (void*)removeSvc;
data->trkId = celix_bundleContext_trackServicesWithOptions(data->ctx, &opts);

printf("Trying to use calc service\n");
celix_bundleContext_useService(data->ctx, EXAMPLE_CALC_NAME, data, (void*)useCalc);
Expand Down
23 changes: 14 additions & 9 deletions examples/celix-examples/track_tracker_example/src/activator.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ celix_status_t activator_start(activator_data_t* act, celix_bundle_context_t *ct

act->trackerId = celix_bundleContext_trackServiceTrackers(ctx, CALC_SERVICE_NAME, act, addCalcTracker, removeCalcTracker);

act->calcTrk1 = celix_bundleContext_trackServices(ctx, CALC_SERVICE_NAME, act, addCalcSvc, removeCalcSvc);

celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
opts.filter.serviceName = CALC_SERVICE_NAME;
opts.filter.filter = "(&(prop1=val1)(prop2=val2))";
opts.callbackHandle = act;
opts.add = addCalcSvc;
opts.remove = removeCalcSvc;
act->calcTrk2 = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
celix_service_tracking_options_t opts1 = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
opts1.filter.serviceName = CALC_SERVICE_NAME;
opts1.callbackHandle = act;
opts1.add = addCalcSvc;
opts1.remove = removeCalcSvc;
act->calcTrk1 = celix_bundleContext_trackServicesWithOptions(ctx, &opts1);

celix_service_tracking_options_t opts2 = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
opts2.filter.serviceName = CALC_SERVICE_NAME;
opts2.filter.filter = "(&(prop1=val1)(prop2=val2))";
opts2.callbackHandle = act;
opts2.add = addCalcSvc;
opts2.remove = removeCalcSvc;
act->calcTrk2 = celix_bundleContext_trackServicesWithOptions(ctx, &opts2);

act->svc.handle = act;
act->svc.calc = calc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ TEST_F(CelixBundleContextBundlesTestSuite, BundleInfoTests) {
auto *services = celix_bundle_listRegisteredServices(bnd);
data->requestedCount = celix_arrayList_size(trackers);
data->provideCount = celix_arrayList_size(services);
celix_bundle_destroyServiceTrackerList(trackers);
celix_arrayList_destroy(trackers);
celix_bundle_destroyRegisteredServicesList(services);
};

Expand All @@ -756,7 +756,7 @@ TEST_F(CelixBundleContextBundlesTestSuite, BundleInfoTests) {


long svcId = celix_bundleContext_registerService(ctx, (void*)0x42, "NopService", NULL);
long trackerId = celix_bundleContext_trackServices(ctx, "AService", NULL, NULL, NULL);
long trackerId = celix_bundleContext_trackServices(ctx, "AService");

called = celix_bundleContext_useBundle(ctx, 0, &data, updateCountFp);
EXPECT_TRUE(called);
Expand Down
Loading

0 comments on commit 6c2b839

Please sign in to comment.