This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/585-celix-conditions
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 69fb405da10248bdee83f592c51b5e8f8a25bb2c
Author: Pepijn Noltes <[email protected]>
AuthorDate: Wed Jun 28 17:22:19 2023 +0200

    Disable condition in framwork
---
 libs/framework/CMakeLists.txt                   |   1 -
 libs/framework/src/celix_framework_conditions.c | 200 +++++++++++++-----------
 libs/framework/src/celix_framework_conditions.h |  47 +++---
 libs/framework/src/framework.c                  |  18 +--
 libs/framework/src/framework_private.h          |   6 -
 5 files changed, 134 insertions(+), 138 deletions(-)

diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index a0c71fc8..82968846 100644
--- a/libs/framework/CMakeLists.txt
+++ b/libs/framework/CMakeLists.txt
@@ -34,7 +34,6 @@ set(FRAMEWORK_SRC
         src/framework_bundle_lifecycle_handler.c
         src/celix_bundle_state.c
         src/celix_framework_utils.c
-        src/celix_framework_conditions.c
         src/celix_module_private.h)
 set(FRAMEWORK_DEPS libuuid::libuuid CURL::libcurl ZLIB::ZLIB ${CMAKE_DL_LIBS})
 
diff --git a/libs/framework/src/celix_framework_conditions.c 
b/libs/framework/src/celix_framework_conditions.c
index 3105baf3..2f717a7c 100644
--- a/libs/framework/src/celix_framework_conditions.c
+++ b/libs/framework/src/celix_framework_conditions.c
@@ -1,107 +1,129 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*   http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-*  KIND, either express or implied.  See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 
-#include "framework_private.h"
 #include "celix_condition.h"
 #include "celix_constants.h"
