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

pnoltes pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/develop by this push:
     new 67910a2  CELIX-464: Some small improvments in the dep man
67910a2 is described below

commit 67910a2f09cf351ba37701739413118e182f6e7f
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue Aug 27 21:49:45 2019 +0200

    CELIX-464: Some small improvments in the dep man
---
 libs/framework/include/celix/dm/DependencyManager.h | 13 ++++++++++---
 libs/framework/include/celix_dependency_manager.h   |  5 +++++
 libs/framework/include/celix_dm_component.h         |  2 ++
 libs/framework/src/dm_component_impl.c              |  6 ++++++
 libs/framework/src/dm_dependency_manager_impl.c     | 19 +++++++++++++++++++
 5 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/libs/framework/include/celix/dm/DependencyManager.h 
b/libs/framework/include/celix/dm/DependencyManager.h
index c00872d..eed174d 100644
--- a/libs/framework/include/celix/dm/DependencyManager.h
+++ b/libs/framework/include/celix/dm/DependencyManager.h
@@ -131,9 +131,16 @@ namespace celix { namespace dm {
          * Stops the Dependency Manager
          */
         void stop() {
-                celix_dependencyManager_removeAllComponents(cDepMan);
-                queuedComponents.clear();
-                startedComponents.clear();
+            std::vector<std::unique_ptr<BaseComponent>> clearStarted{};
+            std::vector<std::unique_ptr<BaseComponent>> clearQueued{};
+            celix_dependencyManager_removeAllComponents(cDepMan);
+            {
+                std::lock_guard<std::recursive_mutex> lock(componentsMutex);
+                std::swap(startedComponents, clearStarted);
+                std::swap(queuedComponents, clearQueued);
+            }
+            clearStarted.clear();
+            clearQueued.clear();
         }
     private:
         celix_bundle_context_t *context {nullptr};
diff --git a/libs/framework/include/celix_dependency_manager.h 
b/libs/framework/include/celix_dependency_manager.h
index e850d0a..82ee3a1 100644
--- a/libs/framework/include/celix_dependency_manager.h
+++ b/libs/framework/include/celix_dependency_manager.h
@@ -70,6 +70,11 @@ celix_dependency_manager_info_t* 
celix_dependencyManager_createInfo(celix_depend
 celix_array_list_t * /*celix_dependency_manager_info_t entries*/ 
celix_dependencyManager_createInfos(celix_dependency_manager_t *manager);
 
 /**
+ * Check if all components - for all bundles - are active (all required 
dependencies resolved).
+ */
+bool celix_dependencyManager_allComponentsActive(celix_dependency_manager_t 
*manager);
+
+/**
  * Destroys a DM info struct.
  */
 void celix_dependencyManager_destroyInfo(celix_dependency_manager_t *manager, 
celix_dependency_manager_info_t *info);
diff --git a/libs/framework/include/celix_dm_component.h 
b/libs/framework/include/celix_dm_component.h
index 12bb06d..50b3750 100644
--- a/libs/framework/include/celix_dm_component.h
+++ b/libs/framework/include/celix_dm_component.h
@@ -142,6 +142,8 @@ celix_status_t 
celix_dmComponent_setCallbacks(celix_dm_component_t *component, c
  */
 celix_status_t celix_dmComponent_getComponentInfo(celix_dm_component_t 
*component, dm_component_info_pt *info);
 
+bool celix_dmComponent_isActive(celix_dm_component_t *component);
+
 /**
  * Destroys a DM Component info struct.
  */
diff --git a/libs/framework/src/dm_component_impl.c 
b/libs/framework/src/dm_component_impl.c
index 45406d1..072910c 100644
--- a/libs/framework/src/dm_component_impl.c
+++ b/libs/framework/src/dm_component_impl.c
@@ -1533,3 +1533,9 @@ void 
celix_dmComponent_destroyComponentInfo(dm_component_info_pt info) {
     }
     free(info);
 }
+
+bool celix_dmComponent_isActive(celix_dm_component_t *component) {
+    pthread_mutex_lock(&component->mutex);
+    return component->active;
+    pthread_mutex_unlock(&component->mutex);
+}
diff --git a/libs/framework/src/dm_dependency_manager_impl.c 
b/libs/framework/src/dm_dependency_manager_impl.c
index b306335..3b0aa0f 100644
--- a/libs/framework/src/dm_dependency_manager_impl.c
+++ b/libs/framework/src/dm_dependency_manager_impl.c
@@ -164,6 +164,25 @@ celix_array_list_t * 
celix_dependencyManager_createInfos(celix_dependency_manage
        return infos;
 }
 
+static void celix_dm_allComponentsActiveCallback(void *handle, const 
celix_bundle_t *bnd) {
+       bool *allActivePtr = handle;
+       celix_bundle_context_t *context = NULL;
+       bundle_getContext((celix_bundle_t*)bnd, &context);
+       celix_dependency_manager_t *mng = 
celix_bundleContext_getDependencyManager(context);
+       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);
+               if (!celix_dmComponent_isActive(cmp)) {
+                       *allActivePtr = false;
+               }
+       }
+}
+
+bool celix_dependencyManager_allComponentsActive(celix_dependency_manager_t 
*manager) {
+       bool allActive = true;
+       celix_bundleContext_useBundles(manager->ctx, &allActive, 
celix_dm_allComponentsActiveCallback);
+       return allActive;
+}
 
 void celix_dependencyManager_destroyInfo(celix_dependency_manager_t *manager 
__attribute__((unused)), celix_dependency_manager_info_t *info) {
        for (int i = 0; i < celix_arrayList_size(info->components); i += 1) {

Reply via email to