You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/05/08 18:52:38 UTC
celix git commit: CELIX-446: Adds
celix_bundleContext_useService(s)WithOptions functions and refactor shell to
use celix_bundleContext_(un)registserService
Repository: celix
Updated Branches:
refs/heads/develop debb4b12d -> 673837fcd
CELIX-446: Adds celix_bundleContext_useService(s)WithOptions functions and refactor shell to use celix_bundleContext_(un)registserService
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/673837fc
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/673837fc
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/673837fc
Branch: refs/heads/develop
Commit: 673837fcd5d8023cabee7ee45095fb403952f7a3
Parents: debb4b1
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue May 8 20:51:57 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue May 8 20:51:57 2018 +0200
----------------------------------------------------------------------
framework/include/bundle_context.h | 90 ++++++++++++++-----
framework/include/service_tracker.h | 2 +-
framework/private/mock/bundle_context_mock.c | 20 ++++-
framework/src/bundle_context.c | 95 +++++++++++++++------
framework/src/service_tracker.c | 14 ++-
framework/tst/bundle_context_services_test.cpp | 26 +++---
shell/include/command.h | 1 +
shell/src/activator.c | 23 +++--
8 files changed, 190 insertions(+), 81 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/include/bundle_context.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_context.h b/framework/include/bundle_context.h
index 36547c4..4ba5904 100644
--- a/framework/include/bundle_context.h
+++ b/framework/include/bundle_context.h
@@ -247,8 +247,6 @@ void celix_bundleContext_unregisterService(celix_bundle_context_t *ctx, long ser
long celix_bundleContext_trackService(
celix_bundle_context_t* ctx,
const char* serviceName,
- const char* versioRange,
- const char* filter,
void* callbackHandle,
void (*set)(void* handle, void* svc)
);
@@ -268,8 +266,6 @@ long celix_bundleContext_trackService(
long celix_bundleContext_trackServices(
celix_bundle_context_t* ctx,
const char* serviceName,
- const char* versioRange,
- const char* filter,
void* callbackHandle,
void (*add)(void* handle, void* svc),
void (*remove)(void* handle, void* svc)
@@ -295,11 +291,11 @@ typedef struct celix_service_tracker_options {
void (*removeWithProperties)(void *handle, void *svc, const celix_properties_t *props);
void (*modifiedWithProperties)(void *handle, void *svc, const celix_properties_t *props);
- void (*setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner); //highest ranking
- void (*addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner);
- void (*removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner);
- void (*modifiedWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner);
-} celix_service_tracker_options_t;
+ void (*setWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner); //highest ranking
+ void (*addWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner);
+ void (*removeWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner);
+ void (*modifiedWithOwner)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner);
+} celix_service_tracking_options_t;
/**
* Tracks services using the provided tracker options.
@@ -309,7 +305,7 @@ typedef struct celix_service_tracker_options {
* @param opts The pointer to the tracker options.
* @return the tracker id or < 0 if unsuccessful.
*/
-long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracker_options_t *opts);
+long celix_bundleContext_trackServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_tracking_options_t *opts);
@@ -334,7 +330,7 @@ bool celix_bundleContext_useServiceWithId(
long serviceId,
const char *serviceName /*sanity check*/,
void *callbackHandle,
- void (*use)(void *handle, void* svc, const celix_properties_t *props, const celix_bundle_t *owner)
+ void (*use)(void *handle, void* svc, const celix_properties_t *props, const celix_bundle_t *svcOwner)
);
/**
@@ -342,15 +338,12 @@ bool celix_bundleContext_useServiceWithId(
* Invokes the provided callback with the found service.
* The svc, props and owner in the callback are only valid during the callback.
* If no service is found the callback will not be invoked.
- * At least a serviceName or filter needs to be provided, if not the callback is not invoked.
*
* This function will block till the callback is finished. As result it is possible to provide callback data from the
* stack.
*
* @param ctx The bundle context
* @param serviceName the required service name.
- * @param serviceRange the optional service version range (e.g. '[1.0.0,2.0.0)' )
- * @param filter the optional filer.
* @param callbackHandle The data pointer, which will be used in the callbacks
* @param use The callback, which will be called when service is retrieved.
* @return True if a service was found.
@@ -358,10 +351,8 @@ bool celix_bundleContext_useServiceWithId(
bool celix_bundleContext_useService(
celix_bundle_context_t *ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void *callbackHandle,
- void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner)
+ void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner)
);
/**
@@ -369,7 +360,6 @@ bool celix_bundleContext_useService(
* Invokes the provided callback with the found services.
* The svc, props and owner in the callback are only valid during the callback.
* If no services are found the callback will not be invoked.
- * At least a serviceName or filter needs to be provided, if not the callback is not invoked.
*
* This function will block till the callback is finished. As result it is possible to provide callback data from the
* stack.
@@ -379,18 +369,74 @@ bool celix_bundleContext_useService(
* @param serviceRange the optional service version range (e.g. '[1.0.0,2.0.0)' )
* @param filter the optional filter.
* @param callbackHandle The data pointer, which will be used in the callbacks
- * @param use The callback, which will be called when service is retrieved.
+ * @param use The callback, which will be called for every service found.
*/
void celix_bundleContext_useServices(
celix_bundle_context_t *ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void *callbackHandle,
- void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *owner)
+ void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner)
);
+typedef struct celix_service_use_options {
+ /**
+ * service filter options. Note the serviceName is required.
+ */
+ const char *serviceName; //REQUIRED
+ const char *versionRange; //default will be empty
+ const char *filter; //default will be empty
+ const char *lang; //default will be LANG_C
+
+ /**
+ * Callback info
+ */
+ void *callbackHandle;
+ void (*use)(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *svcOwner);
+} celix_service_use_options_t;
+
+/**
+ * Get and lock the current highest ranking service conform the service filter info from the provided options.
+ *
+ * Invokes the provided callback with the found service.
+ * The svc, props and owner in the callback are only valid during the callback.
+ * If no service is found the callback will not be invoked.
+ *
+ * This function will block till the callback is finished. As result it is possible to provide callback data from the
+ * stack.
+ *
+ * @param ctx The bundle context.
+ * @param serviceName the required service name.
+ * @param opts The required options. Note that the serviceName is required.
+ * @return True if a service was found.
+ */
+bool celix_bundleContext_useServiceWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts);
+
+
+/**
+ * Get and lock the current services conform the service filter info from the provided options.
+ *
+ * Invokes the provided callback with the found services.
+ * The svc, props and owner in the callback are only valid during the callback.
+ * If no services are found the callback will not be invoked.
+ * At least a serviceName needs to be provided, if not the callback is not invoked.
+ *
+ * This function will block till all the callbacks are finished. As result it is possible to provide callback data from the
+ * stack.
+ *
+ * @param ctx The bundle context.
+ * @param serviceName the required service name.
+ * @param opts The required options. Note that the serviceName is required.
+ * @param callbackHandle The data pointer, which will be used in the callbacks.
+ * @param use The callback, which will be called for every service found.
+ */
+void celix_bundleContext_useServicesWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts);
+
+
/**
* Install and optional start a bundle.
*
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/include/service_tracker.h
----------------------------------------------------------------------
diff --git a/framework/include/service_tracker.h b/framework/include/service_tracker.h
index 6b9fb2c..513b8cc 100644
--- a/framework/include/service_tracker.h
+++ b/framework/include/service_tracker.h
@@ -95,7 +95,7 @@ celix_service_tracker_t* celix_serviceTracker_create(
*/
celix_service_tracker_t* celix_serviceTracker_createWithOptions(
bundle_context_t *ctx,
- const celix_service_tracker_options_t *opts
+ const celix_service_tracking_options_t *opts
);
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/private/mock/bundle_context_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/bundle_context_mock.c b/framework/private/mock/bundle_context_mock.c
index 67bf3be..bddd7fd 100644
--- a/framework/private/mock/bundle_context_mock.c
+++ b/framework/private/mock/bundle_context_mock.c
@@ -307,4 +307,22 @@ bool celix_bundleContext_uninstallBundle(bundle_context_t *ctx, long bundleId) {
->withPointerParameters("ctx", ctx)
->withLongIntParameters("bundleId", bundleId);
return mock_c()->returnValue().value.boolValue;
-}
\ No newline at end of file
+}
+
+bool celix_bundleContext_useServiceWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts) {
+ mock_c()->actualCall("celix_bundleContext_useServiceWithOptions")
+ ->withPointerParameters("ctx", ctx)
+ ->withConstPointerParameters("opts", opts);
+ return mock_c()->returnValue().value.boolValue;
+}
+
+
+void celix_bundleContext_useServicesWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts) {
+ mock_c()->actualCall("celix_bundleContext_useServicesWithOptions")
+ ->withPointerParameters("ctx", ctx)
+ ->withConstPointerParameters("opts", opts);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c
index b058d88..b75b692 100644
--- a/framework/src/bundle_context.c
+++ b/framework/src/bundle_context.c
@@ -677,54 +677,99 @@ bool celix_bundleContext_useServiceWithId(
const char *serviceName,
void *callbackHandle,
void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner)) {
+ celix_service_use_options_t opts;
+ memset(&opts, 0, sizeof(opts));
+
char filter[64];
snprintf(filter, 64, "(%s=%li)", OSGI_FRAMEWORK_SERVICE_ID, serviceId);
- return celix_bundleContext_useService(ctx, serviceName, NULL, filter, callbackHandle, use);
+
+ opts.serviceName = serviceName;
+ opts.filter = filter;
+ opts.callbackHandle = callbackHandle;
+ opts.use = use;
+ return celix_bundleContext_useServiceWithOptions(ctx, &opts);
}
bool celix_bundleContext_useService(
bundle_context_t *ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void *callbackHandle,
void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner)) {
- bool called = false;
- service_tracker_t *trk = celix_serviceTracker_create(ctx, serviceName, versionRange, filter);
- if (trk != NULL) {
- called = celix_serviceTracker_useHighestRankingService(trk, serviceName, callbackHandle, use);
- celix_serviceTracker_destroy(trk);
- }
- return called;
+ celix_service_use_options_t opts;
+ memset(&opts, 0, sizeof(opts));
+ opts.serviceName = serviceName;
+ opts.callbackHandle = callbackHandle;
+ opts.use = use;
+ return celix_bundleContext_useServiceWithOptions(ctx, &opts);
}
void celix_bundleContext_useServices(
bundle_context_t *ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void *callbackHandle,
void (*use)(void *handle, void *svc, const properties_t *props, const bundle_t *owner)) {
- service_tracker_t *trk = celix_serviceTracker_create(ctx, serviceName, versionRange, filter);
- if (trk != NULL) {
- celix_serviceTracker_useServices(trk, serviceName, callbackHandle, use);
- celix_serviceTracker_destroy(trk);
+ celix_service_use_options_t opts;
+ memset(&opts, 0, sizeof(opts));
+ opts.serviceName = serviceName;
+ opts.callbackHandle = callbackHandle;
+ opts.use = use;
+ celix_bundleContext_useServicesWithOptions(ctx, &opts);
+}
+
+bool celix_bundleContext_useServiceWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts) {
+ bool called = false;
+ celix_service_tracking_options_t trkOpts;
+ memset(&trkOpts, 0, sizeof(trkOpts));
+
+ if (opts != NULL) {
+ trkOpts.serviceName = opts->serviceName;
+ trkOpts.filter = opts->filter;
+ trkOpts.versionRange = opts->versionRange;
+ trkOpts.lang = opts->lang;
+
+ service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts);
+ if (trk != NULL) {
+ called = celix_serviceTracker_useHighestRankingService(trk, opts->serviceName, opts->callbackHandle, opts->use);
+ celix_serviceTracker_destroy(trk);
+ }
}
+ return called;
}
+
+
+void celix_bundleContext_useServicesWithOptions(
+ celix_bundle_context_t *ctx,
+ const celix_service_use_options_t *opts) {
+ celix_service_tracking_options_t trkOpts;
+ memset(&trkOpts, 0, sizeof(trkOpts));
+
+ if (opts != NULL) {
+ trkOpts.serviceName = opts->serviceName;
+ trkOpts.filter = opts->filter;
+ trkOpts.versionRange = opts->versionRange;
+ trkOpts.lang = opts->lang;
+
+ service_tracker_t *trk = celix_serviceTracker_createWithOptions(ctx, &trkOpts);
+ if (trk != NULL) {
+ celix_serviceTracker_useServices(trk, opts->serviceName, opts->callbackHandle, opts->use);
+ celix_serviceTracker_destroy(trk);
+ }
+ }
+}
+
+
long celix_bundleContext_trackService(
bundle_context_t* ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void* callbackHandle,
void (*set)(void* handle, void* svc)) {
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.serviceName = serviceName;
- opts.versionRange = versionRange;
- opts.filter = filter;
opts.callbackHandle = callbackHandle;
opts.set = set;
return celix_bundleContext_trackServicesWithOptions(ctx, &opts);
@@ -734,16 +779,12 @@ long celix_bundleContext_trackService(
long celix_bundleContext_trackServices(
bundle_context_t* ctx,
const char* serviceName,
- const char* versionRange,
- const char* filter,
void* callbackHandle,
void (*add)(void* handle, void* svc),
void (*remove)(void* handle, void* svc)) {
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.serviceName = serviceName;
- opts.versionRange = versionRange;
- opts.filter = filter;
opts.callbackHandle = callbackHandle;
opts.add = add;
opts.remove = remove;
@@ -751,7 +792,7 @@ long celix_bundleContext_trackServices(
}
-long celix_bundleContext_trackServicesWithOptions(bundle_context_t *ctx, const celix_service_tracker_options_t *opts) {
+long celix_bundleContext_trackServicesWithOptions(bundle_context_t *ctx, const celix_service_tracking_options_t *opts) {
long trackerId = -1;
celix_service_tracker_t *tracker = celix_serviceTracker_createWithOptions(ctx, opts);
if (tracker != NULL) {
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/src/service_tracker.c
----------------------------------------------------------------------
diff --git a/framework/src/service_tracker.c b/framework/src/service_tracker.c
index 30040e6..194d9ac 100644
--- a/framework/src/service_tracker.c
+++ b/framework/src/service_tracker.c
@@ -560,7 +560,7 @@ celix_service_tracker_t* celix_serviceTracker_create(
const char *serviceName,
const char *versionRange,
const char *filter) {
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.serviceName = serviceName;
opts.filter = filter;
@@ -570,7 +570,7 @@ celix_service_tracker_t* celix_serviceTracker_create(
celix_service_tracker_t* celix_serviceTracker_createWithOptions(
bundle_context_t *ctx,
- const celix_service_tracker_options_t *opts
+ const celix_service_tracking_options_t *opts
) {
celix_service_tracker_t *tracker = NULL;
if (ctx != NULL && opts != NULL && opts->serviceName != NULL) {
@@ -600,8 +600,13 @@ celix_service_tracker_t* celix_serviceTracker_createWithOptions(
celixThreadMutex_create(&tracker->mutex, NULL);
tracker->currentHighestServiceId = -1;
+ //setting lang
+ const char *lang = opts->lang;
+ if (lang == NULL || strncmp("", lang, 1) == 0) {
+ lang = CELIX_FRAMEWORK_SERVICE_C_LANGUAGE;
+ }
+
//setting filter
- const char *lang = opts->lang != NULL ? opts->lang : CELIX_FRAMEWORK_SERVICE_C_LANGUAGE;
if (opts->filter != NULL && opts->versionRange != NULL) {
//TODO version range
asprintf(&tracker->filter, "&((%s=%s)(%s=%s)%s)", OSGI_FRAMEWORK_OBJECTCLASS, opts->serviceName, CELIX_FRAMEWORK_SERVICE_LANGUAGE, lang, opts->filter);
@@ -619,7 +624,8 @@ celix_service_tracker_t* celix_serviceTracker_createWithOptions(
}
} else {
if (opts != NULL && opts->serviceName == NULL) {
- framework_log(logger, OSGI_FRAMEWORK_LOG_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__, "Error incorrect arguments. Missing service name.");
+ framework_log(logger, OSGI_FRAMEWORK_LOG_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
+ "Error incorrect arguments. Missing service name.");
} else {
framework_log(logger, OSGI_FRAMEWORK_LOG_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__, "Error incorrect arguments. Required context (%p) or opts (%p) is NULL", ctx, opts);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/framework/tst/bundle_context_services_test.cpp
----------------------------------------------------------------------
diff --git a/framework/tst/bundle_context_services_test.cpp b/framework/tst/bundle_context_services_test.cpp
index f9050c5..7cbe057 100644
--- a/framework/tst/bundle_context_services_test.cpp
+++ b/framework/tst/bundle_context_services_test.cpp
@@ -109,17 +109,17 @@ TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
};
int total = 0;
- celix_bundleContext_useServices(ctx, "calc", NULL, NULL, &total, use);
+ celix_bundleContext_useServices(ctx, "calc", &total, use);
CHECK_EQUAL(42 * 3, total);
celix_bundleContext_unregisterService(ctx, svcId3);
total = 0;
- celix_bundleContext_useServices(ctx, "calc", NULL, NULL, &total, use);
+ celix_bundleContext_useServices(ctx, "calc", &total, use);
CHECK_EQUAL(42 * 2, total);
total = 0;
- bool called = celix_bundleContext_useService(ctx, "calc", NULL, NULL, &total, use);
+ bool called = celix_bundleContext_useService(ctx, "calc", &total, use);
CHECK(called);
CHECK_EQUAL(42, total);
@@ -263,7 +263,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTest) {
*c -= 1;
};
- long trackerId = celix_bundleContext_trackServices(ctx, "calc", NULL, NULL, &count, add, remove);
+ long trackerId = celix_bundleContext_trackServices(ctx, "calc", &count, add, remove);
CHECK(trackerId > 0);
CHECK_EQUAL(0, count);
@@ -283,11 +283,11 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTest) {
}
TEST(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) {
- long trackerId = celix_bundleContext_trackServices(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ long trackerId = celix_bundleContext_trackServices(NULL, NULL, NULL, NULL, NULL);
CHECK(trackerId < 0); //required ctx and service name missing
- trackerId = celix_bundleContext_trackServices(ctx, NULL, NULL, NULL, NULL, NULL, NULL);
+ trackerId = celix_bundleContext_trackServices(ctx, NULL, NULL, NULL, NULL);
CHECK(trackerId < 0); //required service name missing
- trackerId = celix_bundleContext_trackServices(ctx, "calc", NULL, NULL, NULL, NULL, NULL);
+ trackerId = celix_bundleContext_trackServices(ctx, "calc", NULL, NULL, NULL);
CHECK(trackerId >= 0); //valid
celix_bundleContext_stopTracker(ctx, trackerId);
@@ -297,7 +297,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) {
CHECK(trackerId < 0); //required ctx and opts missing
trackerId = celix_bundleContext_trackServicesWithOptions(ctx, NULL);
CHECK(trackerId < 0); //required opts missing
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
CHECK(trackerId < 0); //required opts->serviceName missing
@@ -325,7 +325,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredSe
- long trackerId = celix_bundleContext_trackServices(ctx, "calc", NULL, NULL, &count, add, remove);
+ long trackerId = celix_bundleContext_trackServices(ctx, "calc", &count, add, remove);
CHECK(trackerId > 0);
CHECK_EQUAL(2, count);
@@ -363,7 +363,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.serviceName = "calc";
opts.callbackHandle = &count;
@@ -403,7 +403,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.serviceName = "calc";
opts.callbackHandle = &count;
@@ -478,7 +478,7 @@ TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
lock.unlock();
};
- long trackerId = celix_bundleContext_trackServices(ctx, calcName, NULL, NULL, &data, add, remove);
+ long trackerId = celix_bundleContext_trackServices(ctx, calcName, &data, add, remove);
std::thread registerThread{[&]{
long id = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
@@ -558,7 +558,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
long svcId2 = celix_bundleContext_registerService(ctx, "NA", svc2, NULL, NULL);
//starting tracker should lead to first set call
- celix_service_tracker_options_t opts;
+ celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
opts.callbackHandle = (void*)&count;
opts.serviceName = "NA";
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/shell/include/command.h
----------------------------------------------------------------------
diff --git a/shell/include/command.h b/shell/include/command.h
index 0e86dcc..65e4306 100644
--- a/shell/include/command.h
+++ b/shell/include/command.h
@@ -35,6 +35,7 @@
#define OSGI_SHELL_COMMAND_DESCRIPTION "command.description"
static const char * const OSGI_SHELL_COMMAND_SERVICE_NAME = "commandService";
+static const char * const OSGI_SHELL_COMMAND_SERVICE_VERSION = "1.0.0";
typedef struct commandService command_service_t;
typedef command_service_t * command_service_pt;
http://git-wip-us.apache.org/repos/asf/celix/blob/673837fc/shell/src/activator.c
----------------------------------------------------------------------
diff --git a/shell/src/activator.c b/shell/src/activator.c
index ddccff6..b5b8e6e 100644
--- a/shell/src/activator.c
+++ b/shell/src/activator.c
@@ -40,8 +40,8 @@ struct command {
char *description;
char *usage;
command_service_pt service;
- service_registration_pt reg;
properties_pt props;
+ long svcId; //used for service (un)registration
};
struct bundle_instance {
@@ -146,7 +146,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context_ptr, void **_ppt
.usage = "dm [f|full] [<Bundle ID> [<Bundle ID> [...]]]"
};
instance_ptr->std_commands[10] =
- (struct command) { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; /*marker for last element*/
+ (struct command) { NULL, NULL, NULL, NULL, NULL, NULL, -1L }; /*marker for last element*/
unsigned int i = 0;
while (instance_ptr->std_commands[i].exec != NULL) {
@@ -211,14 +211,12 @@ celix_status_t bundleActivator_start(void *_ptr, bundle_context_pt context_ptr)
if (status == CELIX_SUCCESS) {
for (unsigned int i = 0; instance_ptr->std_commands[i].exec != NULL; i++) {
- status = bundleContext_registerService(context_ptr, (char *) OSGI_SHELL_COMMAND_SERVICE_NAME,
- instance_ptr->std_commands[i].service,
- instance_ptr->std_commands[i].props,
- &instance_ptr->std_commands[i].reg);
- if (status != CELIX_SUCCESS) {
- break;
- }
-
+ instance_ptr->std_commands[i].svcId = celix_bundleContext_registerService(
+ context_ptr,
+ OSGI_SHELL_COMMAND_SERVICE_NAME,
+ instance_ptr->std_commands[i].service,
+ OSGI_SHELL_COMMAND_SERVICE_VERSION,
+ instance_ptr->std_commands[i].props);
}
}
@@ -232,9 +230,8 @@ celix_status_t bundleActivator_stop(void *_ptr, bundle_context_pt context_ptr) {
if (instance_ptr) {
for (unsigned int i = 0; instance_ptr->std_commands[i].exec != NULL; i++) {
- if (instance_ptr->std_commands[i].reg != NULL) {
- status = serviceRegistration_unregister(instance_ptr->std_commands[i].reg);
- instance_ptr->std_commands[i].reg = NULL;
+ if (instance_ptr->std_commands[i].svcId >= 0) {
+ celix_bundleContext_unregisterService(context_ptr, instance_ptr->std_commands[i].svcId);
instance_ptr->std_commands[i].props = NULL;
}
}