+#include "framework_private.h"
 
 void celix_frameworkConditions_registerInitialConditions(celix_framework_t* 
framework) {
-    long svcId = -1L;
-    celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
-    celixThreadMutex_lock(&framework->conditions.mutex);
-    celix_service_registration_options_t opts = 
CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
-    opts.serviceName = CELIX_CONDITION_SERVICE_NAME;
-    opts.serviceVersion = CELIX_CONDITION_SERVICE_VERSION;
-    opts.svc = &CELIX_CONDITION_INSTANCE;
-    opts.properties = celix_properties_create();
-    if (opts.properties) {
-        celix_properties_set(opts.properties, CELIX_CONDITION_ID, 
CELIX_CONDITION_ID_FRAMEWORK_READY);
-        svcId = celix_bundleContext_registerServiceWithOptionsAsync(ctx, 
&opts);
-    }
-    celix_status_t addStatus = 
celix_arrayList_add(framework->conditions.initialConditionSvcIds, (void*)svcId);
-    if (addStatus != CELIX_SUCCESS) {
-        celix_bundleContext_unregisterService(ctx, svcId);
-        fw_log(framework->logger, CELIX_LOG_LEVEL_ERROR, "Error adding initial 
condition service id to list");
-    }
-    celixThreadMutex_unlock(&framework->conditions.mutex);
-}
-
-void celix_frameworkConditions_unregisterInitialConditions(celix_framework_t* 
framework) {
-    celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
-    celixThreadMutex_lock(&framework->conditions.mutex);
-    for (int i = 0; i < 
celix_arrayList_size(framework->conditions.initialConditionSvcIds); ++i) {
-        long svcId = 
(long)celix_arrayList_get(framework->conditions.initialConditionSvcIds, i);
-        celix_bundleContext_unregisterServiceAsync(ctx, svcId, NULL, NULL);
-    }
-    celix_arrayList_clear(framework->conditions.initialConditionSvcIds);
-    celixThreadMutex_unlock(&framework->conditions.mutex);
+    // long svcId = -1L;
+    // celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
+    // celixThreadMutex_lock(&framework->conditions.mutex);
+    // celix_service_registration_options_t opts = 
CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+    // opts.serviceName = CELIX_CONDITION_SERVICE_NAME;
+    // opts.serviceVersion = CELIX_CONDITION_SERVICE_VERSION;
+    // opts.svc = &CELIX_CONDITION_INSTANCE;
+    // opts.properties = celix_properties_create();
+    // if (opts.properties) {
+    //     celix_properties_set(opts.properties, CELIX_CONDITION_ID, 
CELIX_CONDITION_ID_TRUE);
+    //     svcId = celix_bundleContext_registerServiceWithOptionsAsync(ctx, 
&opts);
+    // }
+    // celix_status_t addStatus = 
celix_arrayList_addLong(framework->conditions.initialConditionSvcIds, svcId);
+    // if (addStatus != CELIX_SUCCESS) {
+    //     celix_bundleContext_unregisterService(ctx, svcId);
+    //     fw_log(framework->logger, CELIX_LOG_LEVEL_ERROR, "Error adding 
initial condition service id to list");
+    // }
+    // celixThreadMutex_unlock(&framework->conditions.mutex);
 }
 
 static void celix_frameworkConditions_checkFrameworkReady(void* data) {
-    celix_framework_t* framework = data;
-    celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
+    // celix_framework_t* framework = data;
+    // celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
 
-    celixThreadMutex_lock(&framework->dispatcher.mutex);
-    bool isEventQueueEmpty = framework->dispatcher.eventQueueSize == 0 && 
celix_arrayList_size(framework->dispatcher.dynamicEventQueue) == 0;
-    bool isActive = framework->dispatcher.active;
-    celixThreadMutex_unlock(&framework->dispatcher.mutex);
+    // celixThreadMutex_lock(&framework->dispatcher.mutex);
+    // int eventQueueSize =
+    //     framework->dispatcher.eventQueueSize + 
celix_arrayList_size(framework->dispatcher.dynamicEventQueue);
+    // bool ready = celix_framework_isCurrentThreadTheEventLoop(framework) ?
+    //         eventQueueSize == 1: /*note 1, because 
celix_frameworkConditions_checkFrameworkReady is called from an event*/
+    //         eventQueueSize == 0;
+    // bool cancel = framework->conditions.cancelRegistrations;
+    // celixThreadMutex_unlock(&framework->dispatcher.mutex);
 
-    if (!isActive) {
-        fw_log(framework->logger, CELIX_LOG_LEVEL_DEBUG, "Framework is not 
active anymore, so no need to register the framework ready condition");
-        return;
-    }
+    // if (cancel) {
+    //     fw_log(framework->logger,
+    //            CELIX_LOG_LEVEL_DEBUG,
+    //            "Framework is stopping or not active anymore, so no need to 
register the framework ready condition");
+    //     return;
+    // }
 
-    if (isEventQueueEmpty) {
-        celixThreadMutex_lock(&framework->conditions.mutex);
-        celix_service_registration_options_t opts = 
CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
-        opts.serviceName = CELIX_CONDITION_SERVICE_NAME;
-        opts.serviceVersion = CELIX_CONDITION_SERVICE_VERSION;
-        opts.svc = &CELIX_CONDITION_INSTANCE;
-        opts.properties = celix_properties_create();
-        if (opts.properties) {
-            celix_properties_set(opts.properties, CELIX_CONDITION_ID, 
CELIX_CONDITION_ID_FRAMEWORK_READY);
-            long svcId = 
celix_bundleContext_registerServiceWithOptionsAsync(ctx, &opts);
-            celix_status_t addStatus = 
celix_arrayList_add(framework->conditions.frameworkReadyConditionSvcIds, 
(void*)svcId);
-            if (addStatus != CELIX_SUCCESS) {
-                celix_bundleContext_unregisterService(ctx, svcId);
-                fw_log(framework->logger, CELIX_LOG_LEVEL_ERROR, "Error adding 
framework ready condition service id to list");
-            }
-        }
-        celixThreadMutex_unlock(&framework->conditions.mutex);
-    } else {
-        //try again later on the event queue
-        celix_framework_fireGenericEvent(framework, -1, 
CELIX_FRAMEWORK_BUNDLE_ID, "Check event queue for framework ready condition 
service", framework, celix_frameworkConditions_checkFrameworkReady, NULL, NULL);
-    }
+    // if (ready) {
+    //     celixThreadMutex_lock(&framework->conditions.mutex);
+    //     celix_service_registration_options_t opts = 
CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+    //     opts.serviceName = CELIX_CONDITION_SERVICE_NAME;
+    //     opts.serviceVersion = CELIX_CONDITION_SERVICE_VERSION;
+    //     opts.svc = &CELIX_CONDITION_INSTANCE;
+    //     opts.properties = celix_properties_create();
+    //     if (opts.properties) {
+    //         celix_properties_set(opts.properties, CELIX_CONDITION_ID, 
CELIX_CONDITION_ID_FRAMEWORK_READY);
+    //         long svcId = 
celix_bundleContext_registerServiceWithOptionsAsync(ctx, &opts);
+    //         celix_status_t addStatus =
+    //             
celix_arrayList_addLong(framework->conditions.frameworkReadyConditionSvcIds, 
svcId);
+    //         if (addStatus != CELIX_SUCCESS) {
+    //             celix_bundleContext_unregisterService(ctx, svcId);
+    //             fw_log(framework->logger,
+    //                    CELIX_LOG_LEVEL_ERROR,
+    //                    "Error adding framework ready condition service id 
to list");
+    //         }
+    //     }
+    //     celixThreadMutex_unlock(&framework->conditions.mutex);
+    // } else {
+    //     // try again later on the event queue
+    //     fprintf(stderr,
+    //             "Event queue not empty, so try again later. bundle state is 
%s\n",
+    //             
celix_bundleState_getName(celix_bundle_getState(framework->bundle))); // TODO 
remove
+    //     celix_framework_fireGenericEvent(framework,
+    //                                      -1,
+    //                                      CELIX_FRAMEWORK_BUNDLE_ID,
+    //                                      "Check event queue for framework 
ready condition service",
+    //                                      framework,
+    //                                      
celix_frameworkConditions_checkFrameworkReady,
+    //                                      NULL,
+    //                                      NULL);
+    // }
 }
 
 void 
celix_frameworkConditions_registerFrameworkReadyConditions(celix_framework_t* 
framework) {
-    //note called when all bundles are installed and started
+    // note called when all bundles are installed and started
     celix_frameworkConditions_checkFrameworkReady(framework);
 }
 
-void 
celix_frameworkConditions_unregisterFrameworkReadyConditions(celix_framework_t* 
framework) {
-    celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
-    celixThreadMutex_lock(&framework->conditions.mutex);
-    for (int i = 0; i < 
celix_arrayList_size(framework->conditions.frameworkReadyConditionSvcIds); ++i) 
{
-        long svcId = 
(long)celix_arrayList_get(framework->conditions.frameworkReadyConditionSvcIds, 
i);
-        celix_bundleContext_unregisterServiceAsync(ctx, svcId, NULL, NULL);
-    }
-    celix_arrayList_clear(framework->conditions.frameworkReadyConditionSvcIds);
-    celixThreadMutex_unlock(&framework->conditions.mutex);
-}
\ No newline at end of file
+// TODO rename to cleanup
+void celix_frameworkConditions_unregisterConditions(celix_framework_t* 
framework) {
+    // celix_bundle_context_t* ctx = 
celix_framework_getFrameworkContext(framework);
+
+    // celixThreadMutex_lock(&framework->conditions.mutex);
+    // framework->conditions.cancelRegistrations = true;
+    // celixThreadMutex_unlock(&framework->conditions.mutex);
+    // celix_framework_waitUntilNoEventsForBnd(framework, 
CELIX_FRAMEWORK_BUNDLE_ID); //TODO maybe remove
+
+    // celixThreadMutex_lock(&framework->conditions.mutex);
+    // for (int i = 0; i < 
celix_arrayList_size(framework->conditions.initialConditionSvcIds); ++i) {
+    //     long svcId = 
(long)celix_arrayList_getLong(framework->conditions.initialConditionSvcIds, i);
+    //     fprintf(stderr, "Unregistering svc id %li\n", svcId);
+    //     celix_bundleContext_unregisterServiceAsync(ctx, svcId, NULL, NULL);
+    // }
+    // celix_arrayList_clear(framework->conditions.initialConditionSvcIds);
+    // for (int i = 0; i < 
celix_arrayList_size(framework->conditions.frameworkReadyConditionSvcIds); ++i) 
{
+    //     long svcId = 
(long)celix_arrayList_getLong(framework->conditions.frameworkReadyConditionSvcIds,
 i);
+    //     fprintf(stderr, "Unregistering svc id %li\n", svcId);
+    //     celix_bundleContext_unregisterServiceAsync(ctx, svcId, NULL, NULL);
+    // }
+    // 
celix_arrayList_clear(framework->conditions.frameworkReadyConditionSvcIds);
+    // celixThreadMutex_unlock(&framework->conditions.mutex);
+}
diff --git a/libs/framework/src/celix_framework_conditions.h 
b/libs/framework/src/celix_framework_conditions.h
index cf9c14ff..a5ce9fdd 100644
--- a/libs/framework/src/celix_framework_conditions.h
+++ b/libs/framework/src/celix_framework_conditions.h
@@ -1,27 +1,27 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*   http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-*  KIND, either express or implied.  See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 
 #ifndef CELIX_CELIX_FRAMEWORK_CONDITIONS_H_
 #define CELIX_CELIX_FRAMEWORK_CONDITIONS_H_
 
