celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [1/2] celix git commit: Refactors some usage of the filters.
Date Tue, 13 Feb 2018 14:23:04 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 7d87b0847 -> c31401633


Refactors some usage of the filters.


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

Branch: refs/heads/develop
Commit: 33e96eb480d3060cfeed73e5c85ec6504a0cd272
Parents: 7d87b08
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Tue Feb 13 15:16:42 2018 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Tue Feb 13 15:16:42 2018 +0100

----------------------------------------------------------------------
 framework/include/listener_hook_service.h       |   3 +-
 framework/src/filter.c                          |   2 +-
 framework/src/framework.c                       | 140 +++++++++----------
 pubsub/pubsub_spi/include/pubsub_utils.h        |   6 +-
 pubsub/pubsub_spi/src/pubsub_utils.c            |   6 +-
 .../topology_manager/src/topology_manager.c     |   2 +-
 6 files changed, 73 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/framework/include/listener_hook_service.h
----------------------------------------------------------------------
diff --git a/framework/include/listener_hook_service.h b/framework/include/listener_hook_service.h
index 1f0c966..d80c09e 100644
--- a/framework/include/listener_hook_service.h
+++ b/framework/include/listener_hook_service.h
@@ -28,7 +28,6 @@
 #define LISTENER_HOOK_SERVICE_H_
 
 
-typedef struct listener_hook *listener_hook_pt;
 typedef struct listener_hook_info *listener_hook_info_pt;
 typedef struct listener_hook_service *listener_hook_service_pt;
 
