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

pnoltes pushed a commit to branch hotfix/remove-refresh-bundle-after-uninstall
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to 
refs/heads/hotfix/remove-refresh-bundle-after-uninstall by this push:
     new c907d6a6 Ensure that dm info only gets retrieved for activate bundles
c907d6a6 is described below

commit c907d6a6c6faa4e7a9005015b067d8e5d0d5a307
Author: Pepijn Noltes <[email protected]>
AuthorDate: Thu May 11 23:14:47 2023 +0200

    Ensure that dm info only gets retrieved for activate bundles
---
 libs/framework/src/dm_dependency_manager_impl.c | 46 +++++++++++--------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/libs/framework/src/dm_dependency_manager_impl.c 
b/libs/framework/src/dm_dependency_manager_impl.c
index 0cf8a0e3..1de53a89 100644
--- a/libs/framework/src/dm_dependency_manager_impl.c
+++ b/libs/framework/src/dm_dependency_manager_impl.c
@@ -212,35 +212,34 @@ celix_dependency_manager_info_t* 
celix_dependencyManager_createInfo(celix_depend
        return info;
 }
 
-typedef struct celix_dm_get_info_callback_data {
-    celix_array_list_t *infos;
-    celix_bundle_context_t* ctx;
-} celix_dm_get_info_callback_data_t;
+static void celix_dm_getInfosCallback(void* handle, const celix_bundle_t* bnd) 
{
+    celix_array_list_t* infos = handle;
 
+    if (celix_bundle_getState(bnd) != CELIX_BUNDLE_STATE_ACTIVE) {
+        return;
+    }
 
-static void celix_dm_getInfosCallback(void *handle, const celix_bundle_t *bnd) 
{
-    celix_dm_get_info_callback_data_t *data = handle;
-
-       celix_bundle_context_t *context = NULL;
-       bundle_getContext((celix_bundle_t*)bnd, &context);
-       celix_dependency_manager_t *mng = 
celix_bundleContext_getDependencyManager(context);
+    celix_bundle_context_t* context = NULL;
+    bundle_getContext((celix_bundle_t*)bnd, &context);
+    celix_dependency_manager_t* mng = 
celix_bundleContext_getDependencyManager(context);
 
-       celix_dependency_manager_info_t *info = calloc(1, sizeof(*info));
-       celixThreadMutex_lock(&mng->mutex);
+    celix_dependency_manager_info_t* info = calloc(1, sizeof(*info));
     info->bndId = celix_bundle_getId(bnd);
     info->bndSymbolicName = 
celix_utils_strdup(celix_bundle_getSymbolicName(bnd));
-       celix_array_list_create_options_t opts = 
CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
-       opts.simpleRemovedCallback = (void*)component_destroyComponentInfo;
+    celix_array_list_create_options_t opts = 
CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
+    opts.simpleRemovedCallback = (void*)component_destroyComponentInfo;
     info->components = celix_arrayList_createWithOptions(&opts);
+
+    celixThreadMutex_lock(&mng->mutex);
     int size = celix_arrayList_size(mng->components);
     for (int i = 0; i < size; i += 1) {
-        celix_dm_component_t *cmp = celix_arrayList_get(mng->components, i);
-        celix_dm_component_info_t *cmpInfo = NULL;
+        celix_dm_component_t* cmp = celix_arrayList_get(mng->components, i);
+        celix_dm_component_info_t* cmpInfo = NULL;
         celix_dmComponent_getComponentInfo(cmp, &cmpInfo);
         celix_arrayList_add(info->components, cmpInfo);
     }
-    celix_arrayList_add(data->infos, info);
-       celixThreadMutex_unlock(&mng->mutex);
+    celix_arrayList_add(infos, info);
+    celixThreadMutex_unlock(&mng->mutex);
 }
 
 static void celix_dependencyManager_destroyInfoCallback(void *data, 
celix_array_list_entry_t entry) {
@@ -250,17 +249,14 @@ static void 
celix_dependencyManager_destroyInfoCallback(void *data, celix_array_
 }
 
 celix_array_list_t * 
celix_dependencyManager_createInfos(celix_dependency_manager_t* manager) {
-    celix_dm_get_info_callback_data_t data;
-    data.ctx = manager->ctx;
-
        celix_array_list_create_options_t opts = 
CELIX_EMPTY_ARRAY_LIST_CREATE_OPTIONS;
        opts.removedCallbackData = manager;
        opts.removedCallback = celix_dependencyManager_destroyInfoCallback;
-    data.infos = celix_arrayList_createWithOptions(&opts);
-       celix_framework_t* fw = celix_bundleContext_getFramework(manager->ctx);
+    celix_array_list_t* infos = celix_arrayList_createWithOptions(&opts);
 
-       celix_framework_useBundles(fw, true, &data, celix_dm_getInfosCallback);
-       return data.infos;
+       celix_framework_t* fw = celix_bundleContext_getFramework(manager->ctx);
+       celix_framework_useBundles(fw, true, infos, celix_dm_getInfosCallback);
+       return infos;
 }
 
 static void celix_dm_allComponentsActiveCallback(void *handle, const 
celix_bundle_t *bnd) {

Reply via email to