-#include "celix_types.h"
 #include "celix_errno.h"
+#include "celix_types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -40,12 +40,6 @@ extern "C" {
  */
 void celix_frameworkConditions_registerInitialConditions(celix_framework_t* 
framework);
 
-/**
- * @brief Unregister the initial celix_condition services for the framework.
- * @param[in] framework The framework.
- */
-void celix_frameworkConditions_unregisterInitialConditions(celix_framework_t* 
framework);
-
 /**
  * @brief Register the framework ready celix_condition services for the 
framework.
  *
@@ -60,11 +54,10 @@ void 
celix_frameworkConditions_unregisterInitialConditions(celix_framework_t* fr
 void 
celix_frameworkConditions_registerFrameworkReadyConditions(celix_framework_t* 
framework);
 
 /**
- * @brief Unregister the framework ready celix_condition services for the 
framework.
+ * @brief Unregister the intial and framework ready celix_condition services 
for the framework.
  * @param framework The framework.
  */
-void 
celix_frameworkConditions_unregisterFrameworkReadyConditions(celix_framework_t* 
framework);
-
+void celix_frameworkConditions_unregisterConditions(celix_framework_t* 
framework);
 
 #ifdef __cplusplus
 }
diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c
index 8962d0f8..12ef7c5b 100644
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@ -36,7 +36,6 @@
 #include "celix_libloader.h"
 #include "celix_log_constants.h"
 #include "celix_module_private.h"
