Repository: celix
Updated Branches:
  refs/heads/develop a431d28de -> 3a8f43437


CELIX-370: Updates C++ DM API. A small diversion from the Java API, too make it 
more natural for C++


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

Branch: refs/heads/develop
Commit: 3a8f4343710cd92efff03695d80ad6d8ae944692
Parents: a431d28
Author: Pepijn Noltes <pepijnnol...@gmail.com>
Authored: Thu Sep 22 20:12:06 2016 +0200
Committer: Pepijn Noltes <pepijnnol...@gmail.com>
Committed: Thu Sep 22 20:12:06 2016 +0200

----------------------------------------------------------------------
 .../include/celix/dm/Component.h                | 55 +++++++--------
 .../include/celix/dm/Component_Impl.h           | 68 ++++++++++++-------
 .../include/celix/dm/DependencyManager.h        | 71 +++-----------------
 .../include/celix/dm/DmActivator.h              | 34 ++--------
 .../include/celix/dm/ServiceDependency.h        |  2 +-
 dependency_manager_cxx/readme.md                | 19 +++---
 dependency_manager_cxx/src/DependencyManager.cc |  4 +-
 .../phase1/src/Phase1Activator.cc               |  6 +-
 .../phase2a/src/Phase2aActivator.cc             | 19 +++---
 .../phase2b/src/Phase2bActivator.cc             | 19 +++---
 .../phase3/src/Phase3Activator.cc               | 18 +++--
 .../src/Phase3LockingActivator.cc               | 11 ++-
 12 files changed, 129 insertions(+), 197 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/include/celix/dm/Component.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/Component.h 
