You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2017/01/17 19:57:32 UTC
celix git commit: CELIX-386: Improves usage of move semantics,
adds override keywords on overriden methods and some small
improvements
Repository: celix
Updated Branches:
refs/heads/develop ed9cb1c71 -> bbc654500
CELIX-386: Improves usage of move semantics, adds override keywords on overriden methods and some small improvements
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/bbc65450
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/bbc65450
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/bbc65450
Branch: refs/heads/develop
Commit: bbc654500ecac1e908715e0af0661aabfa7367bf
Parents: ed9cb1c
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Jan 17 21:01:26 2017 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Jan 17 21:02:28 2017 +0100
----------------------------------------------------------------------
README.md | 2 +-
dependency_manager/CMakeLists.txt | 30 +++++-----
.../include/celix/dm/Component.h | 26 ++++++---
.../include/celix/dm/Component_Impl.h | 44 +++++++++-----
.../include/celix/dm/DependencyManager.h | 48 ++++++++++++---
.../include/celix/dm/DmActivator.h | 61 +++++++++++++++-----
.../include/celix/dm/ServiceDependency.h | 3 +
.../getting_started/using_services_with_cxx.md | 14 ++---
.../dm_example_cxx/phase1/include/Phase1Cmp.h | 2 +-
.../phase1/src/Phase1Activator.cc | 19 +++++-
.../dm_example_cxx/phase2/include/Phase2Cmp.h | 4 +-
.../phase2a/src/Phase2aActivator.cc | 2 +-
.../dm_example_cxx/phase2a/src/Phase2aCmp.cc | 4 +-
.../phase2b/src/Phase2bActivator.cc | 2 +-
.../dm_example_cxx/phase2b/src/Phase2bCmp.cc | 6 ++
.../phase3/src/Phase3Activator.cc | 2 +-
.../src/Phase3LockingActivator.cc | 7 ++-
.../bar/private/include/Bar.h | 2 +-
.../bar/private/include/BarActivator.h | 2 +-
.../bar/private/src/BarActivator.cc | 4 +-
.../baz/private/include/BazActivator.h | 2 +-
.../baz/private/src/BazActivator.cc | 2 +-
.../foo/private/include/FooActivator.h | 2 +-
.../foo/private/src/FooActivator.cc | 2 +-
24 files changed, 206 insertions(+), 86 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 4f7b9d0..18a7b6b 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
#Apache Celix [![Build Status](https://travis-ci.org/apache/celix.svg?branch=develop)](https://travis-ci.org/apache/celix) [![Coverage Status](https://coveralls.io/repos/apache/celix/badge.svg?branch=develop&service=github)](https://coveralls.io/github/apache/celix?branch=develop) [![Coverity Scan Build Status](https://scan.coverity.com/projects/6685/badge.svg)](https://scan.coverity.com/projects/6685)
-Apache Celix is an implementation of the OSGi specification] adapted to C and C++ (C++11). It is a provides a framework to develop (dynamic) modular software applications using component and/or service-oriented programming.
+Apache Celix is an implementation of the OSGi specification adapted to C and C++ (C++11). It is a provides a framework to develop (dynamic) modular software applications using component and/or service-oriented programming.
##Building
For information how to build Apache Celix see [Building Apache Celix](documents/building/readme.md)
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/dependency_manager/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt
index ba65cf6..d849aa8 100644
--- a/dependency_manager/CMakeLists.txt
+++ b/dependency_manager/CMakeLists.txt
@@ -48,22 +48,22 @@ if (DEPENDENCY_MANAGER)
private/src/dm_event
private/src/dm_dependency_manager_impl
)
- #set_target_properties(dependency_manager_static PROPERTIES SOVERSION 1)
+ set_target_properties(dependency_manager_static PROPERTIES SOVERSION 1)
- #add_library(dependency_manager_so SHARED
- # private/src/dm_activator_base
- # private/src/dm_component_impl
- # private/src/dm_service_dependency
- # private/src/dm_event
- # private/src/dm_dependency_manager_impl
- #)
- #set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1)
+ add_library(dependency_manager_so SHARED
+ private/src/dm_activator_base
+ private/src/dm_component_impl
+ private/src/dm_service_dependency
+ private/src/dm_event
+ private/src/dm_dependency_manager_impl
+ )
+ set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1)
- #if (APPLE)
- # target_link_libraries(dependency_manager_so celix_framework "-undefined dynamic_lookup")
- #else()
- # target_link_libraries(dependency_manager_so celix_framework)
- #endif()
+ if (APPLE)
+ target_link_libraries(dependency_manager_so celix_framework "-undefined dynamic_lookup")
+ else()
+ target_link_libraries(dependency_manager_so celix_framework)
+ endif()
include_directories("public/include")
include_directories("private/include")
@@ -85,5 +85,5 @@ if (DEPENDENCY_MANAGER)
)
install_bundle(dm_shell)
install(TARGETS dependency_manager_static DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
- #install(TARGETS dependency_manager_so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
+ install(TARGETS dependency_manager_so DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dependency_manager)
endif (DEPENDENCY_MANAGER)
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 cd0a16b..fd07a42 100644
--- a/dependency_manager_cxx/include/celix/dm/Component.h
+++ b/dependency_manager_cxx/include/celix/dm/Component.h
@@ -25,8 +25,7 @@
#include <map>
#include <string>
-#include <list>
-#include <tuple>
+#include <vector>
namespace celix { namespace dm {
@@ -53,10 +52,12 @@ namespace celix { namespace dm {
template<class T>
class Component : public BaseComponent {
+ using type = T;
private:
- std::shared_ptr<T> instance {nullptr};
- std::list<T> refInstance {};
- std::list<std::shared_ptr<BaseServiceDependency>> dependencies {};
+ std::unique_ptr<T> instance {nullptr};
+ std::shared_ptr<T> sharedInstance {nullptr};
+ std::vector<T> valInstance {};
+ std::vector<std::shared_ptr<BaseServiceDependency>> dependencies {};
void (T::*initFp)() = {};
void (T::*startFp)() = {};
@@ -89,19 +90,26 @@ namespace celix { namespace dm {
T& getInstance();
/**
- * Set the component instance using a (shared) pointer.
+ * Set the component instance using a shared pointer.
*
* @return the DM Component reference for chaining (fluent API)
*/
Component<T>& setInstance(std::shared_ptr<T> inst);
/**
- * Set the component instance using rvalue reference
+ * Set the component instance using a unique pointer.
+ *
+ * @return the DM Component reference for chaining (fluent API)
+ */
+ Component<T>& setInstance(std::unique_ptr<T>&& inst);
+
+ /**
+ * Set the component instance using a value or rval reference
* The DM Component will contain the instance.
*
* @return the DM Component reference for chaining (fluent API)
*/
- Component<T>& setInstance(T&& inst);
+ Component<T>& setInstance(T inst);
/**
* Adds a C++ interface to provide as service to the Celix framework.
@@ -131,7 +139,7 @@ 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 = std::string{}, const Properties properties = Properties{});
+ template<class I> Component<T>& addCInterface(const I* svc, const std::string serviceName, const std::string version = std::string{}, const Properties properties = Properties{});
/**
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 b474421..a7b51f8 100644
--- a/dependency_manager_cxx/include/celix/dm/Component_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/Component_Impl.h
@@ -24,6 +24,7 @@
#include <memory>
#include <iostream>
#include <iomanip>
+#include <type_traits>
using namespace celix::dm;
@@ -42,8 +43,8 @@ Component<T>& Component<T>::addInterfaceWithName(const std::string serviceName,
//setup c properties
properties_pt cProperties = properties_create();
properties_set(cProperties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_CXX_LANGUAGE);
- for (auto iter = properties.begin(); iter != properties.end(); iter++) {
- properties_set(cProperties, (char *) iter->first.c_str(), (char *) iter->second.c_str());
+ for (const auto& pair : properties) {
+ properties_set(cProperties, (char *) pair.first.c_str(), (char *) pair.second.c_str());
}
T* cmpPtr = &this->getInstance();
@@ -63,6 +64,7 @@ template<class T>
template<class I>
Component<T>& Component<T>::addInterface(const std::string version, const Properties properties) {
//get name if not provided
+ static_assert(std::is_base_of<I,T>::value, "Component T must implement Interface I");
std::string serviceName = typeName<I>();
if (serviceName.empty()) {
std::cerr << "Cannot add interface, because type name could not be inferred. function: '" << __PRETTY_FUNCTION__ << "'\n";
@@ -72,11 +74,13 @@ Component<T>& Component<T>::addInterface(const std::string version, const Proper
};
template<class T>
-Component<T>& Component<T>::addCInterface(const void* svc, const std::string serviceName, const std::string version, const Properties properties) {
+template<class I>
+Component<T>& Component<T>::addCInterface(const I* svc, const std::string serviceName, const std::string version, const Properties properties) {
+ static_assert(std::is_pod<I>::value, "Service I must be a 'Plain Old Data' object");
properties_pt cProperties = properties_create();
properties_set(cProperties, CELIX_FRAMEWORK_SERVICE_LANGUAGE, CELIX_FRAMEWORK_SERVICE_C_LANGUAGE);
- for (auto iter = properties.begin(); iter != properties.end(); iter++) {
- properties_set(cProperties, (char*)iter->first.c_str(), (char*)iter->second.c_str());
+ for (const auto& pair : properties) {
+ properties_set(cProperties, (char*)pair.first.c_str(), (char*)pair.second.c_str());
}
const char *cVersion = version.empty() ? nullptr : version.c_str();
@@ -159,14 +163,16 @@ bool Component<T>::isValid() const {
template<class T>
T& Component<T>::getInstance() {
- if (this->refInstance.size() == 1) {
- return refInstance.front();
+ if (this->valInstance.size() == 1) {
+ return valInstance.front();
+ } else if (this->sharedInstance.get() != nullptr) {
+ return *this->sharedInstance;
} else {
if (this->instance.get() == nullptr) {
#ifdef __EXCEPTIONS
- this->instance = std::shared_ptr<T> {new T()};
+ this->instance = std::unique_ptr<T> {new T()};
#else
- this->instance = std::shared_ptr<T> {new(std::nothrow) T()};
+ this->instance = std::unique_ptr<T> {new(std::nothrow) T()};
#endif
}
@@ -176,14 +182,26 @@ T& Component<T>::getInstance() {
template<class T>
Component<T>& Component<T>::setInstance(std::shared_ptr<T> inst) {
- this->instance = inst;
+ this->valInstance.clear();
+ this->instance = std::unique_ptr<T> {nullptr};
+ this->sharedInstance = inst;
+ return *this;
+}
+
+template<class T>
+Component<T>& Component<T>::setInstance(std::unique_ptr<T>&& inst) {
+ this->valInstance.clear();
+ this->sharedInstance = std::shared_ptr<T> {nullptr};
+ this->instance = std::move(inst);
return *this;
}
template<class T>
-Component<T>& Component<T>::setInstance(T&& inst) {
- this->refInstance.clear();
- this->refInstance.push_back(std::move(inst));
+Component<T>& Component<T>::setInstance(T inst) {
+ this->instance = std::unique_ptr<T> {nullptr};
+ this->sharedInstance = std::shared_ptr<T> {nullptr};
+ this->valInstance.clear();
+ this->valInstance.push_back(std::forward<T>(inst));
return *this;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 1991c9d..68ec96f 100644
--- a/dependency_manager_cxx/include/celix/dm/DependencyManager.h
+++ b/dependency_manager_cxx/include/celix/dm/DependencyManager.h
@@ -17,8 +17,8 @@
* under the License.
*/
-#ifndef CELIX_DEPENDENCYMANAGER_H
-#define CELIX_DEPENDENCYMANAGER_H
+#ifndef CELIX_DM_DEPENDENCYMANAGER_H
+#define CELIX_DM_DEPENDENCYMANAGER_H
#include "celix/dm/types.h"
@@ -46,23 +46,55 @@ namespace celix { namespace dm {
const bundle_context_pt bundleContext() const;
const dm_dependency_manager_pt cDependencyManager() const;
+
/**
- * Creates and adds a new DM Component for a component of type T and instance inst
- * If inst if nullptr lazy initializion is used.
+ * Creates and adds a new DM Component for a component of type T.
*
* @return Returns a reference to the DM Component
*/
template<class T>
- Component<T>& createComponent(std::shared_ptr<T> inst = std::shared_ptr<T>{nullptr}) {
- Component<T>* cmp = Component<T>::create(this->context);;
+ Component<T>& createComponent() {
+ Component<T>* cmp = Component<T>::create(this->context);
if (cmp->isValid()) {
- cmp->setInstance(inst);
this->components.push_back(std::unique_ptr<BaseComponent> {cmp});
}
return *cmp;
}
/**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance using a unique ptr.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(std::unique_ptr<T>&& rhs) {
+ return this->createComponent<T>().setInstance(std::move(rhs));
+ }
+
+ /**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance using a shared ptr.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(std::shared_ptr<T> rhs) {
+ return this->createComponent<T>().setInstance(rhs);
+ }
+
+ /**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(T rhs) {
+ return this->createComponent<T>().setInstance(std::forward(rhs));
+ }
+
+ /**
* Starts the Dependency Manager
*/
void start();
@@ -75,4 +107,4 @@ namespace celix { namespace dm {
}}
-#endif //CELIX_DEPENDENCYMANAGER_H
+#endif //CELIX_DM_DEPENDENCYMANAGER_H
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 57f2f97..2ec57fb 100644
--- a/dependency_manager_cxx/include/celix/dm/DmActivator.h
+++ b/dependency_manager_cxx/include/celix/dm/DmActivator.h
@@ -22,16 +22,18 @@
#include "celix/dm/DependencyManager.h"
+#include <utility>
+
namespace celix { namespace dm {
class DmActivator {
protected:
- DependencyManager& depMng;
- DmActivator(DependencyManager& mng) : depMng(mng) {}
+ DependencyManager& mng;
+ DmActivator(DependencyManager& m) : mng(m) {}
public:
~DmActivator() = default;
- DependencyManager& manager() const { return this->depMng; }
+ DependencyManager& manager() const { return this->mng; }
/**
* The init of the DM Activator. Should be overridden by the bundle specific DM activator.
@@ -48,16 +50,6 @@ namespace celix { namespace dm {
virtual void deinit() {};
/**
- * 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(std::shared_ptr<T> inst = std::shared_ptr<T>{nullptr}) { return depMng.createComponent<T>(inst); }
-
- /**
* The static method to create a new DM activator.
* NOTE that this method in intentionally not implemented in the C++ Dependency Manager library.
* This should be done by the bundle specific DM activator.
@@ -66,6 +58,49 @@ namespace celix { namespace dm {
* @returns A pointer to a DmActivator. The Dependency Manager is responsible for deleting the pointer when the bundle is stopped.
*/
static DmActivator* create(DependencyManager& mng);
+
+ /**
+ * Creates and adds a new DM Component for a component of type T.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent() {
+ return mng.createComponent<T>();
+ }
+
+ /**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance using a unique ptr.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(std::unique_ptr<T>&& rhs) {
+ return mng.createComponent<T>(std::move(rhs));
+ }
+
+ /**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance using a shared ptr.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(std::shared_ptr<T> rhs) {
+ return mng.createComponent<T>(rhs);
+ }
+
+ /**
+ * Creates and adds a new DM Component for a component of type T and setting
+ * the instance.
+ *
+ * @return Returns a reference to the DM Component
+ */
+ template<class T>
+ Component<T>& createComponent(T rhs) {
+ return mng.createComponent<T>(std::forward(rhs));
+ }
};
}}
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 2d19200..c664fb2 100644
--- a/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
+++ b/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
@@ -67,6 +67,7 @@ namespace celix { namespace dm {
template<class T>
class TypedServiceDependency : public BaseServiceDependency {
+ using cmpType = T;
protected:
T* componentInstance {nullptr};
public:
@@ -81,6 +82,7 @@ namespace celix { namespace dm {
template<class T, typename I>
class CServiceDependency : public TypedServiceDependency<T> {
+ using type = I;
private:
std::string name {};
std::string filter {};
@@ -174,6 +176,7 @@ namespace celix { namespace dm {
template<class T, class I>
class ServiceDependency : public TypedServiceDependency<T> {
+ using type = I;
private:
bool addCxxLanguageFilter {true};
std::string name {};
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/documents/getting_started/using_services_with_cxx.md
----------------------------------------------------------------------
diff --git a/documents/getting_started/using_services_with_cxx.md b/documents/getting_started/using_services_with_cxx.md
index 5bfff92..488aacd 100644
--- a/documents/getting_started/using_services_with_cxx.md
+++ b/documents/getting_started/using_services_with_cxx.md
@@ -155,7 +155,7 @@ public:
void stop();
void deinit();
- virtual double method(int arg1, double arg2); //implementation of IAnotherExample::method
+ virtual double method(int arg1, double arg2) override; //implementation of IAnotherExample::method
int cMethod(int arg1, double arg2, double *out); //implementation of example_t->method;
};
@@ -177,7 +177,7 @@ private:
example_t cExample {nullptr, nullptr};
public:
BarActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //BAR_ACTIVATOR_H
@@ -242,7 +242,7 @@ void BarActivator::init() {
return bar->cMethod(arg1, arg2, out);
};
- createComponent(bar) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
+ mng.createComponent(bar) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
.addInterface<IAnotherExample>(IANOTHER_EXAMPLE_VERSION, props)
.addCInterface(&this->cExample, EXAMPLE_NAME, EXAMPLE_VERSION, cProps)
.setCallbacks(&Bar::init, &Bar::start, &Bar::stop, &Bar::deinit);
@@ -296,7 +296,7 @@ class FooActivator : public DmActivator {
private:
public:
FooActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //FOO_ACTIVATOR_H
@@ -360,7 +360,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
void FooActivator::init() {
- Component<Foo>& cmp = createComponent<Foo>()
+ Component<Foo>& cmp = mng.createComponent<Foo>()
.setCallbacks(nullptr, &Foo::start, &Foo::stop, nullptr);
cmp.createServiceDependency<IAnotherExample>()
@@ -433,7 +433,7 @@ class BazActivator : public DmActivator {
private:
public:
BazActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //BAZ_ACTIVATOR_H
@@ -521,7 +521,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
void BazActivator::init() {
- Component<Baz>& cmp = createComponent<Baz>()
+ Component<Baz>& cmp = mng.createComponent<Baz>()
.setCallbacks(nullptr, &Baz::start, &Baz::stop, nullptr);
cmp.createServiceDependency<IAnotherExample>()
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase1/include/Phase1Cmp.h b/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
index 5a45746..f475c41 100644
--- a/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
+++ b/examples/dm_example_cxx/phase1/include/Phase1Cmp.h
@@ -37,7 +37,7 @@ public:
void deinit();
int getData() override; //implements IPhase1
- virtual int infoCmd(char* line, FILE *out, FILE* err); //implements cmd service
+ int infoCmd(char* line, FILE *out, FILE* err); //implements cmd service
std::string getName() override;
};
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 c957cc6..6eb9d0d 100644
--- a/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
+++ b/examples/dm_example_cxx/phase1/src/Phase1Activator.cc
@@ -19,6 +19,7 @@
#include "Phase1Cmp.h"
#include "Phase1Activator.h"
+#include "IPhase2.h"
using namespace celix::dm;
@@ -31,8 +32,15 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
return new Phase1Activator(mng);
}
+struct InvalidCServ {
+ void* handle; //valid pod
+ int (*foo)(double arg); //still valid pod
+ void bar(double arg) {} //still valid pod
+ virtual void baz(double arg) {} //not a valid pod
+};
+
void Phase1Activator::init() {
- std::shared_ptr<Phase1Cmp> cmp {new Phase1Cmp()};
+ auto cmp = std::unique_ptr<Phase1Cmp>(new Phase1Cmp());
Properties cmdProps;
cmdProps[OSGI_SHELL_COMMAND_NAME] = "phase1_info";
@@ -46,11 +54,18 @@ void Phase1Activator::init() {
return cmp->infoCmd(line, out, err);
};
- createComponent(cmp) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
+ auto tst = std::unique_ptr<InvalidCServ>(new InvalidCServ{});
+ tst->handle = cmp.get();
+
+
+ mng.createComponent(std::move(cmp)) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
.addInterface<IPhase1>(IPHASE1_VERSION)
+ //.addInterface<IPhase2>() -> Compile error (static assert), because Phase1Cmp does not implement IPhase2
.addCInterface(&cmd, OSGI_SHELL_COMMAND_SERVICE_NAME, "", cmdProps)
+ //.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);
+
}
void Phase1Activator::deinit() {
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2/include/Phase2Cmp.h b/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
index 23f7b87..8f98ae7 100644
--- a/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
+++ b/examples/dm_example_cxx/phase2/include/Phase2Cmp.h
@@ -35,12 +35,12 @@ extern "C" {
class Phase2Cmp : public IPhase2 {
public:
Phase2Cmp() = default;
- Phase2Cmp(Phase2Cmp&& other);
+ Phase2Cmp(Phase2Cmp&& other) noexcept;
Phase2Cmp(const Phase2Cmp& other) = delete;
virtual ~Phase2Cmp() { std::cout << "Destroying Phase2\n"; };
void setPhase1(IPhase1* phase); //injector used by dependency manager
- void setName(srv::info::IName* name) { std::cout << "Setting IName with name: " << name->getName() << std::endl; }
+ void setName(srv::info::IName* name) { std::cout << "Setting IName with name: " << (name != nullptr ? name->getName() : "null") << std::endl; }
void setLogService(const log_service_t* logSrv);
double getData() override; //implements IPhase2
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 5515157..e33ae0e 100644
--- a/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
+++ b/examples/dm_example_cxx/phase2a/src/Phase2aActivator.cc
@@ -35,7 +35,7 @@ void Phase2Activator::init() {
Properties props {};
props["name"] = "phase2a";
- Component<Phase2Cmp>& cmp = createComponent<Phase2Cmp>()
+ Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
.setInstance(Phase2Cmp())
.addInterface<IPhase2>(IPHASE2_VERSION, props);
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc b/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
index 8523ebe..4f68679 100644
--- a/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
+++ b/examples/dm_example_cxx/phase2a/src/Phase2aCmp.cc
@@ -22,8 +22,8 @@
#include <stdlib.h>
#include <stdio.h>
-Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) : phase1(other.phase1), logSrv{other.logSrv} {
- std::cout << "Move constructor Phase2Cmp called\n";
+Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
+ std::cout << "Move constructor Phase2aCmp called\n";
other.phase1 = nullptr;
other.logSrv = nullptr;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 1aae052..4fba8c0 100644
--- a/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
+++ b/examples/dm_example_cxx/phase2b/src/Phase2bActivator.cc
@@ -33,7 +33,7 @@ void Phase2Activator::init() {
Properties props {};
props["name"] = "phase2b";
- Component<Phase2Cmp>& cmp = createComponent<Phase2Cmp>()
+ Component<Phase2Cmp>& cmp = mng.createComponent<Phase2Cmp>()
.addInterface<IPhase2>(IPHASE2_VERSION, props);
cmp.createServiceDependency<IPhase1>()
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
----------------------------------------------------------------------
diff --git a/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc b/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
index b6260af..2f420a0 100644
--- a/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
+++ b/examples/dm_example_cxx/phase2b/src/Phase2bCmp.cc
@@ -22,6 +22,12 @@
#include <stdlib.h>
#include <stdio.h>
+Phase2Cmp::Phase2Cmp(Phase2Cmp&& other) noexcept : phase1(other.phase1), logSrv{other.logSrv} {
+ std::cout << "Move constructor Phase2bCmp called\n";
+ other.phase1 = nullptr;
+ other.logSrv = nullptr;
+}
+
void Phase2Cmp::setPhase1(IPhase1* phase1) {
std::cout << "setting phase1 for phase2\n";
this->phase1 = phase1;
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 ef8cb86..1bccbbc 100644
--- a/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
+++ b/examples/dm_example_cxx/phase3/src/Phase3Activator.cc
@@ -29,7 +29,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
}
void Phase3Activator::init() {
- Component<Phase3Cmp>& cmp = createComponent<Phase3Cmp>() //NOTE no setInstance -> lazy initialization using the default constructor
+ Component<Phase3Cmp>& cmp = mng.createComponent<Phase3Cmp>() //NOTE no setInstance -> lazy initialization using the default constructor
.setCallbacks(nullptr, &Phase3Cmp::start, &Phase3Cmp::stop, nullptr);
cmp.createServiceDependency<IPhase2>()
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/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 c682371..29d178e 100644
--- a/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
+++ b/examples/dm_example_cxx/phase3_locking/src/Phase3LockingActivator.cc
@@ -21,6 +21,8 @@
#include "Phase3LockingCmp.h"
#include "Phase3LockingActivator.h"
+#include <memory>
+
using namespace celix::dm;
@@ -29,8 +31,9 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
}
void Phase3LockingActivator::init() {
- Component<Phase3LockingCmp>& cmp = createComponent<Phase3LockingCmp>()
- //NOTE no setInstance -> lazy initialization using the default constructor
+ auto inst = std::shared_ptr<Phase3LockingCmp> {new Phase3LockingCmp {}};
+
+ Component<Phase3LockingCmp>& cmp = mng.createComponent<Phase3LockingCmp>(inst) //set inst using a shared ptr
.setCallbacks(nullptr, &Phase3LockingCmp::start, &Phase3LockingCmp::stop, nullptr);
cmp.createServiceDependency<IPhase2>()
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/bar/private/include/Bar.h
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/bar/private/include/Bar.h b/examples/services_example_cxx/bar/private/include/Bar.h
index c7b0955..799f8a9 100644
--- a/examples/services_example_cxx/bar/private/include/Bar.h
+++ b/examples/services_example_cxx/bar/private/include/Bar.h
@@ -33,7 +33,7 @@ public:
void stop();
void deinit();
- virtual double method(int arg1, double arg2); //implementation of IAnotherExample::method
+ virtual double method(int arg1, double arg2) override; //implementation of IAnotherExample::method
int cMethod(int arg1, double arg2, double *out); //implementation of example_t->method;
};
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/bar/private/include/BarActivator.h
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/bar/private/include/BarActivator.h b/examples/services_example_cxx/bar/private/include/BarActivator.h
index 043a9f7..0c635a8 100644
--- a/examples/services_example_cxx/bar/private/include/BarActivator.h
+++ b/examples/services_example_cxx/bar/private/include/BarActivator.h
@@ -30,7 +30,7 @@ private:
example_t cExample {nullptr, nullptr};
public:
BarActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //BAR_ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/bar/private/src/BarActivator.cc
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/bar/private/src/BarActivator.cc b/examples/services_example_cxx/bar/private/src/BarActivator.cc
index eeb128d..e4b8bec 100644
--- a/examples/services_example_cxx/bar/private/src/BarActivator.cc
+++ b/examples/services_example_cxx/bar/private/src/BarActivator.cc
@@ -27,7 +27,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
}
void BarActivator::init() {
- std::shared_ptr<Bar> bar = std::shared_ptr<Bar>{new Bar{}};
+ auto bar = std::unique_ptr<Bar>{new Bar{}};
Properties props;
props["meta.info.key"] = "meta.info.value";
@@ -41,7 +41,7 @@ void BarActivator::init() {
return bar->cMethod(arg1, arg2, out);
};
- createComponent(bar) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
+ mng.createComponent(std::move(bar)) //using a pointer a instance. Also supported is lazy initialization (default constructor needed) or a rvalue reference (move)
.addInterface<IAnotherExample>(IANOTHER_EXAMPLE_VERSION, props)
.addCInterface(&this->cExample, EXAMPLE_NAME, EXAMPLE_VERSION, cProps)
.setCallbacks(&Bar::init, &Bar::start, &Bar::stop, &Bar::deinit);
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/baz/private/include/BazActivator.h
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/baz/private/include/BazActivator.h b/examples/services_example_cxx/baz/private/include/BazActivator.h
index eaac934..fe24918 100644
--- a/examples/services_example_cxx/baz/private/include/BazActivator.h
+++ b/examples/services_example_cxx/baz/private/include/BazActivator.h
@@ -28,7 +28,7 @@ class BazActivator : public DmActivator {
private:
public:
BazActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //BAZ_ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/baz/private/src/BazActivator.cc
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/baz/private/src/BazActivator.cc b/examples/services_example_cxx/baz/private/src/BazActivator.cc
index f4f43c3..3f17b5a 100644
--- a/examples/services_example_cxx/baz/private/src/BazActivator.cc
+++ b/examples/services_example_cxx/baz/private/src/BazActivator.cc
@@ -28,7 +28,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
void BazActivator::init() {
- Component<Baz>& cmp = createComponent<Baz>()
+ Component<Baz>& cmp = mng.createComponent<Baz>()
.setCallbacks(nullptr, &Baz::start, &Baz::stop, nullptr);
cmp.createServiceDependency<IAnotherExample>()
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/foo/private/include/FooActivator.h
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/foo/private/include/FooActivator.h b/examples/services_example_cxx/foo/private/include/FooActivator.h
index 5559697..2917cbd 100644
--- a/examples/services_example_cxx/foo/private/include/FooActivator.h
+++ b/examples/services_example_cxx/foo/private/include/FooActivator.h
@@ -28,7 +28,7 @@ class FooActivator : public DmActivator {
private:
public:
FooActivator(DependencyManager& mng) : DmActivator(mng) {}
- virtual void init();
+ virtual void init() override;
};
#endif //FOO_ACTIVATOR_H
http://git-wip-us.apache.org/repos/asf/celix/blob/bbc65450/examples/services_example_cxx/foo/private/src/FooActivator.cc
----------------------------------------------------------------------
diff --git a/examples/services_example_cxx/foo/private/src/FooActivator.cc b/examples/services_example_cxx/foo/private/src/FooActivator.cc
index 57d702b..fba10ce 100644
--- a/examples/services_example_cxx/foo/private/src/FooActivator.cc
+++ b/examples/services_example_cxx/foo/private/src/FooActivator.cc
@@ -28,7 +28,7 @@ DmActivator* DmActivator::create(DependencyManager& mng) {
void FooActivator::init() {
- Component<Foo>& cmp = createComponent<Foo>()
+ Component<Foo>& cmp = mng.createComponent<Foo>()
.setCallbacks(nullptr, &Foo::start, &Foo::stop, nullptr);
cmp.createServiceDependency<IAnotherExample>()