-#include "celix_framework_conditions.h"
 
 #include "bundle_archive_private.h"
 #include "bundle_context_private.h"
@@ -256,10 +255,6 @@ celix_status_t framework_create(framework_pt *out, 
celix_properties_t* config) {
     framework->dispatcher.eventQueue = malloc(sizeof(celix_framework_event_t) 
* framework->dispatcher.eventQueueCap);
     framework->dispatcher.dynamicEventQueue = celix_arrayList_create();
 
-    celixThreadMutex_create(&framework->conditions.mutex, NULL);
-    framework->conditions.initialConditionSvcIds = celix_arrayList_create();
-    framework->conditions.frameworkReadyConditionSvcIds = 
celix_arrayList_create();
-
     //create and store framework uuid
     char uuid[37];
     uuid_t uid;
@@ -482,9 +477,6 @@ celix_status_t framework_start(celix_framework_t* 
framework) {
     CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_STARTED, entry));
     celix_framework_bundleEntry_decreaseUseCount(entry);
 
-    celix_frameworkConditions_registerInitialConditions(framework);
-    CELIX_DO_IF(status, fw_fireFrameworkEvent(framework, 
OSGI_FRAMEWORK_EVENT_STARTED, framework->bundleId));
-
     if (status != CELIX_SUCCESS) {
         status = CELIX_BUNDLE_EXCEPTION;
         fw_logCode(framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Could 
not start framework");
@@ -494,7 +486,7 @@ celix_status_t framework_start(celix_framework_t* 
framework) {
     celix_status_t startStatus = 
framework_autoStartConfiguredBundles(framework);
     celix_status_t installStatus = 
framework_autoInstallConfiguredBundles(framework);
     if (startStatus == CELIX_SUCCESS && installStatus == CELIX_SUCCESS) {
-        celix_frameworkConditions_registerFrameworkReadyConditions(framework);
+        fw_fireFrameworkEvent(framework, OSGI_FRAMEWORK_EVENT_STARTED, 
framework->bundleId); //TODO maybe register framwork.ready on this event and 
only keep the condition true service?
     } else {
         status = CELIX_BUNDLE_EXCEPTION; //error already logged
     }
@@ -1227,11 +1219,10 @@ static void* framework_shutdown(void *framework) {
 
     // 'stop' framework bundle
     if (fwEntry != NULL) {
-        bundle_t *bnd = fwEntry->bnd;
         fw_bundleEntry_waitTillUseCountIs(fwEntry, 1); //note this function 
has 1 use count.
 
         bundle_state_e state;
-        bundle_getState(bnd, &state);
+        bundle_getState(fwEntry->bnd, &state);
         if (state == CELIX_BUNDLE_STATE_ACTIVE || state == 
CELIX_BUNDLE_STATE_STARTING) {
             celix_framework_stopBundleEntry(fw, fwEntry);
         }
@@ -1520,11 +1511,8 @@ static celix_status_t frameworkActivator_stop(void * 
userData, bundle_context_t
     celix_status_t status = CELIX_SUCCESS;
     framework_pt framework;
 
-    if (bundleContext_getFramework(context, &framework) == CELIX_SUCCESS) {
-
-        
celix_frameworkConditions_unregisterFrameworkReadyConditions(framework);
-        celix_frameworkConditions_unregisterInitialConditions(framework);
 
+    if (bundleContext_getFramework(context, &framework) == CELIX_SUCCESS) {
         fw_log(framework->logger, CELIX_LOG_LEVEL_TRACE, "Start shutdown 
thread for framework %s", celix_framework_getUUID(framework));
         celixThreadMutex_lock(&framework->shutdown.mutex);
         bool alreadyInitialized = framework->shutdown.initialized;
diff --git a/libs/framework/src/framework_private.h 
b/libs/framework/src/framework_private.h
index a06a8c3b..d2a36cfc 100644
--- a/libs/framework/src/framework_private.h
+++ b/libs/framework/src/framework_private.h
@@ -188,12 +188,6 @@ struct celix_framework {
         celix_thread_mutex_t mutex; //protects below
         celix_array_list_t* bundleLifecycleHandlers; //entry = 
celix_framework_bundle_lifecycle_handler_t*
     } bundleLifecycleHandling;
-
-    struct {
-        celix_thread_mutex_t mutex; /**< protects below*/
-        celix_array_list_t* initialConditionSvcIds; /**< entry = long (service 
id) */
-        celix_array_list_t* frameworkReadyConditionSvcIds; /**< entry = long 
(service id) */
-    } conditions; /**< Struct to store the framework celix_conditions admin */
 };
 
 /**

Reply via email to