@@ -41,7 +40,7 @@ extern "C" {
 
 struct listener_hook_info {
 	bundle_context_pt context;
-	char *filter;
+	const char *filter;
 	bool removed;
 };
 

http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/framework/src/filter.c
----------------------------------------------------------------------
diff --git a/framework/src/filter.c b/framework/src/filter.c
index 019dff6..b2d942b 100644
--- a/framework/src/filter.c
+++ b/framework/src/filter.c
@@ -110,9 +110,9 @@ void filter_destroy(celix_filter_t * filter) {
         filter->value = NULL;
 		free((char*)filter->attribute);
 		filter->attribute = NULL;
-		free(filter);
         free((char*)filter->filterStr);
         filter->filterStr = NULL;
+        free(filter);
 	}
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/framework/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/src/framework.c b/framework/src/framework.c
index b1db384..7d49254 100644
--- a/framework/src/framework.c
+++ b/framework/src/framework.c
@@ -1290,7 +1290,7 @@ celix_status_t fw_registerService(framework_pt framework, service_registration_p
                         info->context = lContext;
                         info->removed = false;
                     }
-                    subs = CELIX_DO_IF(subs, filter_getString(listener->filter, (const
char**)&info->filter));
+                    subs = CELIX_DO_IF(subs, filter_getString(listener->filter, &info->filter));
 
                     if (subs == CELIX_SUCCESS) {
                         arrayList_add(infos, info);
@@ -1408,7 +1408,6 @@ celix_status_t framework_ungetService(framework_pt framework, bundle_pt
bundle,
 
 void fw_addServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt
listener, const char* sfilter) {
 	array_list_pt listenerHooks = NULL;
-	listener_hook_info_pt info;
 	unsigned int i;
 
 	fw_service_listener_pt fwListener = (fw_service_listener_pt) calloc(1, sizeof(*fwListener));
@@ -1428,13 +1427,12 @@ void fw_addServiceListener(framework_pt framework, bundle_pt bundle,
service_lis
 
 	serviceRegistry_getListenerHooks(framework->registry, framework->bundle, &listenerHooks);
 
-	info = (listener_hook_info_pt) malloc(sizeof(*info));
+    struct listener_hook_info info;
 
 	bundle_getContext(bundle, &context);
-	info->context = context;
-
-	info->removed = false;
-	info->filter = sfilter == NULL ? NULL : strdup(sfilter);
+	info.context = context;
+	info.removed = false;
+	info.filter = sfilter;
 
 	for (i = 0; i < arrayList_size(listenerHooks); i++) {
 		service_reference_pt ref = (service_reference_pt) arrayList_get(listenerHooks, i);
@@ -1445,90 +1443,80 @@ void fw_addServiceListener(framework_pt framework, bundle_pt bundle,
service_lis
 		fw_getService(framework, framework->bundle, ref, (const void **) &hook);
 
 		arrayList_create(&infos);
-		arrayList_add(infos, info);
+		arrayList_add(infos, &info);
 		hook->added(hook->handle, infos);
 		serviceRegistry_ungetService(framework->registry, framework->bundle, ref, &ungetResult);
 		serviceRegistry_ungetServiceReference(framework->registry, framework->bundle, ref);
 		arrayList_destroy(infos);
 	}
 
-	if (info->filter != NULL) {
-	    free(info->filter);
-	}
-	free(info);
-
 	arrayList_destroy(listenerHooks);
 }
 
 void fw_removeServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt
listener) {
-	listener_hook_info_pt info = NULL;
-	unsigned int i;
-	fw_service_listener_pt element;
+	fw_service_listener_pt match = NULL;
 
 	bundle_context_pt context;
 	bundle_getContext(bundle, &context);
 
+    int i;
 	for (i = 0; i < arrayList_size(framework->serviceListeners); i++) {
-		element = (fw_service_listener_pt) arrayList_get(framework->serviceListeners, i);
-		if (element->listener == listener && element->bundle == bundle) {
-			bundle_context_pt lContext = NULL;
-
-			info = (listener_hook_info_pt) malloc(sizeof(*info));
-
-			bundle_getContext(element->bundle, &lContext);
-			info->context = lContext;
-
-			// TODO Filter toString;
-			filter_getString(element->filter, (const char**)&info->filter);
-			info->removed = true;
-
-			arrayList_remove(framework->serviceListeners, i);
-			i--;
-            
-            //unregistering retained service references. For these refs a unregister event
will not be triggered.
-            int k;
-            int rSize = arrayList_size(element->retainedReferences);
-            for (k = 0; k < rSize; k += 1) {
-                service_reference_pt ref = arrayList_get(element->retainedReferences,
k);
-                if (ref != NULL) {
-                    serviceRegistry_ungetServiceReference(framework->registry, element->bundle,
ref); // decrease retain counter                                       
-                } 
-            }
+        fw_service_listener_pt visit = (fw_service_listener_pt) arrayList_get(framework->serviceListeners,
i);
+        if (visit->listener == listener && visit->bundle == bundle) {
+            match = visit;
+            arrayList_remove(framework->serviceListeners, i);
+            break;
+        }
+    }
 
-			element->bundle = NULL;
-			filter_destroy(element->filter);
-            arrayList_destroy(element->retainedReferences);
-			element->filter = NULL;
-			element->listener = NULL;
-			free(element);
-			element = NULL;
-			break;
-		}
-	}
+    if (match != NULL) {
+        //invoke listener hooks
 
-	if (info != NULL) {
-		unsigned int i;
-		array_list_pt listenerHooks = NULL;
-		serviceRegistry_getListenerHooks(framework->registry, framework->bundle, &listenerHooks);
-
-		for (i = 0; i < arrayList_size(listenerHooks); i++) {
-			service_reference_pt ref = (service_reference_pt) arrayList_get(listenerHooks, i);
-			listener_hook_service_pt hook = NULL;
-			array_list_pt infos = NULL;
-			bool ungetResult;
-
-			fw_getService(framework, framework->bundle, ref, (const void **) &hook);
-
-			arrayList_create(&infos);
-			arrayList_add(infos, info);
-			hook->removed(hook->handle, infos);
-			serviceRegistry_ungetService(framework->registry, framework->bundle, ref, &ungetResult);
-			serviceRegistry_ungetServiceReference(framework->registry, framework->bundle, ref);
-			arrayList_destroy(infos);
-		}
+        bundle_context_pt lContext = NULL;
+
+        struct listener_hook_info info;
+        bundle_getContext(match->bundle, &lContext);
+        info.context = lContext;
+        filter_getString(match->filter, &info.filter);
+        info.removed = true;
 
-		arrayList_destroy(listenerHooks);
-        free(info);
+        array_list_pt listenerHooks = NULL;
+        serviceRegistry_getListenerHooks(framework->registry, framework->bundle, &listenerHooks);
+        for (i = 0; i < arrayList_size(listenerHooks); i++) {
+            service_reference_pt ref = (service_reference_pt) arrayList_get(listenerHooks,
i);
+            listener_hook_service_pt hook = NULL;
+            array_list_pt infos = NULL;
+            bool ungetResult;
+
+            fw_getService(framework, framework->bundle, ref, (const void **) &hook);
+
+            arrayList_create(&infos);
+            arrayList_add(infos, &info);
+            hook->removed(hook->handle, infos);
+            serviceRegistry_ungetService(framework->registry, framework->bundle, ref,
&ungetResult);
+            serviceRegistry_ungetServiceReference(framework->registry, framework->bundle,
ref);
+            arrayList_destroy(infos);
+        }
+        arrayList_destroy(listenerHooks);
+    }
+
+    if (match != NULL) {
+        //unregistering retained service references. For these refs a unregister event will
not be triggered.
+        int rSize = arrayList_size(match->retainedReferences);
+        for (i = 0; i < rSize; i += 1) {
+            service_reference_pt ref = arrayList_get(match->retainedReferences, i);
+            if (ref != NULL) {
+                serviceRegistry_ungetServiceReference(framework->registry, match->bundle,
ref); // decrease retain counter
+            }
+        }
+
+        match->bundle = NULL;
+        filter_destroy(match->filter);
+        arrayList_destroy(match->retainedReferences);
+        match->filter = NULL;
+        match->listener = NULL;
+        free(match);
+        match = NULL;
 	}
 }
 
@@ -1653,7 +1641,7 @@ void fw_serviceChanged(framework_pt framework, service_event_type_e
eventType, s
                 event = (service_event_pt) malloc(sizeof (*event));
 
                 serviceRegistry_getServiceReference(framework->registry, element->bundle,
registration, &reference);
-                
+
                 //NOTE: that you are never sure that the UNREGISTERED event will by handle
by an service_listener. listener could be gone
                 //Every reference retained is therefore stored and called when a service
listener is removed from the framework.
                 if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) {
@@ -1667,14 +1655,14 @@ void fw_serviceChanged(framework_pt framework, service_event_type_e
eventType, s
                 element->listener->serviceChanged(element->listener, event);
 
                 serviceRegistry_ungetServiceReference(framework->registry, element->bundle,
reference);
-                
+
                 if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) {
                     //if service listener was active when service was registered, release
the retained reference
                     if (arrayList_removeElement(element->retainedReferences, reference))
{
                         serviceRegistry_ungetServiceReference(framework->registry, element->bundle,
reference); // decrease retain counter
                     }
                 }
-                
+
                 free(event);
 
             } else if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED) {

http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/pubsub/pubsub_spi/include/pubsub_utils.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_utils.h b/pubsub/pubsub_spi/include/pubsub_utils.h
index aff5c72..eb961c9 100644
--- a/pubsub/pubsub_spi/include/pubsub_utils.h
+++ b/pubsub/pubsub_spi/include/pubsub_utils.h
@@ -30,10 +30,10 @@
 #include "bundle_context.h"
 #include "array_list.h"
 
-char* pubsub_getScopeFromFilter(char* bundle_filter);
-char* pubsub_getTopicFromFilter(char* bundle_filter);
+char* pubsub_getScopeFromFilter(const char* bundle_filter);
+char* pubsub_getTopicFromFilter(const char* bundle_filter);
 char* pubsub_getKeysBundleDir(bundle_context_pt ctx);
-array_list_pt pubsub_getTopicsFromString(char* string);
+array_list_pt pubsub_getTopicsFromString(const char* string);
 
 
 #endif /* PUBSUB_UTILS_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/pubsub/pubsub_spi/src/pubsub_utils.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_utils.c b/pubsub/pubsub_spi/src/pubsub_utils.c
index 19b2271..53bacb8 100644
--- a/pubsub/pubsub_spi/src/pubsub_utils.c
+++ b/pubsub/pubsub_spi/src/pubsub_utils.c
@@ -42,7 +42,7 @@
 
 #define MAX_KEYBUNDLE_LENGTH 256
 
-char* pubsub_getScopeFromFilter(char* bundle_filter){
+char* pubsub_getScopeFromFilter(const char* bundle_filter){
 
 	char* scope = NULL;
 
@@ -72,7 +72,7 @@ char* pubsub_getScopeFromFilter(char* bundle_filter){
 	return scope;
 }
 
-char* pubsub_getTopicFromFilter(char* bundle_filter){
+char* pubsub_getTopicFromFilter(const char* bundle_filter){
 
 	char* topic = NULL;
 
@@ -102,7 +102,7 @@ char* pubsub_getTopicFromFilter(char* bundle_filter){
 
 }
 
-array_list_pt pubsub_getTopicsFromString(char* string){
+array_list_pt pubsub_getTopicsFromString(const char* string){
 
 	array_list_pt topic_list = NULL;
 	arrayList_create(&topic_list);

http://git-wip-us.apache.org/repos/asf/celix/blob/33e96eb4/remote_services/topology_manager/src/topology_manager.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/src/topology_manager.c b/remote_services/topology_manager/src/topology_manager.c
index 6472b01..2126df5 100644
--- a/remote_services/topology_manager/src/topology_manager.c
+++ b/remote_services/topology_manager/src/topology_manager.c
@@ -866,7 +866,7 @@ celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_p
 	return status;
 }
 
-celix_status_t topologyManager_extendFilter(topology_manager_pt manager, char *filter, char
**updatedFilter) {
+static celix_status_t topologyManager_extendFilter(topology_manager_pt manager,  const char
*filter, char **updatedFilter) {
 	celix_status_t status;
 	bundle_context_pt context = manager->context;
 	const char* uuid = NULL;


Mime
View raw message