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/13 10:47:47 UTC
celix git commit: CELIX-446: Adds
celix_bundleContext_registerServiceWithOptions api,
refactors previous registerService api.
Repository: celix
Updated Branches:
refs/heads/develop 3ba41cad6 -> 3391d88d0
CELIX-446: Adds celix_bundleContext_registerServiceWithOptions api, refactors previous registerService api.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3391d88d
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3391d88d
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3391d88d
Branch: refs/heads/develop
Commit: 3391d88d09956a5df09eece9b8ad37009bb30484
Parents: 3ba41ca
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Sun May 13 12:47:04 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Sun May 13 12:47:04 2018 +0200
----------------------------------------------------------------------
.../src/dynamic_provider_example.c | 2 +-
.../src/simple_provider_example.c | 2 +-
framework/include/bundle_context.h | 117 ++++++++++++-------
framework/private/mock/bundle_context_mock.c | 29 +----
framework/src/bundle_context.c | 64 +++++-----
framework/tst/bundle_context_services_test.cpp | 50 ++++----
shell/src/activator.c | 12 +-
7 files changed, 143 insertions(+), 133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/dynamic_provider_example.c b/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
index 4127c4b..7a7d9d9 100644
--- a/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
+++ b/examples/celix-examples/services_example_c/src/dynamic_provider_example.c
@@ -65,7 +65,7 @@ void * run(void *handle) {
if (up) {
properties_t *props = properties_create();
celix_properties_setLong(props, OSGI_FRAMEWORK_SERVICE_RANKING, rand());
- data->svcIds[i++] = celix_bundleContext_registerService(data->ctx, EXAMPLE_CALC_NAME, &data->svc, NULL, props);
+ data->svcIds[i++] = celix_bundleContext_registerService(data->ctx, &data->svc, EXAMPLE_CALC_NAME, props);
} else { //down
celix_bundleContext_unregisterService(data->ctx, data->svcIds[i]);
data->svcIds[--i] = -1L;
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/examples/celix-examples/services_example_c/src/simple_provider_example.c
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_c/src/simple_provider_example.c b/examples/celix-examples/services_example_c/src/simple_provider_example.c
index 765a49e..3358903 100644
--- a/examples/celix-examples/services_example_c/src/simple_provider_example.c
+++ b/examples/celix-examples/services_example_c/src/simple_provider_example.c
@@ -54,7 +54,7 @@ celix_status_t bundleActivator_create(celix_bundle_context_t *ctx, void **out) {
celix_status_t bundleActivator_start(void * handle, celix_bundle_context_t *ctx) {
activator_data_t *data = handle;
- data->svcId = celix_bundleContext_registerService(data->ctx, EXAMPLE_CALC_NAME, &data->svc, EXAMPLE_CALC_VERSION, NULL);
+ data->svcId = celix_bundleContext_registerService(data->ctx, &data->svc, EXAMPLE_CALC_NAME, NULL);
printf("Registered calc service with service id %li\n", data->svcId);
return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/framework/include/bundle_context.h
----------------------------------------------------------------------
diff --git a/framework/include/bundle_context.h b/framework/include/bundle_context.h
index 5daaff9..93840b7 100644
--- a/framework/include/bundle_context.h
+++ b/framework/include/bundle_context.h
@@ -196,34 +196,83 @@ bundleContext_getPropertyWithDefault(bundle_context_pt context, const char *name
*/
dm_dependency_manager_t* celix_bundleContext_getDependencyManager(celix_bundle_context_t *ctx);
+
+typedef struct celix_service_registration_options {
+ /**
+ * The service pointer. The actual pointer to the service. For C this is normally a pointer to a struct
+ * with function pointers, but theoretically this can be a pointer to anything (e.g. a pointer to a single function,
+ * or a pointer to a C++ interface implementation, or just a pointer to a data structure).
+ *
+ * The bundle is responsible to keep the service pointer valid as long as it is registered in the Celix framework.
+ */
+ void *svc;
+
+ /**
+ * The service factory pointer.
+ * Note if the factory service is set, the svc field will not be used.
+ *
+ * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the
+ * option to create bundle specific service instances.
+ *
+ * When a service is requested for a bundle the getService of the factory service will be called. This function must
+ * return a valid pointer to a service conform the registered service name or NULL.
+ * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped)
+ * the ungetService function of the service factory will be called.
+ *
+ * The bundle is responsible to keep the service factory pointer valid as long as it is registered in the Celix framework.
+ */
+ celix_service_factory_t *factory;
+
+ /**
+ * The required service name. This is used to identify the service. A fully qualified name with a namespace is
+ * advisable to prevent name collision. (e.g. EXAMPLE_PRESURE_SENSOR).
+ */
+ const char *serviceName;
+
+ /**
+ * The optional service properties. These contain meta information about the service in the
+ * form of string key/values. (e.g. the location of a pressure sensor: location=left-tire).
+ *
+ * When a service is registered the Celix framework will take ownership of the provided properties.
+ * If a registration fails, the properties will be destroyed (freed) by the Celix framework.
+ */
+ celix_properties_t *properties;
+
+ /**
+ * The optional service language. If this is NULL, CELIX_FRAMEWORK_SERVICE_LANGUAGE_C is used.
+ */
+ const char *serviceLanguage;
+
+ /**
+ * The optional service version (in the form of <MAJOR>.<MINOR>.<MICRO>.<QUALIFIER>).
+ * If present consumer of the service can specific which service version range of
+ * a specific service they are interested in. Note that it is the responsibility of the users to ensure that
+ * service in those version range are compatible (binary of source). It is advisable to use semantic versioning
+ * for this.
+ */
+ const char *serviceVersion;
+} celix_service_registration_options_t;
+
+#define CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS { .svc = NULL, \
+ .serviceName = NULL, \
+ .properties = NULL, \
+ .serviceLanguage = NULL, \
+ .serviceVersion = NULL }
+
/**
* Register a C lang service to the framework.
*
* @param ctx The bundle context
- * @param serviceName the service name, cannot be NULL
* @param svc the service object. Normally a pointer to a service struct (e.g. a struct with function pointers)
- * @param serviceVersion The optional service version.
+ * @param serviceName the service name, cannot be NULL
* @param properties The meta properties associated with the service. The service registration will take ownership of the properties (e.g. no destroy needed)
* @return The serviceId, which should be >= 0. If < 0 then the registration was unsuccessful.
*/
-long celix_bundleContext_registerService(celix_bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, celix_properties_t *properties);
-
-/**
-* Register a service for the specified language to the framework.
-*
-* @param ctx The bundle context
-* @param serviceName the service name, cannot be NULL
-* @param svc Pointer to the service. Normally a pointer to a service struct (e.g. a struct with function pointers)
-* @param serviceVersion The optional service version.
-* @param lang The service language. Will be set to CELIX_FRAMEWORK_SERVICE_LANGUAGE_C if NULL is provided.
-* @param properties The meta properties associated with the service. The service registration will take ownership of the properties
-* @return The serviceId, which should >= 0. If < 0 then the registration was unsuccessful.
-*/
-long celix_bundleContext_registerServiceForLang(celix_bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, const char* lang, celix_properties_t *properties);
+long celix_bundleContext_registerService(celix_bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties);
/**
* Register a service factory in the framework (for the C language).
- * THe service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the
+ * The service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the
* option to create bundle specific service instances.
*
* When a service is requested for a bundle the getService of the factory service will be called. This function must
@@ -232,33 +281,22 @@ long celix_bundleContext_registerServiceForLang(celix_bundle_context_t *ctx, con
* the ungetService function of the service factory will be called.
*
* @param ctx The bundle context
- * @param serviceName The required service name of the services this factory will produce.
* @param factory The pointer to the factory service.
- * @param serviceVersion The optional service version.
+ * @param serviceName The required service name of the services this factory will produce.
* @param properties The optional service factory properties. For a service consumer this will be seen as the service properties.
* @return The service id of the service factory or < 0 if the registration was unsuccessful.
*/
-long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, celix_properties_t *properties);
+long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props);
/**
- * Register a service factory in the framework.
- * THe service factory will be called for every bundle requesting/de-requesting a service. This gives the provider the
- * option to create bundle specific service instances.
- *
- * When a service is requested for a bundle the getService of the factory service will be called. This function must
- * return a valid pointer to a service conform the registered service name or NULL.
- * When a service in no longer needed for a bundle (e.g. ending the useService(s) calls when a service tacker is stopped)
- * the ungetService function of the service factory will be called.
- *
- * @param ctx The bundle context
- * @param serviceName The required service name of the services this factory will produce.
- * @param factory The pointer to the factory service.
- * @param serviceVersion The optional service version.
- * @param lang The d service language. Will be set to CELIX_FRAMEWORK_SERVICE_LANGUAGE_C if NULL is provided.
- * @param properties The optional service factory properties. For a service consumer this will be seen as the service properties.
- * @return The service id of the service factory or < 0 if the registration was unsuccessful.
- */
-long celix_bundleContext_registerServiceFactorForLang(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, const char *lang, celix_properties_t *properties);
+* Register a service Celix to the framework using the provded registration options.
+*
+* @param ctx The bundle context
+* @param opts The pointer to the registration options. The options are only in the during registration call.
+* @return The serviceId, which should >= 0. If < 0 then the registration was unsuccessful.
+*/
+long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts);
+
/**
* Unregister the service or service factory with service id.
@@ -565,8 +603,6 @@ bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bundl
* requested bundle tracker ootions.
*/
typedef struct celix_bundle_tracker_options {
- //TODO options to track framework & own bundle
-
/**
* Handle used in the tracker callbacks.
*/
@@ -612,7 +648,6 @@ long celix_bundleContext_trackBundlesWithOptions(
const celix_bundle_tracker_options_t *opts
);
-//TODO except framework & own bundle
/**
* track bundles
* The add bundle callback will also be called for already installed bundles.
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/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 b763b5a..9d3fe85 100644
--- a/framework/private/mock/bundle_context_mock.c
+++ b/framework/private/mock/bundle_context_mock.c
@@ -194,24 +194,19 @@ celix_status_t bundleContext_getProperty(bundle_context_pt context, const char *
return mock_c()->returnValue().value.intValue;
}
-long celix_bundleContext_registerService(bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, properties_t *properties) {
+long celix_bundleContext_registerService(bundle_context_t *ctx, void *svc, const char *serviceName, properties_t *properties) {
mock_c()->actualCall("celix_bundleContext_registerCService")
->withPointerParameters("ctx", ctx)
->withStringParameters("serviceName", serviceName)
->withPointerParameters("svc", svc)
- ->withPointerParameters("properties", properties)
- ->withStringParameters("serviceName", serviceVersion);
+ ->withPointerParameters("properties", properties);
return mock_c()->returnValue().value.longIntValue;
}
-long celix_bundleContext_registerServiceForLang(bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, const char* lang, properties_t *properties) {
- mock_c()->actualCall("celix_bundleContext_registerServiceForLang")
+long celix_bundleContext_registerServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_registration_options_t *opts) {
+ mock_c()->actualCall("celix_bundleContext_registerServiceWithOptions")
->withPointerParameters("ctx", ctx)
- ->withStringParameters("serviceName", serviceName)
- ->withConstPointerParameters("svc", svc)
- ->withPointerParameters("properties", properties)
- ->withStringParameters("serviceName", serviceVersion)
- ->withStringParameters("lang", lang);
+ ->withConstPointerParameters("opts", opts);
return mock_c()->returnValue().value.longIntValue;
}
@@ -327,23 +322,11 @@ void celix_bundleContext_useServicesWithOptions(
->withConstPointerParameters("opts", opts);
}
-long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, celix_properties_t *props) {
+long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props) {
mock_c()->actualCall("celix_bundleContext_registerServiceFactory")
->withPointerParameters("ctx", ctx)
->withStringParameters("serviceName", serviceName)
->withPointerParameters("factory", factory)
- ->withStringParameters("serviceVersion", serviceVersion)
- ->withPointerParameters("props", props);
- return mock_c()->returnValue().value.longIntValue;
-}
-
-long celix_bundleContext_registerServiceFactorForLang(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, const char *lang, celix_properties_t *props) {
- mock_c()->actualCall("celix_bundleContext_registerServiceFactorForLang")
- ->withPointerParameters("ctx", ctx)
- ->withStringParameters("serviceName", serviceName)
- ->withPointerParameters("factory", factory)
- ->withStringParameters("serviceVersion", serviceVersion)
- ->withStringParameters("lang", lang)
->withPointerParameters("props", props);
return mock_c()->returnValue().value.longIntValue;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/framework/src/bundle_context.c b/framework/src/bundle_context.c
index ffb1704..f79d101 100644
--- a/framework/src/bundle_context.c
+++ b/framework/src/bundle_context.c
@@ -425,29 +425,47 @@ celix_status_t bundleContext_getPropertyWithDefault(bundle_context_pt context, c
**********************************************************************************************************************/
-long celix_bundleContext_registerService(bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, properties_t *properties) {
- return celix_bundleContext_registerServiceForLang(ctx, serviceName, svc, serviceVersion, NULL, properties);
+long celix_bundleContext_registerService(bundle_context_t *ctx, void *svc, const char *serviceName, celix_properties_t *properties) {
+ celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+ opts.svc = svc;
+ opts.serviceName = serviceName;
+ opts.properties = properties;
+ return celix_bundleContext_registerServiceWithOptions(ctx, &opts);
}
-long celix_bundleContext_registerServiceForLang(bundle_context_t *ctx, const char *serviceName, void *svc, const char *serviceVersion, const char* lang, properties_t *properties) {
+long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, celix_service_factory_t *factory, const char *serviceName, celix_properties_t *props) {
+ celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+ opts.factory = factory;
+ opts.serviceName = serviceName;
+ opts.properties = props;
+ return celix_bundleContext_registerServiceWithOptions(ctx, &opts);
+}
+
+long celix_bundleContext_registerServiceWithOptions(bundle_context_t *ctx, const celix_service_registration_options_t *opts) {
long svcId = -1;
service_registration_t *reg = NULL;
- if (properties == NULL) {
- properties = properties_create();
+ celix_properties_t *props = opts->properties;
+ if (props == NULL) {
+ props = celix_properties_create();
}
- if (serviceVersion != NULL) {
- properties_set(properties, CELIX_FRAMEWORK_SERVICE_VERSION, serviceVersion);
+ if (opts->serviceVersion != NULL && strncmp("", opts->serviceVersion, 1) != 0) {
+ celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_VERSION, opts->serviceVersion);
}
- if (serviceName != NULL) {
- properties_set(properties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, lang == NULL ? CELIX_FRAMEWORK_SERVICE_C_LANGUAGE : lang);
- bundleContext_registerService(ctx, serviceName, svc, properties, ®);
+ const char *lang = opts->serviceLanguage != NULL && strncmp("", opts->serviceLanguage, 1) != 0 ? opts->serviceLanguage : CELIX_FRAMEWORK_SERVICE_C_LANGUAGE;
+ celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, lang);
+ if (opts->serviceName != NULL && strncmp("", opts->serviceName, 1) != 0) {
+ if (opts->factory != NULL) {
+ reg = celix_framework_registerServiceFactory(ctx->framework, ctx->bundle, opts->serviceName, opts->factory, props);
+ } else {
+ bundleContext_registerService(ctx, opts->serviceName, opts->svc, props, ®);
+ }
svcId = serviceRegistration_getServiceId(reg); //save to call with NULL
} else {
framework_logIfError(logger, CELIX_ILLEGAL_ARGUMENT, NULL, "Required serviceName argument is NULL");
}
if (svcId < 0) {
- properties_destroy(properties);
+ properties_destroy(props);
} else {
celixThreadMutex_lock(&ctx->mutex);
arrayList_add(ctx->svcRegistrations, reg);
@@ -803,30 +821,6 @@ long celix_bundleContext_trackServicesWithOptions(bundle_context_t *ctx, const c
return trackerId;
}
-long celix_bundleContext_registerServiceFactory(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, celix_properties_t *props) {
- return celix_bundleContext_registerServiceFactorForLang(ctx, serviceName, factory, serviceVersion, NULL, props);
-}
-
-long celix_bundleContext_registerServiceFactorForLang(celix_bundle_context_t *ctx, const char *serviceName, celix_service_factory_t *factory, const char *serviceVersion, const char *lang, celix_properties_t *props) {
- if (props == NULL) {
- props = celix_properties_create();
- }
- if (serviceVersion != NULL) {
- celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_VERSION, serviceVersion);
- }
- celix_properties_set(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, lang == NULL ? CELIX_FRAMEWORK_SERVICE_C_LANGUAGE : lang);
- service_registration_t *reg = celix_framework_registerServiceFactory(ctx->framework, ctx->bundle, serviceName, factory, props);
- long facId = serviceRegistration_getServiceId(reg); //save to call with NULL
- if (facId < 0) {
- properties_destroy(props);
- } else {
- celixThreadMutex_lock(&ctx->mutex);
- arrayList_add(ctx->svcRegistrations, reg);
- celixThreadMutex_unlock(&ctx->mutex);
- }
- return facId;
-}
-
long celix_bundleContext_findService(celix_bundle_context_t *ctx, const char *serviceName) {
celix_service_filter_options_t opts = CELIX_EMPTY_SERVICE_FILTER_OPTIONS;
opts.serviceName = serviceName;
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/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 ec7b92d..9162212 100644
--- a/framework/tst/bundle_context_services_test.cpp
+++ b/framework/tst/bundle_context_services_test.cpp
@@ -70,7 +70,7 @@ TEST(CelixBundleContextServicesTests, registerService) {
return n * 42;
};
- long svcId = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId >= 0);
celix_bundleContext_unregisterService(ctx, svcId);
};
@@ -93,13 +93,13 @@ TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
return n * 42;
};
- long svcId1 = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId1 >= 0);
- long svcId2 = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId2 >= 0);
- long svcId3 = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId3 = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId3 >= 0);
auto use = [](void *handle, void *svc) {
@@ -140,7 +140,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseService) {
return n * 42;
};
- long svcId = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId >= 0);
int result = 0;
@@ -179,7 +179,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
return n * 42;
};
- long svcId = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
CHECK(svcId >= 0);
struct sync {
@@ -265,11 +265,11 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTest) {
CHECK(trackerId > 0);
CHECK_EQUAL(0, count);
- long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", NULL);
CHECK(svcId1 > 0);
CHECK_EQUAL(1, count);
- long svcId2 = celix_bundleContext_registerService(ctx, "calc", (void*)0x200, NULL, NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", NULL);
CHECK(svcId2 > 0);
CHECK_EQUAL(2, count);
@@ -318,8 +318,8 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredSe
*c -= 1;
};
- long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x010, NULL, NULL);
- long svcId2 = celix_bundleContext_registerService(ctx, "calc", (void*)0x020, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x010, "calc", NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x020, "calc", NULL);
@@ -327,11 +327,11 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredSe
CHECK(trackerId > 0);
CHECK_EQUAL(2, count);
- long svcId3 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
+ long svcId3 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", NULL);
CHECK(svcId1 > 0);
CHECK_EQUAL(3, count);
- long svcId4 = celix_bundleContext_registerService(ctx, "calc", (void*)0x200, NULL, NULL);
+ long svcId4 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", NULL);
CHECK(svcId2 > 0);
CHECK_EQUAL(4, count);
@@ -359,7 +359,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
*c -= 1;
};
- long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", NULL);
celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
@@ -371,7 +371,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
CHECK(trackerId > 0);
CHECK_EQUAL(1, count);
- long svcId2 = celix_bundleContext_registerService(ctx, "calc", (void*)0x200, NULL, NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", NULL);
CHECK(svcId1 > 0);
CHECK_EQUAL(2, count);
@@ -399,7 +399,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
*c -= 1;
};
- long svcId1 = celix_bundleContext_registerService(ctx, "calc", (void*)0x100, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", NULL);
celix_service_tracking_options_t opts;
memset(&opts, 0, sizeof(opts));
@@ -411,7 +411,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
CHECK(trackerId > 0);
CHECK_EQUAL(1, count);
- long svcId2 = celix_bundleContext_registerService(ctx, "calc", (void*)0x200, NULL, NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", NULL);
CHECK(svcId1 > 0);
CHECK_EQUAL(2, count);
@@ -479,7 +479,7 @@ TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
long trackerId = celix_bundleContext_trackServices(ctx, calcName, &data, add, remove);
std::thread registerThread{[&]{
- long id = celix_bundleContext_registerService(ctx, calcName, &svc, NULL, NULL);
+ long id = celix_bundleContext_registerService(ctx, &svc, calcName, NULL);
std::cout << "registered service with id " << id << std::endl;
std::lock_guard<std::mutex> lock{data.mutex};
data.svcId = id;
@@ -552,8 +552,8 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
*c = callCount;
};
- long svcId1 = celix_bundleContext_registerService(ctx, "NA", svc1, NULL, NULL);
- long svcId2 = celix_bundleContext_registerService(ctx, "NA", svc2, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, svc1, "NA", NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, svc2, "NA", NULL);
//starting tracker should lead to first set call
celix_service_tracking_options_t opts;
@@ -567,12 +567,12 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
//register svc3 should lead to second set call
properties_t *props3 = celix_properties_create();
celix_properties_set(props3, OSGI_FRAMEWORK_SERVICE_RANKING, "10");
- long svcId3 = celix_bundleContext_registerService(ctx, "NA", svc3, NULL, props3);
+ long svcId3 = celix_bundleContext_registerService(ctx, svc3, "NA", props3);
//register svc4 should lead to no set (lower ranking)
properties_t *props4 = celix_properties_create();
celix_properties_set(props4, OSGI_FRAMEWORK_SERVICE_RANKING, "10");
- long svcId4 = celix_bundleContext_registerService(ctx, "NA", svc4, NULL, props4);
+ long svcId4 = celix_bundleContext_registerService(ctx, svc4, "NA", props4);
//unregister svc3 should lead to set (new highest ranking)
celix_bundleContext_unregisterService(ctx, svcId3);
@@ -593,8 +593,6 @@ TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
int (*calc)(int);
};
auto name = "CALC";
- auto version = "1.0.0";
-
int count = 0;
celix_service_factory_t fac;
@@ -612,7 +610,7 @@ TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
*c += 1;
};
- long facId = celix_bundleContext_registerServiceFactory(ctx, name, &fac, version, NULL);
+ long facId = celix_bundleContext_registerServiceFactory(ctx, &fac, name, NULL);
CHECK_TRUE(facId >= 0);
@@ -631,8 +629,8 @@ TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
}
TEST(CelixBundleContextServicesTests, findServicesTest) {
- long svcId1 = celix_bundleContext_registerService(ctx, "example", (void*)0x100, NULL, NULL);
- long svcId2 = celix_bundleContext_registerService(ctx, "example", (void*)0x100, NULL, NULL);
+ long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", NULL);
+ long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", NULL);
long foundId = celix_bundleContext_findService(ctx, "non existing service name");
CHECK_EQUAL(-1L, foundId);
http://git-wip-us.apache.org/repos/asf/celix/blob/3391d88d/shell/src/activator.c
----------------------------------------------------------------------
diff --git a/shell/src/activator.c b/shell/src/activator.c
index b5b8e6e..16923cf 100644
--- a/shell/src/activator.c
+++ b/shell/src/activator.c
@@ -211,12 +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++) {
- 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);
+ celix_service_registration_options_t opts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+ opts.svc = instance_ptr->std_commands[i].service;
+ opts.serviceName = OSGI_SHELL_COMMAND_SERVICE_NAME;
+ opts.serviceVersion = OSGI_SHELL_COMMAND_SERVICE_VERSION;
+ opts.properties = instance_ptr->std_commands[i].props;
+ instance_ptr->std_commands[i].svcId = celix_bundleContext_registerServiceWithOptions(context_ptr, &opts);
}
}