Skip to content

Commit

Permalink
gh-87: Change signature celix_bundleContext_trackServices
Browse files Browse the repository at this point in the history
Also update the celix_bundleContext_trackServices usage.
  • Loading branch information
pnoltes committed Feb 11, 2024
1 parent b5ee724 commit 7b37d72
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 185 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ limitations under the License.
- linked_list.h is removed and no longer supported. Use celix_array_list.h instead.
- ip_utils.h is removed and no longer supported.
- array_list.h is removed and no longer supported. Use celix_array_list.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.

## 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_trackService(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_trackService(ctx.get(), CELIX_LOG_SERVICE_NAME);
EXPECT_EQ(2, control->nrOfLogServices(control->handle, nullptr));

//request a 'logger1' log service
Expand Down Expand Up @@ -225,7 +225,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_trackService(ctx.get(), CELIX_LOG_SERVICE_NAME);
celix_framework_waitForEmptyEventQueue(fw.get());
EXPECT_EQ(2, control->nrOfLogServices(control->handle, 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
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 @@ -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 7b37d72

Please sign in to comment.