celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject celix git commit: CELIX-426: Refactors C++ Bundle Activator concept
Date Fri, 18 May 2018 09:02:29 GMT
Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-426-cxx-api 4f4389256 -> 51f62041c


CELIX-426: Refactors C++ Bundle Activator concept


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

Branch: refs/heads/feature/CELIX-426-cxx-api
Commit: 51f62041cfac38f79544df6fc1552e26e263a9f6
Parents: 4f43892
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Fri May 18 11:01:46 2018 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Fri May 18 11:01:46 2018 +0200

----------------------------------------------------------------------
 .../bar/BarActivator.cc                         |  11 +-
 .../bar/BarActivator.h                          |   8 +-
 .../baz/BazActivator.cc                         |  11 +-
 .../baz/BazActivator.h                          |   8 +-
 .../foo/FooActivator.cc                         |  11 +-
 .../foo/FooActivator.h                          |  10 +-
 .../bundle_example_cxx/src/BundleActivator.cc   |  21 ++--
 .../phase1/src/Phase1Activator.cc               |  10 +-
 .../dm_example_cxx/phase1/src/Phase1Activator.h |   8 +-
 .../dm_example_cxx/phase2/src/Phase2Activator.h |   8 +-
 .../phase2/src/Phase2aActivator.cc              |  10 +-
 .../phase2/src/Phase2bActivator.cc              |  10 +-
 .../phase3/src/Phase3Activator.cc               |  14 ++-
 .../dm_example_cxx/phase3/src/Phase3Activator.h |   4 +-
 .../phase3/src/Phase3BaseActivator.cc           |  10 +-
 .../phase3/src/Phase3BaseActivator.h            |  11 +-
 .../src/Phase3LockingActivator.cc               |  13 +-
 .../phase3_locking/src/Phase3LockingActivator.h |   9 +-
 .../src/ConsumerBundleActivator.cc              |  20 ++--
 .../src/ProviderBundleActivator.cc              |  14 +--
 framework/include/celix/BundleActivator.h       | 120 +++++++++++--------
 framework/include/celix/IBundleActivator.h      |  34 ------
 .../include/celix/impl/BundleContextImpl.h      |   7 +-
 23 files changed, 191 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.cc b/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.cc
index 1dc5a7e..cef088a 100644
--- a/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.cc
+++ b/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.cc
@@ -22,11 +22,9 @@
 
 #include "celix/BundleActivator.h"
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new BarActivator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(BarActivator)
 
-BarActivator::BarActivator(celix::BundleContext& ctx) {
+celix_status_t BarActivator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
     auto bar = std::unique_ptr<Bar>{new Bar{}};
 
@@ -46,4 +44,7 @@ BarActivator::BarActivator(celix::BundleContext& ctx) {
         .addInterface<IAnotherExample>(IAnotherExample::VERSION, props)
         .addCInterface(&this->cExample, EXAMPLE_NAME, EXAMPLE_VERSION, cProps)
         .setCallbacks(&Bar::init, &Bar::start, &Bar::stop, &Bar::deinit);
-}
\ No newline at end of file
+    return CELIX_SUCCESS;
+}
+
+celix_status_t BarActivator::stop(celix::BundleContext&) {return CELIX_SUCCESS;}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.h b/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.h
index 8642c4f..8ec236f 100644
--- a/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.h
+++ b/examples/celix-examples/best_practice_example_cxx/bar/BarActivator.h
@@ -20,13 +20,13 @@
 #ifndef BAR_ACTIVATOR_H
 #define BAR_ACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
+#include "celix/BundleContext.h"
 #include "example.h"
 