b/dependency_manager_cxx/include/celix/dm/Component.h
index e55044b..4963d9d 100644
--- a/dependency_manager_cxx/include/celix/dm/Component.h
+++ b/dependency_manager_cxx/include/celix/dm/Component.h
@@ -31,6 +31,7 @@
 namespace celix { namespace dm {
 
     class BaseComponent {
+    private:
         bundle_context_pt context {nullptr};
         std::string name {};
         dm_component_pt cCmp {nullptr};
@@ -52,8 +53,10 @@ namespace celix { namespace dm {
 
     template<class T>
     class Component : public BaseComponent {
-        std::shared_ptr<T> instance = {nullptr};
+    private:
+        std::shared_ptr<T> instance {nullptr};
         std::list<T> refInstance {};
+        std::list<std::shared_ptr<BaseServiceDependency>> dependencies {};
 
         void (T::*initFp)() = {};
         void (T::*startFp)() = {};
@@ -64,6 +67,20 @@ namespace celix { namespace dm {
         virtual ~Component();
 
         /**
+         * Creates a Component using the provided bundle context.
+         * Will use new(nothrow) if exceptions are disabled.
+         * @return newly created DM Component or nullptr
+         */
+        static Component<T>* create(bundle_context_pt, std::string name = {});
+
+        /**
+         * Wether the component is valid. Invalid component can occurs when no 
new components can be created and
+         * exceptions are not allowed.
+         * @return
+         */
+        bool isValid() const;
+
+        /**
          * Get the component instance. If no instance is explicitly set with 
setInstance than a instance will be create
          * using a default constructor.
          *
@@ -86,16 +103,6 @@ namespace celix { namespace dm {
          */
         Component<T>& setInstance(T&& inst);
 
-
-        /**
-         * Adds a C++ interface to provide as service to the Celix framework.
-         * The interface name will be inferred using the I template.
-         *
-         * @param version The version of the interface (e.g. "1.0.0"), can be 
an empty string
-         * @return the DM Component reference for chaining (fluent API)
-         */
-        template<class I> Component<T>& addInterface(const std::string 
version);
-
         /**
          * Adds a C++ interface to provide as service to the Celix framework.
          * The interface name will be inferred using the I template.
@@ -104,7 +111,7 @@ namespace celix { namespace dm {
          * @param properties To (meta) properties to provide with the service
          * @return the DM Component reference for chaining (fluent API)
          */
-        template<class I> Component<T>& addInterface(const std::string 
version, const Properties properties);
+        template<class I> Component<T>& addInterface(const std::string 
version, const Properties properties = {});
 
         /**
          * Adds a C++ interface to provide as service to the Celix framework.
@@ -114,7 +121,7 @@ namespace celix { namespace dm {
          * @param properties To (meta) properties to provide with the service
          * @return the DM Component reference for chaining (fluent API)
          */
-        Component<T>& addInterface(const std::string serviceName, const 
std::string version, const Properties properties);
+        Component<T>& addInterface(const std::string serviceName, const 
std::string version = {}, const Properties properties = {});
 
         /**
          * Adds a C interface to provide as service to the Celix framework.
@@ -124,28 +131,19 @@ namespace celix { namespace dm {
          * @param version The version of the interface (e.g. "1.0.0"), can be 
an empty string
          * @param properties To (meta) properties to provide with the service
          */
-        Component<T>& addCInterface(const void* svc, const std::string 
serviceName, const std::string version);
+        Component<T>& addCInterface(const void* svc, const std::string 
serviceName, const std::string version = {}, const Properties properties = {});
 
-        /**
-         * Adds a C interface to provide as service to the Celix framework.
-         *
-         * @param svc The service struct
-         * @param serviceName The service name to use
-         * @param version The version of the interface (e.g. "1.0.0"), can be 
an empty string
-         * @param properties To (meta) properties to provide with the service
-         */
-        Component<T>& addCInterface(const void* svc, const std::string 
serviceName, const std::string version, const Properties properties);
 
         /**
-         * Adds a C++ service dependency to the component
+         * Creates and adds a C++ service dependency to the component
          *
-         * @return the DM Component reference for chaining (fluent API)
+         * @return the Service Dependency reference for chaining (fluent API)
          */
         template<class I>
-        Component<T>& add(ServiceDependency<T,I>& dep);
+        ServiceDependency<T,I>& createServiceDependency();
 
         /**
-         * Removes a C++ service dependency to the component
+         Creates and adds a C++ service dependency to the component
          *
          * @return the DM Component reference for chaining (fluent API)
          */
@@ -158,7 +156,7 @@ namespace celix { namespace dm {
          * @return the DM Component reference for chaining (fluent API)
          */
         template<typename I>
-        Component<T>& add(CServiceDependency<T,I>& dep);
+        CServiceDependency<T,I>& createCServiceDependency();
 
         /**
          * Removes a C service dependency to the component
@@ -185,7 +183,6 @@ namespace celix { namespace dm {
             void (T::*deinit)()
         );
     };
-
 }}
 
 #include "celix/dm/Component_Impl.h"

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/include/celix/dm/Component_Impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/Component_Impl.h 
b/dependency_manager_cxx/include/celix/dm/Component_Impl.h
index 8f42131..eadfa15 100644
--- a/dependency_manager_cxx/include/celix/dm/Component_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/Component_Impl.h
@@ -30,13 +30,8 @@ template<class T>
 Component<T>::Component(const bundle_context_pt context, std::string name) : 
BaseComponent(context, name) { }
 
 template<class T>
-Component<T>::~Component() { }
-
-template<class T>
-template<class I>
-Component<T>& Component<T>::addInterface(const std::string version) {
-    Properties props;
-    return addInterface<I>(version, props);
+Component<T>::~Component() {
+    this->dependencies.clear();
 }
 
 template<class T>
@@ -66,11 +61,6 @@ Component<T>& Component<T>::addInterface(const std::string 
serviceName, const st
 };
 
 template<class T>
-Component<T>& Component<T>::addCInterface(const void* svc, const std::string 
serviceName, const std::string version) {
-    return this->addCInterface(svc, serviceName, version, Properties());
-};
-
-template<class T>
 Component<T>& Component<T>::addCInterface(const void* svc, const std::string 
serviceName, const std::string version, const Properties properties) {
     properties_pt cProperties = properties_create();
     properties_set(cProperties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, 
CELIX_FRAMEWORK_SERVICE_C_LANGUAGE);
@@ -86,48 +76,80 @@ Component<T>& Component<T>::addCInterface(const void* svc, 
const std::string ser
 
 template<class T>
 template<class I>
-Component<T>& Component<T>::add(ServiceDependency<T,I>& dep) {
-    component_addServiceDependency(cComponent(), dep.cServiceDependency());
-    dep.setComponentInstance(&getInstance());
-    return *this;
+ServiceDependency<T,I>& Component<T>::createServiceDependency() {
+#ifdef __EXCEPTIONS
+    auto dep = std::shared_ptr<ServiceDependency<T,I>> {new 
ServiceDependency<T,I>()};
+#else
+    auto dep = std::shared_ptr<ServiceDependency<T,I>> {new(std::nothrow) 
ServiceDependency<T,I>()};
+    //TODO handle nullptr, how?
+#endif
+    this->dependencies.push_back(dep);
+    component_addServiceDependency(cComponent(), dep->cServiceDependency());
+    dep->setComponentInstance(&getInstance());
+    return *dep;
 }
 
 template<class T>
 template<class I>
 Component<T>& Component<T>::remove(ServiceDependency<T,I>& dep) {
     component_removeServiceDependency(cComponent(), dep.cServiceDependency());
+    this->dependencies.remove(dep);
     return *this;
 }
 
 template<class T>
 template<typename I>
-Component<T>& Component<T>::add(CServiceDependency<T,I>& dep) {
-    component_addServiceDependency(cComponent(), dep.cServiceDependency());
-    dep.setComponentInstance(&getInstance());
-    return *this;
+CServiceDependency<T,I>& Component<T>::createCServiceDependency() {
+#ifdef __EXCEPTIONS
+    auto dep = std::shared_ptr<CServiceDependency<T,I>> {new 
CServiceDependency<T,I>()};
+#else
+    auto dep = std::shared_ptr<CServiceDependency<T,I>> {new(std::nothrow) 
CServiceDependency<T,I>()};
+    //TODO handle nullptr, how?
+#endif
+    this->dependencies.push_back(dep);
+    component_addServiceDependency(cComponent(), dep->cServiceDependency());
+    dep->setComponentInstance(&getInstance());
+    return *dep;
 }
 
 template<class T>
 template<typename I>
 Component<T>& Component<T>::remove(CServiceDependency<T,I>& dep) {
     component_removeServiceDependency(cComponent(), dep.cServiceDependency());
+    this->dependencies.remove(dep);
     return *this;
 }
 
 template<class T>
+Component<T>* Component<T>::create(bundle_context_pt context, std::string 
name) {
+    std::string n = name.empty() ? typeName<T>() : name;
+#ifdef __EXCEPTIONS
+    Component<T>* cmp = new Component<T>(context, n);
+#else
+    Component<T>* cmp = new(std::nothrow) Component<T>(context, n);
+#endif
+    return cmp;
+}
+
+template<class T>
+bool Component<T>::isValid() const {
+    return this->bundleContext() != nullptr;
+}
+
+template<class T>
 T& Component<T>::getInstance() {
     if (this->refInstance.size() == 1) {
         return refInstance.front();
-    } else {  //TODO check if we can use move??
+    } else {
         if (this->instance.get() == nullptr) {
 #ifdef __EXCEPTIONS
             this->instance = std::shared_ptr<T> {new T()};
 #else
             this->instance = std::shared_ptr<T> {new(std::nothrow) T()};
+
 #endif
-            //TODO check needed, how to handle nullptr ?
         }
-        return *this->instance.get();
+        return *this->instance;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/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 c453457..569cc2e 100644
--- a/dependency_manager_cxx/include/celix/dm/DependencyManager.h
+++ b/dependency_manager_cxx/include/celix/dm/DependencyManager.h
@@ -35,11 +35,10 @@ extern "C" {
 namespace celix { namespace dm {
 
     class DependencyManager {
+    private:
         bundle_context_pt context = {nullptr};
-        std::list<std::shared_ptr<BaseComponent>> components {};
-        std::list<BaseComponent*> addedComponents {};
+        std::list<std::unique_ptr<BaseComponent>> components {};
         dm_dependency_manager_pt cDepMan {nullptr};
-        std::list<std::shared_ptr<BaseServiceDependency>> dependencies {};
     public:
         DependencyManager(bundle_context_pt context);
         virtual ~DependencyManager();
@@ -48,71 +47,23 @@ namespace celix { namespace dm {
         const dm_dependency_manager_pt cDependencyManager() const;
 
         /**
-         * Create a new DM Component for a component of type T
+         * Creates and adds a new DM Component for a component of type T and 
instance inst
+         * If inst if nullptr lazy initializion is used.
          *
          * @return Returns a reference to the DM Component
          */
         template<class T>
-        Component<T>& createComponent() {
-            std::shared_ptr<Component<T>> cmp {new Component<T>(this->context, 
typeName<T>())};
-            this->components.push_back(cmp);
+        Component<T>& createComponent(std::shared_ptr<T> inst) {
+            Component<T>* cmp = Component<T>::create(this->context);
+            //TODO handle nullptr component, how?
+            if (inst.get() != nullptr) {
+                cmp->setInstance(inst);
+            }
+            this->components.push_back(std::unique_ptr<BaseComponent> {cmp});
             return *cmp;
         }
 
         /**
-         * Adds a DM Component to the Dependency Manager
-         */
-        template<class T>
-        void add(Component<T>& cmp) {
-            addedComponents.push_back(&cmp);
-        }
-
-        /**
-         * Removes a DM Component to the Dependency Manager
-         */
-        template<class T>
-        void remove(Component<T>& cmp) {
-            addedComponents.remove(&cmp);
-        }
-
-        /**
-         * Create a new C++ service dependency for a component of type T with 
an interface of type I
-         *
-         * @return Returns a reference to the service dependency
-         */
-        template<class T, class I>
-        ServiceDependency<T,I>& createServiceDependency() {
-#ifdef __EXCEPTIONS
-            auto dep = std::shared_ptr<ServiceDependency<T,I>> {new 
ServiceDependency<T,I>()};
-#else
-            auto dep = std::shared_ptr<ServiceDependency<T,I>> 
{new(std::nothrow) ServiceDependency<T,I>()};
-            //TODO handle nullptr, how? Note that in modern operating system a 
null return for a alloc is virtually impossible.
-#endif
-
-            dependencies.push_back(dep);
-            return *dep;
-        };
-
-
-        /**
-         * Create a new C service dependency for a component of type T.
-         *
-         * @return Returns a reference to the service dependency
-         */
-        template<class T, typename I>
-        CServiceDependency<T,I>& createCServiceDependency() {
-#ifdef __EXCEPTIONS
-            auto dep = std::shared_ptr<CServiceDependency<T,I>> {new 
CServiceDependency<T,I>()};
-#else
-            auto dep = std::shared_ptr<CServiceDependency<T,I>> 
{new(std::nothrow) CServiceDependency<T,I>()};
-            //TODO handle nullptr, how?
-#endif
-
-            dependencies.push_back(dep);
-            return *dep;
-        }
-
-        /**
          * Starts the Dependency Manager
          */
         void start();

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/include/celix/dm/DmActivator.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/DmActivator.h 
b/dependency_manager_cxx/include/celix/dm/DmActivator.h
index 503b824..69c86eb 100644
--- a/dependency_manager_cxx/include/celix/dm/DmActivator.h
+++ b/dependency_manager_cxx/include/celix/dm/DmActivator.h
@@ -46,40 +46,14 @@ namespace celix { namespace dm {
         virtual void deinit(DependencyManager& manager) {};
 
         /**
-         * Create a new DM Component for a component of type T
+         * Creates and adds a new DM Component for a component of type T.
+         * If inst is provided the DM Component will manage provided instance.
+         * If inst is not provided (nullptr) the DM Component will lazy 
contsruct a new instance if needed.
          *
          * @return Returns a reference to the DM Component
          */
         template< class T>
-        Component<T>& createComponent() { return manager.createComponent<T>(); 
}
-
-        /**
-         * Adds a DM Component to the Dependency Manager
-         */
-        template<class T>
-        void add(Component<T>& cmp) { manager.add(cmp); }
-
-        /**
-        * Removes a DM Component to the Dependency Manager
-        */
-        template<class T>
-        void remove(Component<T>& cmp) { manager.remove(cmp); }
-
-        /**
-         * Create a new C++ service dependency for a component of type T with 
an interface of type I
-         *
-         * @return Returns a reference to the service dependency
-         */
-        template<class T, class I>
-        ServiceDependency<T,I>& createServiceDependency() { return 
manager.createServiceDependency<T,I>(); }
-
-        /**
-         * Create a new C service dependency for a component of type T.
-         *
-         * @return Returns a reference to the service dependency
-         */
-        template<class T, typename I>
-        CServiceDependency<T,I>& createCServiceDependency() { return 
manager.createCServiceDependency<T,I>(); }
+        Component<T>& createComponent(std::shared_ptr<T> inst = {nullptr}) { 
return manager.createComponent<T>(inst); }
 
         /**
          * The static method to create a new DM activator.

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/ServiceDependency.h 
b/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
index f0d715a..17e02fe 100644
--- a/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
+++ b/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
@@ -106,7 +106,7 @@ namespace celix { namespace dm {
          * @param filter The (additional) filter to use (e.g. 
"(location=front)")
          * @return the C service dependency reference for chaining (fluent API)
          */
-        CServiceDependency<T,I>& setCService(const std::string serviceName, 
const std::string serviceVersionRange, const std::string filter);
+        CServiceDependency<T,I>& setCService(const std::string serviceName, 
const std::string serviceVersionRange = {}, const std::string filter = {});
 
         /**
          * Specify if the service dependency is required. Default is false

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/readme.md
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/readme.md b/dependency_manager_cxx/readme.md
index 4bb429c..14eb333 100644
--- a/dependency_manager_cxx/readme.md
+++ b/dependency_manager_cxx/readme.md
@@ -7,12 +7,10 @@ The Apache Celix C++ Dependency Manager is inspired by the 
[Apache Felix Depende
 
 The C++ Dependency Manager uses fluent interface to make specifying DM 
components and service dependencies very concise and relies on features 
introduced in C++11.
 
-
-
 ## C++ and C Dependency Manager
 
 The C++ Dependency Manager is build on top of the C Dependency Manager.
-To get an good overview of the C++ Dependency Manager alse read the 
[Dependency Manager documentation](../dependency_manager/README.md) 
+To get a good overview of the C++ Dependency Manager please read the 
[Dependency Manager documentation](../dependency_manager/README.md)
 
 ## DM Parts
 
@@ -24,22 +22,21 @@ The `DmActivator` class should be inherited by a bundle 
specific Activator.
 
 - The static `DmActivator::create` method needs to be implemented and should 
return a bundle specific subclass instance of the DmActivator.
 - The `DmActivator::init` method should be overridden and can be used to 
specify which components to use in the bundle.
-- The `DmActivator::deinit` method can be ocerridden if some cleanup is needed 
when a bundle is stopped.
+- The `DmActivator::deinit` method can be overridden if some cleanup is needed 
when a bundle is stopped.
 
 ### Dependency Manager
 
-The `DependencyManager` act as an entry point to add or remove (DM) 
Components. 
+The `DependencyManager` act as an entry point to create (DM) Components.
 
 ### Component
 
-
-
 The (DM) `Component` manages the life cycle of a component (of the template 
type T). For example, when all required service dependencies are available the 
`Component` will call the `start` specified callback function of the component.
 
 The `Component::setInstance` can be used to set the component instance to 
used. If no instance is set the (DM) `Component` will (lazy) create a component 
instance using the default constructor.
-The `component::addInterface` can be used to specify one additional C service 
provided by the component.
-The `component::addCInterface` can be used to specify one additional C++ 
service provided by the component. 
-The `component::add` can be used to specify one additional service dependency.
+The `Component::addInterface` can be used to specify one additional C service 
provided by the component.
+The `Component::addCInterface` can be used to specify one additional C++ 
service provided by the component.
+The template method `Component::createServiceDependency` can be used to 
specify one additional typed C++ service dependency.
+The template method `Component::createCServiceDependency` can be used to 
specify one additional typed C service dependency.
 
 ### ServiceDependency and CServiceDependency
 
@@ -49,7 +46,7 @@ The (DM) `CServiceDependency` can be used to specify C 
service dependencies for
 When these dependencies are set to required the `Component` will ensure that 
components will only be started when all required dependencies are available 
and stop the component if any of the required dependencies are removed.
 This feature should prevent a lot of boiler plating code compared to using a 
service tracker or services references directly. 
 
-A service dependency update strategy can also be specified. Default this 
strategy is set to `DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND` this strategy will 
stop and start (suspend) a component when any of the specified service 
dependencies change (are removed, added or modified). 
+A service dependency update strategy can also be specified (suspend or 
locking. Default this strategy is set to `DependencyUpdateStrategy::suspend` 
this strategy will stop and start (suspend) a component when any of the 
specified service dependencies changes (are removed, added or modified).
 When correctly used this strategy removes the need for locking services during 
updates/invocation. See the dependency manager_cxx example for more details.
 
 The `(C)ServiceDependency::setCallbacks` function can be used to specify the 
function callback used when services are added, set, removed or modified. 

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/dependency_manager_cxx/src/DependencyManager.cc
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/src/DependencyManager.cc 
b/dependency_manager_cxx/src/DependencyManager.cc
index f3a2109..39f1995 100644
--- a/dependency_manager_cxx/src/DependencyManager.cc
+++ b/dependency_manager_cxx/src/DependencyManager.cc
@@ -41,7 +41,7 @@ const dm_dependency_manager_pt 
DependencyManager::cDependencyManager() const {
 }
 
 void DependencyManager::start() {
-    for(BaseComponent* cmp : addedComponents)  {
+    for(std::unique_ptr<BaseComponent>& cmp : components)  {
         dependencyManager_add(cDepMan, cmp->cComponent());
     }
 }
@@ -49,8 +49,6 @@ void DependencyManager::start() {
 void DependencyManager::stop() {
     dependencyManager_removeAllComponents(cDepMan);
     components.clear();
-    addedComponents.clear();
-    dependencies.clear();
 }
 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/src/Phase1Activator.cc 
b/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
index c3d7754..f322195 100644
--- a/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
+++ b/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
@@ -46,12 +46,10 @@ void Phase1Activator::init(DependencyManager& manager) {
         return cmp->infoCmd(line, out, err);
     };
 
-    add(createComponent<Phase1Cmp>()
-        .setInstance(cmp) //using a pointer a instance. Also support is lazy 
initialization (default constructor needed) or a rvalue reference (move)
+    createComponent(cmp)  //using a pointer a instance. Also supported is lazy 
initialization (default constructor needed) or a rvalue reference (move)
         .addInterface<IPhase1>(IPHASE1_VERSION)
         .addCInterface(&cmd, OSGI_SHELL_COMMAND_SERVICE_NAME, "", cmdProps)
-        .setCallbacks(&Phase1Cmp::init, &Phase1Cmp::start, &Phase1Cmp::stop, 
&Phase1Cmp::deinit)
-    );
+        .setCallbacks(&Phase1Cmp::init, &Phase1Cmp::start, &Phase1Cmp::stop, 
&Phase1Cmp::deinit);
 }
 
 void Phase1Activator::deinit(DependencyManager& manager) {

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc 
b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
index c486fe9..c8b4659 100644
--- a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
+++ b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
@@ -34,19 +34,18 @@ void Phase2Activator::init(DependencyManager& manager) {
     Properties props {};
     props["name"] = "phase2a";
 
-    add(createComponent<Phase2Cmp>()
-        .setInstance(Phase2Cmp()) 
-        .addInterface<IPhase2>(IPHASE2_VERSION, props)
-        .add(createServiceDependency<Phase2Cmp,IPhase1>()
+    Component<Phase2Cmp>& cmp = createComponent<Phase2Cmp>()
+            .setInstance(Phase2Cmp())
+            .addInterface<IPhase2>(IPHASE2_VERSION, props);
+
+    cmp.createServiceDependency<IPhase1>()
             .setRequired(true)
-            .setCallbacks(&Phase2Cmp::setPhase1)
-        )
-        .add(createCServiceDependency<Phase2Cmp, log_service_t>()
+            .setCallbacks(&Phase2Cmp::setPhase1);
+
+    cmp.createCServiceDependency<log_service_t>()
             .setRequired(false)
             .setCService(OSGI_LOGSERVICE_NAME, {}, {})
-            .setCallbacks(&Phase2Cmp::setLogService)
-        )
-    );
+            .setCallbacks(&Phase2Cmp::setLogService);
 }
 
 void Phase2Activator::deinit(DependencyManager& manager) {

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc 
b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
index 1ce7c78..f972d9d 100644
--- a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
+++ b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
@@ -33,18 +33,17 @@ void Phase2Activator::init(DependencyManager& manager) {
     Properties props {};
     props["name"] = "phase2b";
 
-    add(createComponent<Phase2Cmp>()
-        .addInterface<IPhase2>(IPHASE2_VERSION, props)
-        .add(createServiceDependency<Phase2Cmp,IPhase1>()
+    Component<Phase2Cmp>& cmp = createComponent<Phase2Cmp>()
+        .addInterface<IPhase2>(IPHASE2_VERSION, props);
+
+    cmp.createServiceDependency<IPhase1>()
             .setRequired(true)
-            .setCallbacks(&Phase2Cmp::setPhase1)
-        )
-        .add(createCServiceDependency<Phase2Cmp, log_service_t>()
+            .setCallbacks(&Phase2Cmp::setPhase1);
+
+    cmp.createCServiceDependency<log_service_t>()
             .setRequired(false)
-            .setCService(OSGI_LOGSERVICE_NAME, {}, {})
-            .setCallbacks(&Phase2Cmp::setLogService)
-        )
-    );
+            .setCService(OSGI_LOGSERVICE_NAME)
+            .setCallbacks(&Phase2Cmp::setLogService);
 }
 
 void Phase2Activator::deinit(DependencyManager& manager) {

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase3/src/Phase3Activator.cc 
b/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
index 76a6eaa..4688fb0 100644
--- a/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
+++ b/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
@@ -29,17 +29,15 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
 }
 
 void Phase3Activator::init(DependencyManager& manager) {
-    add(createComponent<Phase3Cmp>()
-        //NOTE no setInstance -> lazy initialization using the default 
constructor
-        .setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, nullptr)
-        .add(createServiceDependency<Phase3Cmp,IPhase2>()
+    Component<Phase3Cmp>& cmp = createComponent<Phase3Cmp>() //NOTE no 
setInstance -> lazy initialization using the default constructor
+            .setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, 
nullptr);
+
+    cmp.createServiceDependency<IPhase2>()
             .setRequired(true)
-            .setCallbacks(&Phase3Cmp::addPhase2, &Phase3Cmp::removePhase2)
-        )
-        .add(createServiceDependency<Phase3Cmp,IPhase2>()
+            .setCallbacks(&Phase3Cmp::addPhase2, &Phase3Cmp::removePhase2);
+
+    cmp.createServiceDependency<IPhase2>()
              .setRequired(false)
              .setFilter("(&(name=phase2a)(non-existing=*))")
-             .setCallbacks(&Phase3Cmp::setPhase2a)
-        )
-    );
+             .setCallbacks(&Phase3Cmp::setPhase2a);
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/3a8f4343/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
----------------------------------------------------------------------
diff --git 
a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc 
b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
index 546807b..9819824 100644
--- a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
@@ -29,12 +29,11 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
 }
 
 void Phase3LockingActivator::init(DependencyManager& manager) {
-    add(createComponent<Phase3LockingCmp>()
+    Component<Phase3LockingCmp>& cmp = createComponent<Phase3LockingCmp>()
         //NOTE no setInstance -> lazy initialization using the default 
constructor
-        .setCallbacks(nullptr, &Phase3LockingCmp::start, 
&Phase3LockingCmp::stop, nullptr)
-        .add(createServiceDependency<Phase3LockingCmp,IPhase2>()
+        .setCallbacks(nullptr, &Phase3LockingCmp::start, 
&Phase3LockingCmp::stop, nullptr);
+
+    cmp.createServiceDependency<IPhase2>()
             .setStrategy(DependencyUpdateStrategy::locking)
-            .setCallbacks(&Phase3LockingCmp::addPhase2, 
&Phase3LockingCmp::removePhase2)
-        )
-    );
+            .setCallbacks(&Phase3LockingCmp::addPhase2, 
&Phase3LockingCmp::removePhase2);
 }
\ No newline at end of file

Reply via email to