celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] dhbfischer commented on a change in pull request #286: Feature/async svc registration
Date Fri, 18 Dec 2020 07:47:12 GMT

dhbfischer commented on a change in pull request #286:
URL: https://github.com/apache/celix/pull/286#discussion_r545154911



##########
File path: libs/framework/src/bundle_context.c
##########
@@ -461,52 +505,117 @@ long celix_bundleContext_registerServiceWithOptions(bundle_context_t
*ctx, const
     }
     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,
&reg);
-        }
-        svcId = serviceRegistration_getServiceId(reg); //save to call with NULL
+
+    long svcId = -1;
+    if (!async && celix_framework_isCurrentThreadTheEventLoop(ctx->framework))
{
+        /*
+         * Note already on event loop, cannot register the service async, because we cannot
wait a future event (the
+         * service registration) the event loop.
+         *
+         * So in this case we handle the service registration the "traditional way" and call
the sync fw service
+         * registrations versions on the event loop thread
+         */
+
+        svcId = celix_framework_registerService(ctx->framework, ctx->bundle, opts->serviceName,
opts->svc, opts->factory, props);
     } else {
-        framework_logIfError(ctx->framework->logger, CELIX_ILLEGAL_ARGUMENT, NULL,
"Required serviceName argument is NULL");
+        svcId = celix_framework_registerServiceAsync(ctx->framework, ctx->bundle, opts->serviceName,
opts->svc, opts->factory, props, opts->asyncData, opts->asyncCallback, NULL, NULL);
+        if (!async && svcId >= 0) {
+            //note on event loop thread, but in a sync call, so waiting till service registration
is concluded
+            celix_bundleContext_waitForAsyncRegistration(ctx, svcId);
+        }
     }
+
+
     if (svcId < 0) {
         properties_destroy(props);
     } else {
         celixThreadMutex_lock(&ctx->mutex);
-        arrayList_add(ctx->svcRegistrations, reg);
+        celix_arrayList_addLong(ctx->svcRegistrations, svcId);
         celixThreadMutex_unlock(&ctx->mutex);
+        if (!async) {

Review comment:
       Why calling an async callback in a non async function?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message