celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erjanalt...@apache.org
Subject celix git commit: DepMgr-C++: DependencyManager::start starts now only not started components, this makes it possible to add and start components when the DependencyManager is already started.
Date Tue, 17 Apr 2018 09:27:01 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 000259361 -> 184497c35


DepMgr-C++: DependencyManager::start starts now only not started components, this makes it
possible to add and start components when the DependencyManager is already started.


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/184497c3
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/184497c3
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/184497c3

Branch: refs/heads/develop
Commit: 184497c35658294748e1a230718834f5b2019947
Parents: 0002593
Author: Erjan Altena <erjanaltena@gmail.com>
Authored: Tue Apr 17 11:26:34 2018 +0200
Committer: Erjan Altena <erjanaltena@gmail.com>
Committed: Tue Apr 17 11:26:34 2018 +0200

----------------------------------------------------------------------
 .../include/celix/dm/DependencyManager.h        | 25 ++++++++++++++++----
 .../include/celix/dm/DependencyManager_Impl.h   |  3 ++-
 2 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/184497c3/dependency_manager_cxx/include/celix/dm/DependencyManager.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/DependencyManager.h b/dependency_manager_cxx/include/celix/dm/DependencyManager.h
index f079b35..e51a4d7 100644
--- a/dependency_manager_cxx/include/celix/dm/DependencyManager.h
+++ b/dependency_manager_cxx/include/celix/dm/DependencyManager.h
@@ -29,6 +29,7 @@
 #include "dm_dependency_manager.h"
 
 #include <vector>
+#include <mutex>
 
 namespace celix { namespace dm {
 
@@ -44,7 +45,15 @@ namespace celix { namespace dm {
                 this->cDepMan = nullptr;
         }
 
-        DependencyManager(DependencyManager&&) = default;
+        DependencyManager(DependencyManager&& mgr) : componentsMutex{} {
+                std::lock_guard<std::mutex> lock(componentsMutex);
+                mgr.context = context;
+                mgr.queuedComponents = std::move(queuedComponents);
+                mgr.startedComponents = std::move(startedComponents);
+                mgr.cDepMan = cDepMan;
+                cDepMan = nullptr;
+                context = nullptr;
+        }
         DependencyManager& operator=(DependencyManager&&) = default;
 
         DependencyManager(const DependencyManager&) = delete;
@@ -93,9 +102,12 @@ namespace celix { namespace dm {
          * Starts the Dependency Manager
          */
         void start() {
-                for(std::unique_ptr<BaseComponent>& cmp : components)  {
-                        dependencyManager_add(cDepMan, cmp->cComponent());
+                std::lock_guard<std::mutex> lock(componentsMutex);
+                for (auto it = queuedComponents.begin(); it != queuedComponents.end(); ++it)
{
+                        dependencyManager_add(cDepMan, (*it)->cComponent());
+                        startedComponents.push_back(std::move(*it));
                 }
+                queuedComponents.clear();
         }
 
         /**
@@ -103,12 +115,15 @@ namespace celix { namespace dm {
          */
         void stop() {
                 dependencyManager_removeAllComponents(cDepMan);
-                components.clear();
+                queuedComponents.clear();
+                startedComponents.clear();
         }
     private:
         bundle_context_pt context {nullptr};
-        std::vector<std::unique_ptr<BaseComponent>> components {};
+        std::vector<std::unique_ptr<BaseComponent>> queuedComponents {};
+        std::vector<std::unique_ptr<BaseComponent>> startedComponents {};
         dm_dependency_manager_pt cDepMan {nullptr};
+        std::mutex componentsMutex{};
     };
 
 }}

http://git-wip-us.apache.org/repos/asf/celix/blob/184497c3/dependency_manager_cxx/include/celix/dm/DependencyManager_Impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/DependencyManager_Impl.h b/dependency_manager_cxx/include/celix/dm/DependencyManager_Impl.h
index 70cbcca..5714ef0 100644
--- a/dependency_manager_cxx/include/celix/dm/DependencyManager_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/DependencyManager_Impl.h
@@ -25,7 +25,8 @@ Component<T>& DependencyManager::createComponent(std::string name)
{
                         Component<T>::create(this->context) :
                         Component<T>::create(this->context, name);
     if (cmp->isValid()) {
-        this->components.push_back(std::unique_ptr<BaseComponent> {cmp});
+        std::lock_guard<std::mutex> lock(componentsMutex);
+        this->queuedComponents.push_back(std::unique_ptr<BaseComponent> {cmp});
     }
     return *cmp;
 }


Mime
View raw message