-class BarActivator : public celix::IBundleActivator {
+class BarActivator {
 public:
-    BarActivator(celix::BundleContext &ctx);
-    virtual ~BarActivator() = default;
+    celix_status_t start(celix::BundleContext &ctx);
+    celix_status_t stop(celix::BundleContext &ctx);
 private:
     example_t cExample {nullptr, nullptr};
 };

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.cc b/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.cc
index a3d3a4f..1b48634 100644
--- a/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.cc
+++ b/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.cc
@@ -22,11 +22,9 @@
 
 #include "celix/BundleActivator.h"
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new BazActivator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(BazActivator)
 
-BazActivator::BazActivator(celix::BundleContext& ctx) {
+celix_status_t BazActivator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
     Component<Baz>& cmp = mng.createComponent<Baz>()
         .setCallbacks(nullptr, &Baz::start, &Baz::stop, nullptr);
@@ -42,4 +40,7 @@ BazActivator::BazActivator(celix::BundleContext& ctx) {
             .setStrategy(DependencyUpdateStrategy::locking)
             .setVersionRange(EXAMPLE_CONSUMER_RANGE)
             .setCallbacks(&Baz::addExample, &Baz::removeExample);
-}
\ No newline at end of file
+    return CELIX_SUCCESS;
+}
+
+celix_status_t BazActivator::stop(celix::BundleContext &){return CELIX_SUCCESS;}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.h b/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.h
index e1a7c38..1832ee1 100644
--- a/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.h
+++ b/examples/celix-examples/best_practice_example_cxx/baz/BazActivator.h
@@ -20,12 +20,12 @@
 #ifndef BAZ_ACTIVATOR_H
 #define BAZ_ACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
+#include "celix/BundleContext.h"
 
-class BazActivator : public celix::IBundleActivator {
+class BazActivator {
 public:
-    BazActivator(celix::BundleContext &ctx);
-    virtual ~BazActivator() = default;
+    celix_status_t start(celix::BundleContext &ctx);
+    celix_status_t stop(celix::BundleContext &ctx);
 };
 
 #endif //BAZ_ACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.cc b/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.cc
index 719da16..af82700 100644
--- a/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.cc
+++ b/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.cc
@@ -22,11 +22,9 @@
 
 #include "celix/BundleActivator.h"
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new FooActivator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(FooActivator)
 
-FooActivator::FooActivator(celix::BundleContext& ctx) {
+celix_status_t FooActivator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
     Component<Foo>& cmp = mng.createComponent<Foo>()
         .setCallbacks(nullptr, &Foo::start, &Foo::stop, nullptr);
@@ -40,4 +38,7 @@ FooActivator::FooActivator(celix::BundleContext& ctx) {
             .setRequired(false)
             .setVersionRange(EXAMPLE_CONSUMER_RANGE)
             .setCallbacks(&Foo::setExample);
-}
\ No newline at end of file
+    return CELIX_SUCCESS;
+}
+
+celix_status_t FooActivator::stop(celix::BundleContext &) {return CELIX_SUCCESS;}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.h b/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.h
index a79d365..0e1bb04 100644
--- a/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.h
+++ b/examples/celix-examples/best_practice_example_cxx/foo/FooActivator.h
@@ -17,16 +17,16 @@
  * under the License.
  */
 
+#include "celix/BundleContext.h"
+
 #ifndef FOO_ACTIVATOR_H
 #define FOO_ACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
-
-class FooActivator : public celix::IBundleActivator {
+class FooActivator {
 private:
 public:
-    FooActivator(celix::BundleContext &ctx);
-    virtual ~FooActivator() = default;
+    celix_status_t start(celix::BundleContext &ctx);
+    celix_status_t stop(celix::BundleContext &ctx);
 };
 
 #endif //FOO_ACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc b/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
index 367d1dc..a472b06 100644
--- a/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
+++ b/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
@@ -18,25 +18,22 @@
  */
 
 #include <iostream>
-
 #include "celix/BundleActivator.h"
 
 namespace {
-    class BundleActivator : public celix::IBundleActivator {
+    class BundleActivator  {
     public:
-        BundleActivator(celix::BundleContext &) {
-            //std::cout << "Hello world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
-            std::cout << "Hello world from C++ bundle " << std::endl;
+        celix_status_t start(celix::BundleContext &ctx) {
+            std::cout << "Hello world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
+            return CELIX_SUCCESS;
         }
-        virtual ~BundleActivator() {
-            //std::cout << "Goodbye world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
+
+        celix_status_t stop(celix::BundleContext &ctx) {
+            std::cout << "Goodbye world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
+            return CELIX_SUCCESS;
         }
-    protected:
-        //celix::BundleContext &ctx;
     };
 }
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new BundleActivator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(BundleActivator)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.cc b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.cc
index 1f11349..aa33f22 100644
--- a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.cc
@@ -36,11 +36,9 @@ struct InvalidCServ {
     virtual void baz(double __attribute__((unused)) arg) {} //not a valid pod
 };
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new Phase1Activator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(Phase1Activator)
 
-Phase1Activator::Phase1Activator(celix::BundleContext& ctx) {
+celix_status_t Phase1Activator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
     auto cmp = std::unique_ptr<Phase1Cmp>(new Phase1Cmp());
 
@@ -67,8 +65,10 @@ Phase1Activator::Phase1Activator(celix::BundleContext& ctx) {
                     //.addCInterface(tst.get(), "TEST_SRV") -> Compile error (static assert),
because InvalidCServ is not a pod
                     .addInterface<srv::info::IName>(INAME_VERSION)
                     .setCallbacks(&Phase1Cmp::init, &Phase1Cmp::start, &Phase1Cmp::stop,
&Phase1Cmp::deinit);
+    return CELIX_SUCCESS;
 }
 
-Phase1Activator::~Phase1Activator() {
+celix_status_t Phase1Activator::stop(celix::BundleContext &) {
     //nothing to do
+    return CELIX_SUCCESS;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.h b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.h
index 240c3ec..0d68ec9 100644
--- a/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.h
+++ b/examples/celix-examples/dm_example_cxx/phase1/src/Phase1Activator.h
@@ -20,16 +20,16 @@
 #ifndef CELIX_PHASE1ACTIVATOR_H
 #define CELIX_PHASE1ACTIVATOR_H
 
-#include <celix/IBundleActivator.h>
+#include <celix/BundleActivator.h>
 #include "celix/dm/DmActivator.h"
 #include "command.h"
 
 using namespace celix::dm;
 
-class Phase1Activator : public celix::IBundleActivator {
+class Phase1Activator {
 public:
-    Phase1Activator(celix::BundleContext& _ctx);
-    virtual ~Phase1Activator();
+    celix_status_t start(celix::BundleContext& _ctx);
+    celix_status_t stop(celix::BundleContext& _ctx);
 private:
     command_service_t cmd {nullptr, nullptr};
 };

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h
index 38a5cd7..eec1ab3 100644
--- a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h
+++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2Activator.h
@@ -20,14 +20,14 @@
 #ifndef CELIX_PHASE2AACTIVATOR_H
 #define CELIX_PHASE2AACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
+#include "celix/BundleContext.h"
 
 using namespace celix::dm;
 
-class Phase2Activator : public celix::IBundleActivator {
+class Phase2Activator  {
 public:
-    Phase2Activator(celix::BundleContext& ctx);
-    virtual ~Phase2Activator();
+    celix_status_t start(celix::BundleContext &ctx);
+    celix_status_t stop(celix::BundleContext &ctx);
 };
 
 #endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
index 80d9bb4..edf6568 100644
--- a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2aActivator.cc
@@ -25,11 +25,9 @@
 #include "celix/BundleActivator.h"
 
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new Phase2Activator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(Phase2Activator)
 
-Phase2Activator::Phase2Activator(celix::BundleContext& ctx) {
+celix_status_t Phase2Activator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
 
     Properties props {};
@@ -50,8 +48,10 @@ Phase2Activator::Phase2Activator(celix::BundleContext& ctx) {
     cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
             .setRequired(false)
             .setCallbacks(&Phase2Cmp::setLogService);
+    return CELIX_SUCCESS;
 }
 
-Phase2Activator::~Phase2Activator() {
+celix_status_t Phase2Activator::stop(celix::BundleContext &) {
     //nothing
+    return CELIX_SUCCESS;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
index 49298c3..a7538d4 100644
--- a/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase2/src/Phase2bActivator.cc
@@ -23,11 +23,9 @@
 
 #include "celix/BundleActivator.h"
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new Phase2Activator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(Phase2Activator)
 
-Phase2Activator::Phase2Activator(celix::BundleContext& ctx) {
+celix_status_t Phase2Activator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
 
     Properties props {};
@@ -43,8 +41,10 @@ Phase2Activator::Phase2Activator(celix::BundleContext& ctx) {
     cmp.createCServiceDependency<log_service_t>(OSGI_LOGSERVICE_NAME)
             .setRequired(false)
             .setCallbacks(&Phase2Cmp::setLogService);
+    return CELIX_SUCCESS;
 }
 
-Phase2Activator::~Phase2Activator() {
+celix_status_t Phase2Activator::stop(celix::BundleContext&) {
     //nothing
+    return CELIX_SUCCESS;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc
index 4cf88cc..56d33a1 100644
--- a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.cc
@@ -23,16 +23,18 @@
 
 #include "celix/BundleActivator.h"
 
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(Phase3Activator)
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new Phase3Activator{ctx};
-}
 
-Phase3Activator::Phase3Activator(celix::BundleContext& ctx) : Phase3BaseActivator{ctx.getDependencyManager()}
{
-    cmp.createServiceDependency<IPhase2>()
+celix_status_t Phase3Activator::start(celix::BundleContext& ctx) {
+    this->Phase3BaseActivator::start(ctx);
+    this->cmp->createServiceDependency<IPhase2>()
              .setRequired(false)
              .setFilter("(&(name=phase2a)(non-existing=*))")
              .setCallbacks(&Phase3Cmp::setPhase2a);
+    return CELIX_SUCCESS;
 }
 
-Phase3Activator::~Phase3Activator(){}
+celix_status_t Phase3Activator::stop(celix::BundleContext &ctx) {
+    return this->Phase3BaseActivator::stop(ctx);
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h
index e4f91c8..731a3ad 100644
--- a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h
+++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3Activator.h
@@ -24,8 +24,8 @@
 
 class Phase3Activator : public Phase3BaseActivator {
 public:
-    Phase3Activator(celix::BundleContext& ctx);
-    ~Phase3Activator();
+    virtual celix_status_t start(celix::BundleContext& ctx);
+    virtual celix_status_t stop(celix::BundleContext& ctx);
 };
 
 #endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc
index d7d16c5..b7b963a 100644
--- a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.cc
@@ -20,12 +20,18 @@
 #include "Phase3Cmp.h"
 #include "Phase3BaseActivator.h"
 
-Phase3BaseActivator::Phase3BaseActivator(celix::dm::DependencyManager& mng) : cmp(mng.createComponent<Phase3Cmp>())
{
+celix_status_t Phase3BaseActivator::start(celix::BundleContext& ctx) {
+    auto& cmp = ctx.getDependencyManager().createComponent<Phase3Cmp>();
     cmp.setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, nullptr);
 
     cmp.createServiceDependency<IPhase2>()
             .setRequired(true)
             .setCallbacks(&Phase3Cmp::addPhase2, &Phase3Cmp::removePhase2);
+    this->cmp = &cmp;
+    return CELIX_SUCCESS;
 }
 
-Phase3BaseActivator::~Phase3BaseActivator(){};
+celix_status_t Phase3BaseActivator::stop(celix::BundleContext &){
+    this->cmp = nullptr;
+    return CELIX_SUCCESS;
+};

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
index 27deee2..0fd6cbe 100644
--- a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
+++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
@@ -20,15 +20,16 @@
 #ifndef CELIX_PHASE3BASEACTIVATOR_H
 #define CELIX_PHASE3BASEACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
+#include "celix/BundleContext.h"
 #include "celix/dm/DependencyManager.h"
 
-class Phase3BaseActivator : public celix::IBundleActivator {
+class Phase3BaseActivator  {
 public:
-    Phase3BaseActivator(celix::dm::DependencyManager& mng);
-    virtual ~Phase3BaseActivator();
+    virtual ~Phase3BaseActivator(){}
+    virtual celix_status_t start(celix::BundleContext& ctx);
+    virtual celix_status_t stop(celix::BundleContext& ctx);
 protected:
-    celix::dm::Component<Phase3Cmp>& cmp;
+    celix::dm::Component<Phase3Cmp> *cmp{nullptr};
 };
 
 #endif //CELIX_PHASE3BASEACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
index eb538b5..da444f0 100644
--- a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
+++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
@@ -25,13 +25,9 @@
 
 #include "celix/BundleActivator.h"
 
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(Phase3LockingActivator)
 
-
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new Phase3LockingActivator{ctx};
-}
-
-Phase3LockingActivator::Phase3LockingActivator(celix::BundleContext& ctx) {
+celix_status_t Phase3LockingActivator::start(celix::BundleContext& ctx) {
     auto &mng = ctx.getDependencyManager();
     auto inst = std::shared_ptr<Phase3LockingCmp> {new Phase3LockingCmp {}};
 
@@ -41,6 +37,9 @@ Phase3LockingActivator::Phase3LockingActivator(celix::BundleContext&
ctx) {
     cmp.createServiceDependency<IPhase2>()
             .setStrategy(DependencyUpdateStrategy::locking)
             .setCallbacks(&Phase3LockingCmp::addPhase2, &Phase3LockingCmp::removePhase2);
+    return CELIX_SUCCESS;
 }
 
-Phase3LockingActivator::~Phase3LockingActivator() {}
\ No newline at end of file
+celix_status_t Phase3LockingActivator::stop(celix::BundleContext &) {
+    return CELIX_SUCCESS;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
index 1ff75ba..d3ade9e 100644
--- a/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
+++ b/examples/celix-examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.h
@@ -17,15 +17,16 @@
  * under the License.
  */
 
+#include "celix/BundleContext.h"
+
 #ifndef CELIX_PHASE3LOCKINGACTIVATOR_H
 #define CELIX_PHASE3LOCKINGACTIVATOR_H
 
-#include "celix/IBundleActivator.h"
 
-class Phase3LockingActivator : public celix::IBundleActivator {
+class Phase3LockingActivator {
 public:
-    Phase3LockingActivator(celix::BundleContext& ctx);
-    virtual ~Phase3LockingActivator();
+    celix_status_t start(celix::BundleContext& ctx);
+    celix_status_t stop(celix::BundleContext& ctx);
 };
 
 #endif //CELIX_PHASE3LOCKINGAACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc b/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
index f12e714..5f74b0c 100644
--- a/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
+++ b/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
@@ -26,22 +26,26 @@
 #include "ICalc.h"
 
 namespace {
-    class BundleActivator : public celix::IBundleActivator {
+    class BundleActivator {
     public:
-        BundleActivator(celix::BundleContext &_ctx) : ctx{_ctx} {
+        celix_status_t  start(celix::BundleContext &ctx) {
             this->trackerId = ctx.trackServices<example::ICalc>(example::ICalc::NAME,
                  [this](example::ICalc *) {  this->trackCount += 1; },
                  [this](example::ICalc *) {  this->trackCount -= 1; });
+
+            this->useThread = std::thread{[&ctx, this] { this->use(ctx); }};
+            return CELIX_SUCCESS;
         }
 
-        virtual ~BundleActivator() {
+        celix_status_t  stop(celix::BundleContext &ctx) {
             ctx.stopTracker(this->trackerId);
             this->running = false;
             this->useThread.join();
+            return CELIX_SUCCESS;
         }
 
     protected:
-        void use() {
+        void use(celix::BundleContext &ctx) {
                 while(running) {
                         int count = 0;
                         double total = 0;
@@ -65,17 +69,13 @@ namespace {
         }
 
     private:
-        celix::BundleContext &ctx;
-
         long trackerId{-1};
-        std::thread useThread{[this] { this->use(); }};
+        std::thread useThread{};
 
         std::atomic<bool> running{true};
         std::atomic<int> trackCount{0};
     };
 }
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new BundleActivator{ctx};
-}
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(BundleActivator)
 

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/examples/celix-examples/services_example_cxx/src/ProviderBundleActivator.cc
----------------------------------------------------------------------
diff --git a/examples/celix-examples/services_example_cxx/src/ProviderBundleActivator.cc b/examples/celix-examples/services_example_cxx/src/ProviderBundleActivator.cc
index c83b4af..36a2b33 100644
--- a/examples/celix-examples/services_example_cxx/src/ProviderBundleActivator.cc
+++ b/examples/celix-examples/services_example_cxx/src/ProviderBundleActivator.cc
@@ -33,9 +33,9 @@ namespace {
         }
     };
 
-    class BundleActivator : public celix::IBundleActivator {
+    class BundleActivator {
     public:
-        BundleActivator(celix::BundleContext &ctx) {
+        celix_status_t  start(celix::BundleContext &ctx) {
             /*
              * This thread registers calc service to a max of 100, then unregistered the
services and repeats.
              */
@@ -66,21 +66,19 @@ namespace {
                 std::for_each(svcIds.begin(), svcIds.end(), [&ctx](long id){ctx.unregisterService(id);});
 
             }};
+            return  CELIX_SUCCESS;
         }
 
-        virtual ~BundleActivator() {
+        celix_status_t  stop(celix::BundleContext &) {
             this->running = false;
             th.join();
+            return CELIX_SUCCESS;
         }
 
     private:
         std::thread th{};
-
         std::atomic<bool> running{true};
     };
 }
 
-celix::IBundleActivator* celix::createBundleActivator(celix::BundleContext &ctx) {
-    return new BundleActivator{ctx};
-}
-
+CELIX_GEN_CXX_BUNDLE_ACTIVATOR(BundleActivator)

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/framework/include/celix/BundleActivator.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/BundleActivator.h b/framework/include/celix/BundleActivator.h
index ccf15fc..d4b98b6 100644
--- a/framework/include/celix/BundleActivator.h
+++ b/framework/include/celix/BundleActivator.h
@@ -17,66 +17,90 @@
  *under the License.
  */
 
-#ifndef CXX_CELIX_BUNDLEACTIVATOR_H
-#define CXX_CELIX_BUNDLEACTIVATOR_H
-
 #include <memory>
 
-#include "celix/IBundleActivator.h"
+#include "celix/BundleContext.h"
 #include "celix/Framework.h"
 
-#include "bundle_activator.h"
+#include "celix/BundleContext.h"
+#include "celix/Framework.h"
 
-/**
- * Note & Warning this is a header implementation of the C bundle activator.
- * As result this header can only be included ones or the activator symbols will
- * be duplicate (linking error).
- */
+#ifndef CXX_CELIX_BUNDLEACTIVATOR_H
+#define CXX_CELIX_BUNDLEACTIVATOR_H
 
 namespace celix {
     /**
-     * The celix::createBundleActivator which needs to be implemented by a bundle.
-    */
-    static celix::IBundleActivator* createBundleActivator(celix::BundleContext &ctx);
+     * The BundleActivatorAdapter adapts the C bundle activator calls to a C++ bundle activator.
+     * The Type parameter (T) is the C++ bundle activator and needs to support:
+     * - A public default constructor.
+     * - A public destructor.
+     * - A public 'celix_status_t start(celix::BundleContext &ctx)` method.
+     * - A public 'celix_status_t start(celix::BundleContext &ctx)` method.
+     */
+    template<typename T>
+    class BundleActivatorAdapter {
+    private:
+        std::unique_ptr<celix::Framework> fw{};
+        std::unique_ptr<celix::BundleContext> ctx{};
+        std::unique_ptr<T> activator{};
+    public:
+        BundleActivatorAdapter(bundle_context_t *c_ctx) {
+            this->fw = std::unique_ptr<celix::Framework>{new celix::impl::FrameworkImpl{c_ctx}};
\
+            this->ctx = std::unique_ptr<celix::BundleContext>{new celix::impl::BundleContextImpl{c_ctx,
*this->fw}}; \
+            this->activator = nullptr;
+        }
 
-    namespace impl {
-        struct ActivatorData {
-            std::unique_ptr<celix::Framework> fw{};
-            std::unique_ptr<celix::BundleContext> ctx{};
-            std::unique_ptr<celix::IBundleActivator> act{};
-        };
-    }
-}
-
-
-extern "C" celix_status_t bundleActivator_create(bundle_context_t *c_ctx, void **userData)
{
-    auto *data = new celix::impl::ActivatorData;
-    data->fw = std::unique_ptr<celix::Framework>{new celix::impl::FrameworkImpl{c_ctx}};
-    data->ctx = std::unique_ptr<celix::BundleContext>{new celix::impl::BundleContextImpl{c_ctx,
*data->fw}};
-    *userData = data;
-    return CELIX_SUCCESS;
-}
+        ~BundleActivatorAdapter() {
+            this->ctx = nullptr;
+            this->fw = nullptr;
+            this->activator = nullptr;
+        }
 
-extern "C" celix_status_t bundleActivator_start(void *userData, bundle_context_t *) {
-    auto *data = static_cast<celix::impl::ActivatorData*>(userData);
-    data->act = std::unique_ptr<celix::IBundleActivator>{celix::createBundleActivator(*data->ctx)};
-    data->ctx->getDependencyManager().start();
-    return CELIX_SUCCESS;
-}
+        celix_status_t start() noexcept  {
+            this->activator = std::unique_ptr<T>{new T};
+            celix_status_t status = this->activator->start(*this->ctx);
+            if (status == CELIX_SUCCESS) {
+                this->ctx->getDependencyManager().start();
+            }
+            return status;
+        }
 
-extern "C" celix_status_t bundleActivator_stop(void *userData, bundle_context_t *) {
-    auto *data = static_cast<celix::impl::ActivatorData*>(userData);
-    data->ctx->getDependencyManager().stop();
-    data->act = nullptr;
-    return CELIX_SUCCESS;
+        celix_status_t stop() noexcept {
+            celix_status_t status = this->activator->stop(*this->ctx);
+            if (status == CELIX_SUCCESS) {
+                this->ctx->getDependencyManager().stop();
+            }
+            this->activator = nullptr; //implicit delete
+            return status;
+        }
+    };
 }
 
-extern "C" celix_status_t bundleActivator_destroy(void *userData, bundle_context_t*) {
-    auto *data = static_cast<celix::impl::ActivatorData*>(userData);
-    data->ctx = nullptr;
-    data->fw = nullptr;
-    delete data;
-    return CELIX_SUCCESS;
-}
+/**
+ * This macro generated the required bundle activator symbols, which uses the celix::BundleActivatorAdapter
to
+ * adapt the C bundle activator calls to the provided C++ bundle activator class.
+ */
+#define CELIX_GEN_CXX_BUNDLE_ACTIVATOR(clazz)                                           
                              \
+extern "C" celix_status_t bundleActivator_create(bundle_context_t *c_ctx, void **userData)
{                           \
+    auto *data = new celix::BundleActivatorAdapter<clazz>{c_ctx};                 
                                    \
+    *userData = data;                                                                   
                              \
+    return CELIX_SUCCESS;                                                               
                              \
+}                                                                                       
                              \
+                                                                                        
                              \
+extern "C" celix_status_t bundleActivator_start(void *userData, bundle_context_t *) {   
                              \
+    auto *data = static_cast<celix::BundleActivatorAdapter<clazz>*>(userData);
                                        \
+    return data->start();                                                            
                                 \
+}                                                                                       
                              \
+                                                                                        
                              \
+extern "C" celix_status_t bundleActivator_stop(void *userData, bundle_context_t *) {    
                              \
+    auto *data = static_cast<celix::BundleActivatorAdapter<clazz>*>(userData);
                                        \
+    return data->stop();                                                             
                                 \
+}                                                                                       
                              \
+                                                                                        
                              \
+extern "C" celix_status_t bundleActivator_destroy(void *userData, bundle_context_t*) {  
                              \
+    auto *data = static_cast<celix::BundleActivatorAdapter<clazz>*>(userData);
                                        \
+    delete data;                                                                        
                              \
+    return CELIX_SUCCESS;                                                               
                              \
+}                                                                                       
                              \
 
 #endif //CXX_CELIX_BUNDLEACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/framework/include/celix/IBundleActivator.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/IBundleActivator.h b/framework/include/celix/IBundleActivator.h
deleted file mode 100644
index 35487b0..0000000
--- a/framework/include/celix/IBundleActivator.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- *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 CXX_CELIX_IBUNDLEACTIVATOR_H
-#define CXX_CELIX_IBUNDLEACTIVATOR_H
-
-#include "celix/BundleContext.h"
-
-namespace celix {
-
-    class IBundleActivator {
-    public:
-        IBundleActivator(){};
-        virtual ~IBundleActivator(){};
-    };
-}
-
-#endif //CXX_CELIX_IBUNDLEACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/51f62041/framework/include/celix/impl/BundleContextImpl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/impl/BundleContextImpl.h b/framework/include/celix/impl/BundleContextImpl.h
index 42af304..0afe73a 100644
--- a/framework/include/celix/impl/BundleContextImpl.h
+++ b/framework/include/celix/impl/BundleContextImpl.h
@@ -171,7 +171,8 @@ namespace celix {
             }
 
             long trackServiceInternal(const std::string &serviceName, std::function<void(void
*svc)> set) noexcept override  {
-                celix_service_tracking_options_t opts = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
+                celix_service_tracking_options_t opts; //TODO why not ok? = CELIX_EMPTY_SERVICE_TRACKING_OPTIONS;
+                std::memset(&opts, 0, sizeof(opts));
 
                 auto c_set = [](void *handle, void *svc) {
                     auto *entry = static_cast<TrackEntry*>(handle);
@@ -336,7 +337,9 @@ long celix::BundleContext::registerServiceWithOptions(const celix::ServiceRegist
         celix_properties_set(c_props, pair.first.c_str(), pair.second.c_str());
     }
 
-    celix_service_registration_options_t cOpts = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+    celix_service_registration_options_t cOpts; //TODO compile error gcc = CELIX_EMPTY_SERVICE_REGISTRATION_OPTIONS;
+    std::memset(&cOpts, 0, sizeof(cOpts));
+
     cOpts.svc = static_cast<void*>(&opts.svc);
     cOpts.serviceName = opts.serviceName.c_str();
     cOpts.serviceVersion = opts.serviceVersion.c_str();


Mime
View raw message