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-386: Fixes an error in the ServiceDependency callback handling
Date Mon, 27 Mar 2017 17:34:11 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 544906ff6 -> d14fa9939


CELIX-386: Fixes an error in the ServiceDependency callback handling


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

Branch: refs/heads/develop
Commit: d14fa993945d0d95bb9df8d7864f992fe4e7f085
Parents: 544906f
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Mon Mar 27 19:33:37 2017 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Mon Mar 27 19:33:37 2017 +0200

----------------------------------------------------------------------
 .../include/celix/dm/ServiceDependency_Impl.h   | 37 +++++++++++---------
 framework/private/src/service_registration.c    | 10 +++---
 2 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d14fa993/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 731800d..85f5504 100644
--- a/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
+++ b/dependency_manager_cxx/include/celix/dm/ServiceDependency_Impl.h
@@ -188,19 +188,22 @@ template<class T, typename I>
 int CServiceDependency<T,I>::invokeCallback(std::function<void(const I*, Properties&&)>
fp, service_reference_pt  ref, const void* service) {
     service_registration_pt reg {nullptr};
     properties_pt props {nullptr};
-    serviceReference_getServiceRegistration(ref, &reg);
-    serviceRegistration_getProperties(reg, &props);
 
     Properties properties {};
     const char* key {nullptr};
     const char* value {nullptr};
 
-    hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
-    while(hashMapIterator_hasNext(&iter)) {
-        key = (const char*) hashMapIterator_nextKey(&iter);
-        value = properties_get(props, key);
-        //std::cout << "got property " << key << "=" << value <<
"\n";
-        properties[key] = value;
+    if (ref != nullptr) {
+        serviceReference_getServiceRegistration(ref, &reg);
+        serviceRegistration_getProperties(reg, &props);
+        
+        hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
+        while(hashMapIterator_hasNext(&iter)) {
+            key = (const char*) hashMapIterator_nextKey(&iter);
+            value = properties_get(props, key);
+            //std::cout << "got property " << key << "=" << value
<< "\n";
+            properties[key] = value;
+        }
     }
 
     const I* srv = (const I*) service;
@@ -389,19 +392,21 @@ int ServiceDependency<T,I>::invokeCallback(std::function<void(I*,
Properties&&)>
     service_registration_pt reg {nullptr};
     properties_pt props {nullptr};
     I *svc = (I*)service;
-    serviceReference_getServiceRegistration(ref, &reg);
-    serviceRegistration_getProperties(reg, &props);
 
     Properties properties {};
     const char* key {nullptr};
     const char* value {nullptr};
 
-    hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
-    while(hashMapIterator_hasNext(&iter)) {
-        key = (const char*) hashMapIterator_nextKey(&iter);
-        value = properties_get(props, key);
-        //std::cout << "got property " << key << "=" << value <<
"\n";
-        properties[key] = value;
+    if (ref != nullptr) {
+        serviceReference_getServiceRegistration(ref, &reg);
+        serviceRegistration_getProperties(reg, &props);
+        hash_map_iterator_t iter = hashMapIterator_construct((hash_map_pt)props);
+        while(hashMapIterator_hasNext(&iter)) {
+            key = (const char*) hashMapIterator_nextKey(&iter);
+            value = properties_get(props, key);
+            //std::cout << "got property " << key << "=" << value
<< "\n";
+            properties[key] = value;
+        }
     }
 
     fp(svc, std::move(properties)); //explicit move of lvalue properties.

http://git-wip-us.apache.org/repos/asf/celix/blob/d14fa993/framework/private/src/service_registration.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registration.c b/framework/private/src/service_registration.c
index e916457..5d23dbf 100644
--- a/framework/private/src/service_registration.c
+++ b/framework/private/src/service_registration.c
@@ -221,17 +221,17 @@ celix_status_t serviceRegistration_ungetService(service_registration_pt
registra
 celix_status_t serviceRegistration_getProperties(service_registration_pt registration, properties_pt
*properties) {
 	celix_status_t status = CELIX_SUCCESS;
 
-    if (registration != NULL && *properties == NULL) {
+    if (registration != NULL) {
         celixThreadRwlock_readLock(&registration->lock);
         *properties = registration->properties;
         celixThreadRwlock_unlock(&registration->lock);
-	} else {
-		status = CELIX_ILLEGAL_ARGUMENT;
-	}
+     } else {
+          status = CELIX_ILLEGAL_ARGUMENT;
+     }
 
     framework_logIfError(logger, status, NULL, "Cannot get registration properties");
 
-	return status;
+    return status;
 }
 
 celix_status_t serviceRegistration_setProperties(service_registration_pt registration, properties_pt
properties) {


Mime
View raw message