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 2015/11/18 15:43:19 UTC

celix git commit: CELIX-272: Add missing getBundles method for service_registry.

Repository: celix
Updated Branches:
  refs/heads/develop c1c2ac9f6 -> 78bd2627f


CELIX-272: Add missing getBundles method for service_registry.


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

Branch: refs/heads/develop
Commit: 78bd2627f94e0c2ac87cfe80935cc0b5cb13aa35
Parents: c1c2ac9
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Nov 18 15:42:33 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Nov 18 15:42:33 2015 +0100

----------------------------------------------------------------------
 framework/private/src/service_registry.c | 35 +++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/78bd2627/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index 1b1c2b1..1c4f725 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -50,9 +50,9 @@ static celix_status_t serviceRegistry_checkReference(service_registry_pt registr
                                                      reference_status_t *refStatus);
 static void serviceRegistry_logIllegalReference(service_registry_pt registry, service_reference_pt reference,
                                                    reference_status_t refStatus);
-
 static celix_status_t serviceRegistry_setReferenceStatus(service_registry_pt registry, service_reference_pt reference,
                                                   bool deleted);
+static celix_status_t serviceRegistry_getUsingBUndles(service_registry_pt registry, service_registration_pt reg, array_list_pt *bundles);
 
 celix_status_t serviceRegistry_create(framework_pt framework, serviceChanged_function_pt serviceChanged, service_registry_pt *out) {
 	celix_status_t status;
@@ -63,7 +63,7 @@ celix_status_t serviceRegistry_create(framework_pt framework, serviceChanged_fun
 	} else {
 
         reg->callback.handle = reg;
-        reg->callback.getUsingBundles = NULL; /*TODO*/
+        reg->callback.getUsingBundles = (void *)serviceRegistry_getUsingBUndles;
         reg->callback.unregister = (void *) serviceRegistry_unregisterService;
         reg->callback.modified = (void *) serviceRegistry_servicePropertiesModified;
 
@@ -670,3 +670,34 @@ celix_status_t serviceRegistry_servicePropertiesModified(service_registry_pt reg
 	}
 	return CELIX_SUCCESS;
 }
+
+static celix_status_t serviceRegistry_getUsingBUndles(service_registry_pt registry, service_registration_pt registration, array_list_pt *out) {
+    celix_status_t status;
+    array_list_pt bundles = NULL;
+    hash_map_iterator_pt iter;
+
+    status = arrayList_create(&bundles);
+    if (status == CELIX_SUCCESS) {
+        celixThreadRwlock_readLock(&registry->lock);
+        iter = hashMapIterator_create(registry->serviceReferences);
+        while (hashMapIterator_hasNext(iter)) {
+            hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+            bundle_pt registrationUser = hashMapEntry_getKey(entry);
+            service_registration_pt reg = hashMapEntry_getValue(entry);
+            if (registration == reg) {
+                arrayList_add(bundles, registrationUser);
+            }
+        }
+        celixThreadRwlock_unlock(&registry->lock);
+    }
+
+    if (status == CELIX_SUCCESS) {
+        *out = bundles;
+    } else {
+        if (bundles != NULL) {
+            arrayList_destroy(bundles);
+        }
+    }
+
+    return status;
+}