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: Adds usage of IBundleActivator to the CELIX_GEN_CXX_BUNDLE_ACTIVATOR macro.
Date Sun, 27 May 2018 19:15:21 GMT
Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-426-cxx-api 2e04253d5 -> e633316f8


CELIX-426: Adds usage of IBundleActivator to the CELIX_GEN_CXX_BUNDLE_ACTIVATOR macro.


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

Branch: refs/heads/feature/CELIX-426-cxx-api
Commit: e633316f8288120ded7fe50248f5b8c296eac1f7
Parents: 2e04253
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Sun May 27 21:14:34 2018 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Sun May 27 21:14:34 2018 +0200

----------------------------------------------------------------------
 .../bar/BarActivator.h                          |  9 ++---
 .../baz/BazActivator.h                          |  8 +++--
 .../foo/FooActivator.h                          |  9 ++---
 .../bundle_example_cxx/src/BundleActivator.cc   |  8 +++--
 .../dm_example_cxx/phase1/src/Phase1Activator.h | 11 +++---
 .../dm_example_cxx/phase2/src/Phase2Activator.h | 11 +++---
 .../dm_example_cxx/phase3/src/Phase3Activator.h |  4 +--
 .../phase3/src/Phase3BaseActivator.h            | 11 +++---
 .../phase3_locking/src/Phase3LockingActivator.h | 10 +++---
 .../src/ConsumerBundleActivator.cc              |  7 ++--
 .../src/ProviderBundleActivator.cc              |  6 ++--
 libs/framework/include/celix/BundleActivator.h  | 16 ++++-----
 libs/framework/include/celix/IBundleActivator.h | 37 ++++++++++++++++++++
 libs/framework/include/celix/IServiceFactory.h  |  2 +-
 14 files changed, 95 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 8ec236f..1f0baba 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,14 @@
 #ifndef BAR_ACTIVATOR_H
 #define BAR_ACTIVATOR_H
 
-#include "celix/BundleContext.h"
+#include "celix/IBundleActivator.h"
 #include "example.h"
 
