Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 41A80200B8E for ; Mon, 26 Sep 2016 10:33:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 402B5160AC8; Mon, 26 Sep 2016 08:33:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3474C160AB8 for ; Mon, 26 Sep 2016 10:33:02 +0200 (CEST) Received: (qmail 31719 invoked by uid 500); 26 Sep 2016 08:33:01 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 31708 invoked by uid 99); 26 Sep 2016 08:33:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2016 08:33:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 29CB6DFF56; Mon, 26 Sep 2016 08:33:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pnoltes@apache.org To: commits@celix.apache.org Message-Id: <7dc51e04febe4359aa97b7e90643532b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: 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. Date: Mon, 26 Sep 2016 08:33:01 +0000 (UTC) archived-at: Mon, 26 Sep 2016 08:33:03 -0000 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 Authored: Mon Sep 26 10:31:29 2016 +0200 Committer: Pepijn Noltes 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* create(bundle_context_pt, std::string name = {}); + static Component* 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 Component& addInterface(const std::string version, const Properties properties = {}); + template Component& 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& addInterface(const std::string serviceName, const std::string version = {}, const Properties properties = {}); + Component& 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& addCInterface(const void* svc, const std::string serviceName, const std::string version = {}, const Properties properties = {}); + Component& 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 -Component::Component(const bundle_context_pt context, std::string name) : BaseComponent(context, name) { } +Component::Component(const bundle_context_pt context, std::string name) : BaseComponent(context, name) {} template Component::~Component() { @@ -80,8 +80,11 @@ ServiceDependency& Component::createServiceDependency() { #ifdef __EXCEPTIONS auto dep = std::shared_ptr> {new ServiceDependency()}; #else + static ServiceDependency invalidDep{false}; auto dep = std::shared_ptr> {new(std::nothrow) ServiceDependency()}; - //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& Component::createCServiceDependency() { #ifdef __EXCEPTIONS auto dep = std::shared_ptr> {new CServiceDependency()}; #else + static CServiceDependency invalidDep{false}; auto dep = std::shared_ptr> {new(std::nothrow) CServiceDependency()}; - //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 Component* Component::create(bundle_context_pt context, std::string name) { std::string n = name.empty() ? typeName() : name; #ifdef __EXCEPTIONS - Component* cmp = new Component(context, n); + Component* cmp = new Component{context, n}; #else + static Component invalid{nullptr, std::string{}}; Component* cmp = new(std::nothrow) Component(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 - Component& createComponent(std::shared_ptr inst) { + Component& createComponent(std::shared_ptr inst = std::shared_ptr{nullptr}) { Component* cmp = Component::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 {cmp}); } - this->components.push_back(std::unique_ptr {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& createComponent(std::shared_ptr inst = {nullptr}) { return manager.createComponent(inst); } + Component& createComponent(std::shared_ptr inst = std::shared_ptr{nullptr}) { return manager.createComponent(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 namespace celix { namespace dm { - typedef std::map Properties; + using Properties = std::map; }} #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() {}; + CServiceDependency(bool valid = true) : TypedServiceDependency(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& setCService(const std::string serviceName, const std::string serviceVersionRange = {}, const std::string filter = {}); + CServiceDependency& 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& CServiceDependency::setCService(const std::string template void CServiceDependency::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::setupService() { template CServiceDependency& CServiceDependency::setAddLanguageFilter(bool addLang) { + if (!this->valid) { + *this; + } serviceDependency_setAddCLanguageFilter(this->cServiceDependency(), addLang); this->setupService(); return *this; @@ -48,12 +54,18 @@ CServiceDependency& CServiceDependency::setAddLanguageFilter(bool addL template CServiceDependency& CServiceDependency::setRequired(bool req) { + if (!this->valid) { + return *this; + } serviceDependency_setRequired(this->cServiceDependency(), req); return *this; } template CServiceDependency& CServiceDependency::setStrategy(DependencyUpdateStrategy strategy) { + if (!this->valid) { + return *this; + } this->setDepStrategy(strategy); return *this; } @@ -98,6 +110,9 @@ CServiceDependency& CServiceDependency::setCallbacks( template void CServiceDependency::setupCallbacks() { + if (!this->valid) { + return; + } int(*cset)(void*,const void*) {nullptr}; int(*cadd)(void*, const void*) {nullptr}; @@ -186,12 +201,16 @@ int CServiceDependency::invokeCallbackWithProperties(void(T::*fp)(const I*, } template -ServiceDependency::ServiceDependency() : TypedServiceDependency() { +ServiceDependency::ServiceDependency(bool valid) : TypedServiceDependency(valid) { setupService(); }; template void ServiceDependency::setupService() { + if (!this->valid) { + return; + } + std::string n = name; if (n.empty()) { @@ -352,6 +371,9 @@ int ServiceDependency::invokeCallbackWithProperties(void(T::*fp)(I*, Proper template void ServiceDependency::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) {