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 2016/09/26 08:33:01 UTC
celix git commit: CELIX-370: Makes use of default argument more
explicit for OSX compiling and adds static (invalid) version for Component &
SrvDependencies to return when new(nothrow) fails.
Repository: celix
Updated Branches:
refs/heads/develop 3a8f43437 -> d02d39304
CELIX-370: Makes use of default argument more explicit for OSX compiling and adds static (invalid) version for Component & SrvDependencies to return when new(nothrow) fails.
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d02d3930
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d02d3930
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d02d3930
Branch: refs/heads/develop
Commit: d02d3930476739b3d9b49face538de1d420ebab0
Parents: 3a8f434
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Sep 26 10:31:29 2016 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Sep 26 10:31:29 2016 +0200
----------------------------------------------------------------------
.../include/celix/dm/Component.h | 8 +++----
.../include/celix/dm/Component_Impl.h | 18 +++++++++++----
.../include/celix/dm/DependencyManager.h | 8 +++----
.../include/celix/dm/DmActivator.h | 2 +-
.../include/celix/dm/Properties.h | 2 +-
.../include/celix/dm/ServiceDependency.h | 16 +++++++++----
.../include/celix/dm/ServiceDependency_Impl.h | 24 +++++++++++++++++++-
dependency_manager_cxx/src/ServiceDependency.cc | 12 +++++++---
8 files changed, 66 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/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 4963d9d..578714c 100644
--- a/dependency_manager_cxx/include/celix/dm/Component.h
+++ b/dependency_manager_cxx/include/celix/dm/Component.h
@@ -71,7 +71,7 @@ namespace celix { namespace dm {
* Will use new(nothrow) if exceptions are disabled.
* @return newly created DM Component or nullptr
*/
- static Component<T>* create(bundle_context_pt, std::string name = {});
+ static Component<T>* create(bundle_context_pt, std::string name = std::string{});
/**
* Wether the component is valid. Invalid component can occurs when no new components can be created and
@@ -111,7 +111,7 @@ namespace celix { namespace dm {
* @param properties To (meta) properties to provide with the service
* @return the DM Component reference for chaining (fluent API)
*/
- template<class I> Component<T>& addInterface(const std::string version, const Properties properties = {});
+ template<class I> Component<T>& addInterface(const std::string version, const Properties properties = Properties{});
/**
* Adds a C++ interface to provide as service to the Celix framework.
@@ -121,7 +121,7 @@ namespace celix { namespace dm {
* @param properties To (meta) properties to provide with the service
* @return the DM Component reference for chaining (fluent API)
*/
- Component<T>& addInterface(const std::string serviceName, const std::string version = {}, const Properties properties = {});
+ Component<T>& addInterface(const std::string serviceName, const std::string version = std::string{}, const Properties properties = Properties{});
/**
* Adds a C interface to provide as service to the Celix framework.
@@ -131,7 +131,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 = {}, const Properties properties = {});
+ Component<T>& addCInterface(const void* 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/d02d3930/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 eadfa15..07dbeea 100644
--- a/dependency_manager_cxx/include/celix/dm/Component_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/Component_Impl.h
@@ -27,7 +27,7 @@
using namespace celix::dm;
template<class T>
-Component<T>::Component(const bundle_context_pt context, std::string name) : BaseComponent(context, name) { }
+Component<T>::Component(const bundle_context_pt context, std::string name) : BaseComponent(context, name) {}
template<class T>
Component<T>::~Component() {
@@ -80,8 +80,11 @@ ServiceDependency<T,I>& Component<T>::createServiceDependency() {
#ifdef __EXCEPTIONS
auto dep = std::shared_ptr<ServiceDependency<T,I>> {new ServiceDependency<T,I>()};
#else
+ static ServiceDependency<T,I> invalidDep{false};
auto dep = std::shared_ptr<ServiceDependency<T,I>> {new(std::nothrow) ServiceDependency<T,I>()};
- //TODO handle nullptr, how?
+ if (dep == nullptr) {
+ return invalidDep;
+ }
#endif
this->dependencies.push_back(dep);
component_addServiceDependency(cComponent(), dep->cServiceDependency());
@@ -103,8 +106,11 @@ CServiceDependency<T,I>& Component<T>::createCServiceDependency() {
#ifdef __EXCEPTIONS
auto dep = std::shared_ptr<CServiceDependency<T,I>> {new CServiceDependency<T,I>()};
#else
+ static CServiceDependency<T,I> invalidDep{false};
auto dep = std::shared_ptr<CServiceDependency<T,I>> {new(std::nothrow) CServiceDependency<T,I>()};
- //TODO handle nullptr, how?
+ if (dep == nullptr) {
+ return invalidDep;
+ }
#endif
this->dependencies.push_back(dep);
component_addServiceDependency(cComponent(), dep->cServiceDependency());
@@ -124,9 +130,13 @@ template<class T>
Component<T>* Component<T>::create(bundle_context_pt context, std::string name) {
std::string n = name.empty() ? typeName<T>() : name;
#ifdef __EXCEPTIONS
- Component<T>* cmp = new Component<T>(context, n);
+ Component<T>* cmp = new Component<T>{context, n};
#else
+ static Component<T> invalid{nullptr, std::string{}};
Component<T>* cmp = new(std::nothrow) Component<T>(context, n);
+ if (cmp == nullptr) {
+ cmp = &invalid;
+ }
#endif
return cmp;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/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 569cc2e..a9f11b9 100644
--- a/dependency_manager_cxx/include/celix/dm/DependencyManager.h
+++ b/dependency_manager_cxx/include/celix/dm/DependencyManager.h
@@ -53,13 +53,11 @@ namespace celix { namespace dm {
* @return Returns a reference to the DM Component
*/
template<class T>
- Component<T>& createComponent(std::shared_ptr<T> inst) {
+ Component<T>& createComponent(std::shared_ptr<T> inst = std::shared_ptr<T>{nullptr}) {
Component<T>* cmp = Component<T>::create(this->context);
- //TODO handle nullptr component, how?
- if (inst.get() != nullptr) {
- cmp->setInstance(inst);
+ if (cmp->isValid()) {
+ this->components.push_back(std::unique_ptr<BaseComponent> {cmp});
}
- this->components.push_back(std::unique_ptr<BaseComponent> {cmp});
return *cmp;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/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 69c86eb..e1207df 100644
--- a/dependency_manager_cxx/include/celix/dm/DmActivator.h
+++ b/dependency_manager_cxx/include/celix/dm/DmActivator.h
@@ -53,7 +53,7 @@ namespace celix { namespace dm {
* @return Returns a reference to the DM Component
*/
template< class T>
- Component<T>& createComponent(std::shared_ptr<T> inst = {nullptr}) { return manager.createComponent<T>(inst); }
+ Component<T>& createComponent(std::shared_ptr<T> inst = std::shared_ptr<T>{nullptr}) { return manager.createComponent<T>(inst); }
/**
* The static method to create a new DM activator.
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/dependency_manager_cxx/include/celix/dm/Properties.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/Properties.h b/dependency_manager_cxx/include/celix/dm/Properties.h
index 7e4ca95..bb4fd78 100644
--- a/dependency_manager_cxx/include/celix/dm/Properties.h
+++ b/dependency_manager_cxx/include/celix/dm/Properties.h
@@ -24,7 +24,7 @@
#include <string>
namespace celix { namespace dm {
- typedef std::map<std::string, std::string> Properties;
+ using Properties = std::map<std::string, std::string>;
}}
#endif //CELIX_DM_PROPERTIES_H
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/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 17e02fe..b42ef76 100644
--- a/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
+++ b/dependency_manager_cxx/include/celix/dm/ServiceDependency.h
@@ -45,15 +45,21 @@ namespace celix { namespace dm {
class BaseServiceDependency {
protected:
+ const bool valid;
dm_service_dependency_pt cServiceDep {nullptr};
void setDepStrategy(DependencyUpdateStrategy strategy);
public:
- BaseServiceDependency();
+ BaseServiceDependency(bool valid);
virtual ~BaseServiceDependency() = default;
/**
+ * Wether the service dependency is valid.
+ */
+ bool isValid() const { return valid; }
+
+ /**
* Returns the C DM service dependency
*/
dm_service_dependency_pt cServiceDependency() const { return cServiceDep; }
@@ -64,7 +70,7 @@ namespace celix { namespace dm {
protected:
T* componentInstance {nullptr};
public:
- TypedServiceDependency() : BaseServiceDependency() {}
+ TypedServiceDependency(bool valid) : BaseServiceDependency(valid) {}
virtual ~TypedServiceDependency() = default;
/**
@@ -95,7 +101,7 @@ namespace celix { namespace dm {
void setupService();
public:
- CServiceDependency() : TypedServiceDependency<T>() {};
+ CServiceDependency(bool valid = true) : TypedServiceDependency<T>(valid) {};
virtual ~CServiceDependency() = default;
/**
@@ -106,7 +112,7 @@ namespace celix { namespace dm {
* @param filter The (additional) filter to use (e.g. "(location=front)")
* @return the C service dependency reference for chaining (fluent API)
*/
- CServiceDependency<T,I>& setCService(const std::string serviceName, const std::string serviceVersionRange = {}, const std::string filter = {});
+ CServiceDependency<T,I>& setCService(const std::string serviceName, const std::string serviceVersionRange = std::string{}, const std::string filter = std::string{});
/**
* Specify if the service dependency is required. Default is false
@@ -183,7 +189,7 @@ namespace celix { namespace dm {
int invokeCallback(void(T::*fp)(I*), const void* service);
int invokeCallbackWithProperties(void(T::*fp)(I*, Properties&&), service_reference_pt ref, const void* service);
public:
- ServiceDependency();
+ ServiceDependency(bool valid = true);
virtual ~ServiceDependency() = default;
/**
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h b/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
index ccd4d01..13055b6 100644
--- a/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
@@ -34,6 +34,9 @@ CServiceDependency<T,I>& CServiceDependency<T,I>::setCService(const std::string
template<class T, typename I>
void CServiceDependency<T,I>::setupService() {
+ if (!this->valid) {
+ return;
+ }
const char* cversion = this->versionRange.empty() ? nullptr : versionRange.c_str();
const char* cfilter = filter.empty() ? nullptr : filter.c_str();
serviceDependency_setService(this->cServiceDependency(), this->name.c_str(), cversion, cfilter);
@@ -41,6 +44,9 @@ void CServiceDependency<T,I>::setupService() {
template<class T, typename I>
CServiceDependency<T,I>& CServiceDependency<T,I>::setAddLanguageFilter(bool addLang) {
+ if (!this->valid) {
+ *this;
+ }
serviceDependency_setAddCLanguageFilter(this->cServiceDependency(), addLang);
this->setupService();
return *this;
@@ -48,12 +54,18 @@ CServiceDependency<T,I>& CServiceDependency<T,I>::setAddLanguageFilter(bool addL
template<class T, typename I>
CServiceDependency<T,I>& CServiceDependency<T,I>::setRequired(bool req) {
+ if (!this->valid) {
+ return *this;
+ }
serviceDependency_setRequired(this->cServiceDependency(), req);
return *this;
}
template<class T, typename I>
CServiceDependency<T,I>& CServiceDependency<T,I>::setStrategy(DependencyUpdateStrategy strategy) {
+ if (!this->valid) {
+ return *this;
+ }
this->setDepStrategy(strategy);
return *this;
}
@@ -98,6 +110,9 @@ CServiceDependency<T,I>& CServiceDependency<T,I>::setCallbacks(
template<class T, typename I>
void CServiceDependency<T,I>::setupCallbacks() {
+ if (!this->valid) {
+ return;
+ }
int(*cset)(void*,const void*) {nullptr};
int(*cadd)(void*, const void*) {nullptr};
@@ -186,12 +201,16 @@ int CServiceDependency<T,I>::invokeCallbackWithProperties(void(T::*fp)(const I*,
}
template<class T, class I>
-ServiceDependency<T,I>::ServiceDependency() : TypedServiceDependency<T>() {
+ServiceDependency<T,I>::ServiceDependency(bool valid) : TypedServiceDependency<T>(valid) {
setupService();
};
template<class T, class I>
void ServiceDependency<T,I>::setupService() {
+ if (!this->valid) {
+ return;
+ }
+
std::string n = name;
if (n.empty()) {
@@ -352,6 +371,9 @@ int ServiceDependency<T,I>::invokeCallbackWithProperties(void(T::*fp)(I*, Proper
template<class T, class I>
void ServiceDependency<T,I>::setupCallbacks() {
+ if (!this->valid) {
+ return;
+ }
int(*cset)(void*,const void*) {nullptr};
int(*cadd)(void*, const void*) {nullptr};
http://git-wip-us.apache.org/repos/asf/celix/blob/d02d3930/dependency_manager_cxx/src/ServiceDependency.cc
----------------------------------------------------------------------
diff --git a/dependency_manager_cxx/src/ServiceDependency.cc b/dependency_manager_cxx/src/ServiceDependency.cc
index 559efba..452ecc8 100644
--- a/dependency_manager_cxx/src/ServiceDependency.cc
+++ b/dependency_manager_cxx/src/ServiceDependency.cc
@@ -22,12 +22,18 @@
using namespace celix::dm;
-BaseServiceDependency::BaseServiceDependency() {
- serviceDependency_create(&this->cServiceDep);
- serviceDependency_setStrategy(this->cServiceDep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND); //NOTE using suspend as default strategy
+BaseServiceDependency::BaseServiceDependency(bool v) : valid{v} {
+ if (this->valid) {
+ serviceDependency_create(&this->cServiceDep);
+ //NOTE using suspend as default strategy
+ serviceDependency_setStrategy(this->cServiceDep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
+ }
}
void BaseServiceDependency::setDepStrategy(DependencyUpdateStrategy strategy) {
+ if (!valid) {
+ return;
+ }
if (strategy == DependencyUpdateStrategy::locking) {
serviceDependency_setStrategy(this->cServiceDependency(), DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
} else if (strategy == DependencyUpdateStrategy::suspend) {