-class BarActivator {
+class BarActivator : public celix::IBundleActivator {
 public:
-    celix_status_t start(celix::BundleContext &ctx);
-    celix_status_t stop(celix::BundleContext &ctx);
+    virtual ~BarActivator(){}
+    celix_status_t start(celix::BundleContext &ctx) override;
+    celix_status_t stop(celix::BundleContext &ctx) override;
 private:
     example_t cExample {nullptr, nullptr};
 };

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 1832ee1..d03b646 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,14 @@
 #ifndef BAZ_ACTIVATOR_H
 #define BAZ_ACTIVATOR_H
 
+#include "celix/IBundleActivator.h"
 #include "celix/BundleContext.h"
 
-class BazActivator {
+class BazActivator : public celix::IBundleActivator {
 public:
-    celix_status_t start(celix::BundleContext &ctx);
-    celix_status_t stop(celix::BundleContext &ctx);
+    virtual ~BazActivator(){}
+    celix_status_t start(celix::BundleContext &ctx) override;
+    celix_status_t stop(celix::BundleContext &ctx) override;
 };
 
 #endif //BAZ_ACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 0e1bb04..63c9979 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,17 @@
  * under the License.
  */
 
-#include "celix/BundleContext.h"
+#include "celix/IBundleActivator.h"
 
 #ifndef FOO_ACTIVATOR_H
 #define FOO_ACTIVATOR_H
 
-class FooActivator {
+class FooActivator : public celix::IBundleActivator {
 private:
 public:
-    celix_status_t start(celix::BundleContext &ctx);
-    celix_status_t stop(celix::BundleContext &ctx);
+    virtual ~FooActivator(){}
+    celix_status_t start(celix::BundleContext &ctx) override ;
+    celix_status_t stop(celix::BundleContext &ctx) override ;
 };
 
 #endif //FOO_ACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 741ce60..a082bff 100644
--- a/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
+++ b/examples/celix-examples/bundle_example_cxx/src/BundleActivator.cc
@@ -20,14 +20,16 @@
 #include <iostream>
 #include "celix/BundleActivator.h"
 namespace {
-    class BundleActivator  {
+    class BundleActivator : public celix::IBundleActivator {
     public:
-        celix_status_t start(celix::BundleContext &ctx) {
+        virtual ~BundleActivator(){}
+
+        celix_status_t start(celix::BundleContext &ctx) override {
             std::cout << "Hello world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
             return CELIX_SUCCESS;
         }
 
-        celix_status_t stop(celix::BundleContext &ctx) {
+        celix_status_t stop(celix::BundleContext &ctx) override {
             std::cout << "Goodbye world from C++ bundle with id " << ctx.getBundle().getBundleId()
<< std::endl;
             return CELIX_SUCCESS;
         }

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 0d68ec9..9c8f5a6 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,15 @@
 #ifndef CELIX_PHASE1ACTIVATOR_H
 #define CELIX_PHASE1ACTIVATOR_H
 
-#include <celix/BundleActivator.h>
-#include "celix/dm/DmActivator.h"
+#include "celix/IBundleActivator.h"
 #include "command.h"
 
-using namespace celix::dm;
 
-class Phase1Activator {
+class Phase1Activator : public celix::IBundleActivator {
 public:
-    celix_status_t start(celix::BundleContext& _ctx);
-    celix_status_t stop(celix::BundleContext& _ctx);
+    virtual ~Phase1Activator(){}
+    celix_status_t start(celix::BundleContext& _ctx) override;
+    celix_status_t stop(celix::BundleContext& _ctx) override;
 private:
     command_service_t cmd {nullptr, nullptr};
 };

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 eec1ab3..c551581 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,13 @@
 #ifndef CELIX_PHASE2AACTIVATOR_H
 #define CELIX_PHASE2AACTIVATOR_H
 
-#include "celix/BundleContext.h"
+#include "celix/IBundleActivator.h"
 
-using namespace celix::dm;
-
-class Phase2Activator  {
+class Phase2Activator : public celix::IBundleActivator {
 public:
-    celix_status_t start(celix::BundleContext &ctx);
-    celix_status_t stop(celix::BundleContext &ctx);
+    virtual ~Phase2Activator(){}
+    celix_status_t start(celix::BundleContext &ctx) override;
+    celix_status_t stop(celix::BundleContext &ctx) override;
 };
 
 #endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 731a3ad..7478fdb 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:
-    virtual celix_status_t start(celix::BundleContext& ctx);
-    virtual celix_status_t stop(celix::BundleContext& ctx);
+    celix_status_t start(celix::BundleContext& ctx) override;
+    celix_status_t stop(celix::BundleContext& ctx) override;
 };
 
 #endif //CELIX_PHASE2AACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 0fd6cbe..951b18a 100644
--- a/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
+++ b/examples/celix-examples/dm_example_cxx/phase3/src/Phase3BaseActivator.h
@@ -20,14 +20,15 @@
 #ifndef CELIX_PHASE3BASEACTIVATOR_H
 #define CELIX_PHASE3BASEACTIVATOR_H
 
-#include "celix/BundleContext.h"
-#include "celix/dm/DependencyManager.h"
+#include "celix/IBundleActivator.h"
+#include "Phase3Cmp.h"
 
-class Phase3BaseActivator  {
+class Phase3BaseActivator : public celix::IBundleActivator {
 public:
+    Phase3BaseActivator(){}
     virtual ~Phase3BaseActivator(){}
-    virtual celix_status_t start(celix::BundleContext& ctx);
-    virtual celix_status_t stop(celix::BundleContext& ctx);
+    celix_status_t start(celix::BundleContext& ctx) override;
+    celix_status_t stop(celix::BundleContext& ctx) override;
 protected:
     celix::dm::Component<Phase3Cmp> *cmp{nullptr};
 };

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 d3ade9e..603c2b2 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,16 +17,16 @@
  * under the License.
  */
 
-#include "celix/BundleContext.h"
+#include "celix/IBundleActivator.h"
 
 #ifndef CELIX_PHASE3LOCKINGACTIVATOR_H
 #define CELIX_PHASE3LOCKINGACTIVATOR_H
 
-
-class Phase3LockingActivator {
+class Phase3LockingActivator : public celix::IBundleActivator {
 public:
-    celix_status_t start(celix::BundleContext& ctx);
-    celix_status_t stop(celix::BundleContext& ctx);
+    virtual ~Phase3LockingActivator(){}
+    celix_status_t start(celix::BundleContext& ctx) override;
+    celix_status_t stop(celix::BundleContext& ctx) override;
 };
 
 #endif //CELIX_PHASE3LOCKINGAACTIVATOR_H

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 5f74b0c..10c3e51 100644
--- a/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
+++ b/examples/celix-examples/services_example_cxx/src/ConsumerBundleActivator.cc
@@ -26,9 +26,10 @@
 #include "ICalc.h"
 
 namespace {
-    class BundleActivator {
+    class BundleActivator : public celix::IBundleActivator {
     public:
-        celix_status_t  start(celix::BundleContext &ctx) {
+        virtual ~BundleActivator(){}
+        celix_status_t  start(celix::BundleContext &ctx) override {
             this->trackerId = ctx.trackServices<example::ICalc>(example::ICalc::NAME,
                  [this](example::ICalc *) {  this->trackCount += 1; },
                  [this](example::ICalc *) {  this->trackCount -= 1; });
@@ -37,7 +38,7 @@ namespace {
             return CELIX_SUCCESS;
         }
 
-        celix_status_t  stop(celix::BundleContext &ctx) {
+        celix_status_t  stop(celix::BundleContext &ctx) override {
             ctx.stopTracker(this->trackerId);
             this->running = false;
             this->useThread.join();

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/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 36a2b33..6d337a7 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 {
+    class BundleActivator : public celix::IBundleActivator {
     public:
-        celix_status_t  start(celix::BundleContext &ctx) {
+        celix_status_t start(celix::BundleContext &ctx)  override {
             /*
              * This thread registers calc service to a max of 100, then unregistered the
services and repeats.
              */
@@ -69,7 +69,7 @@ namespace {
             return  CELIX_SUCCESS;
         }
 
-        celix_status_t  stop(celix::BundleContext &) {
+        celix_status_t  stop(celix::BundleContext &) override {
             this->running = false;
             th.join();
             return CELIX_SUCCESS;

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/libs/framework/include/celix/BundleActivator.h
----------------------------------------------------------------------
diff --git a/libs/framework/include/celix/BundleActivator.h b/libs/framework/include/celix/BundleActivator.h
index 448f75b..855b3dd 100644
--- a/libs/framework/include/celix/BundleActivator.h
+++ b/libs/framework/include/celix/BundleActivator.h
@@ -19,10 +19,7 @@
 
 #include <memory>
 
-#include "celix/BundleContext.h"
-#include "celix/Framework.h"
-
-#include "celix/BundleContext.h"
+#include "celix/IBundleActivator.h"
 #include "celix/Framework.h"
 
 #ifndef CXX_CELIX_BUNDLEACTIVATOR_H
@@ -33,16 +30,17 @@ namespace celix {
      * 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.
+     * - Implementing the celix::IBundleActivator interface, which contains:
+     *      - 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{};
+        std::unique_ptr<celix::IBundleActivator> activator{};
     public:
         BundleActivatorAdapter(bundle_context_t *c_ctx) {
             this->fw = std::unique_ptr<celix::Framework>{new celix::impl::FrameworkImpl{c_ctx}};
\
@@ -57,7 +55,7 @@ namespace celix {
         }
 
         celix_status_t start() noexcept  {
-            this->activator = std::unique_ptr<T>{new T};
+            this->activator = std::unique_ptr<celix::IBundleActivator>{new T};
             celix_status_t status = this->activator->start(*this->ctx);
             if (status == CELIX_SUCCESS) {
                 this->ctx->getDependencyManager().start();

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/libs/framework/include/celix/IBundleActivator.h
----------------------------------------------------------------------
diff --git a/libs/framework/include/celix/IBundleActivator.h b/libs/framework/include/celix/IBundleActivator.h
new file mode 100644
index 0000000..6e8d2a3
--- /dev/null
+++ b/libs/framework/include/celix/IBundleActivator.h
@@ -0,0 +1,37 @@
+/**
+ *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.
+ */
+
+#include "celix/BundleContext.h"
+
+#ifndef CXX_CELIX_IBUNDLEACTIVATOR_H
+#define CXX_CELIX_IBUNDLEACTIVATOR_H
+
+namespace celix {
+
+    class IBundleActivator {
+
+    public:
+        virtual ~IBundleActivator(){}
+
+        virtual celix_status_t start(celix::BundleContext &ctx) = 0;
+        virtual celix_status_t stop(celix::BundleContext &ctx) = 0;
+    };
+}
+
+#endif //CXX_CELIX_IBUNDLEACTIVATOR_H
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/e633316f/libs/framework/include/celix/IServiceFactory.h
----------------------------------------------------------------------
diff --git a/libs/framework/include/celix/IServiceFactory.h b/libs/framework/include/celix/IServiceFactory.h
index d35f4ba..8ac8a11 100644
--- a/libs/framework/include/celix/IServiceFactory.h
+++ b/libs/framework/include/celix/IServiceFactory.h
@@ -28,7 +28,7 @@ namespace celix {
     class IServiceFactory {
     public:
         using type = I;
-        
+
         virtual ~IServiceFactory() = default;
 
         virtual I* getService(const celix::Bundle &bundle, const celix::Properties &properties)
= 0;


Mime
View raw message