celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [18/21] celix git commit: CELIX-269: Fixed severial issues concering the dependency manager. Removed the need for cleanup from the dm activator, this will be done by the dm base activator.
Date Tue, 03 Nov 2015 11:09:55 GMT
CELIX-269: Fixed severial issues concering the dependency manager. Removed the need for cleanup
from the dm activator, this will be done by the dm base activator.


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

Branch: refs/heads/develop
Commit: 59c8e5d87134d94135ddc92e5dc5ea0f82b9cee6
Parents: e302c2d
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Mon Nov 2 14:07:07 2015 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Mon Nov 2 14:07:07 2015 +0100

----------------------------------------------------------------------
 dependency_manager/private/include/dm_event.h   |  2 +
 .../private/src/dm_activator_base.c             | 63 ++++++++------
 .../private/src/dm_component_impl.c             | 89 +++++---------------
 .../private/src/dm_dependency_manager_impl.c    | 28 +++---
 dependency_manager/private/src/dm_event.c       | 17 +++-
 .../private/src/dm_service_dependency.c         | 14 +--
 .../public/include/dm_dependency_manager.h      |  5 +-
 .../private/src/dependency_activator.c          |  9 --
 framework/private/src/service_reference.c       | 37 +++-----
 framework/private/src/utils.c                   | 15 ++++
 framework/public/include/utils.h                |  2 +
 11 files changed, 132 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/include/dm_event.h
----------------------------------------------------------------------
diff --git a/dependency_manager/private/include/dm_event.h b/dependency_manager/private/include/dm_event.h
index 8e23721..21f9831 100644
--- a/dependency_manager/private/include/dm_event.h
+++ b/dependency_manager/private/include/dm_event.h
@@ -42,6 +42,8 @@ typedef enum dm_event_type dm_event_type_e;
 
 struct dm_event {
 	void *service;
+	long serviceId;
+	long ranking;
 	service_reference_pt reference;
 	bundle_context_pt context;
 	bundle_pt bundle;

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index 25065a9..60a47ac 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -53,14 +53,22 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void
**userData
 		dm_create(context, &dependency_activator->userData);
 		dependency_activator->info = serv;
 
-		(*userData) = dependency_activator;;
-
-		status = CELIX_SUCCESS;
+        status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
 	} else {
-		free(dependency_activator);
-		free(serv);
+        status = CELIX_ENOMEM;
+
 	}
 
+    if (status == CELIX_SUCCESS) {
+        *userData = dependency_activator;
+    } else {
+        if (dependency_activator != NULL) {
+            dependencyManager_destroy(dependency_activator->manager);
+        }
+        free(dependency_activator);
+        free(serv);
+    }
+
 	return status;
 }
 
@@ -68,42 +76,47 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt
context)
 	celix_status_t status;
 	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
-	status = dependencyManager_create(dependency_activator->context, &dependency_activator->manager);
 
-	if (status == CELIX_SUCCESS) {
-		dm_init(dependency_activator->userData, context, dependency_activator->manager);
-	}
+    status = dm_init(dependency_activator->userData, context, dependency_activator->manager);
+
+    if (status == CELIX_SUCCESS) {
+        //Create the service
+        dependency_activator->info->handle = dependency_activator->manager;
+        dependency_activator->info->getInfo = (void *) dependencyManager_getInfo;
+        dependency_activator->info->destroyInfo = (void *) dependencyManager_destroyInfo;
 
-	//Create the service
-	dependency_activator->info->handle = dependency_activator->manager;
-	dependency_activator->info->getInfo = (void *)dependencyManager_getInfo;
-    dependency_activator->info->destroyInfo = (void *)dependencyManager_destroyInfo;
+        status = bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info,
NULL,
+                                               &(dependency_activator->reg));
+    }
 
-	bundleContext_registerService(context, DM_INFO_SERVICE_NAME, dependency_activator->info,
NULL, &(dependency_activator->reg));
 	return status;
 }
 
 celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context __attribute__((unused)))
{
 	celix_status_t status = CELIX_SUCCESS;
-	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
-
-	dm_destroy(dependency_activator->userData, dependency_activator->context, dependency_activator->manager);
+    dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
-	dependencyManager_destroy(&dependency_activator->manager);
+    // Remove the service
+    status = serviceRegistration_unregister(dependency_activator->reg);
+    depedencyManager_removeAllComponents(dependency_activator->manager);
 
-	// Remove the service
-	serviceRegistration_unregister(dependency_activator->reg);
-
-	dependency_activator->userData = NULL;
-	dependency_activator->manager = NULL;
-
-	return status;
+    return status;
 }
 
 celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context __attribute__((unused)))
{
 	celix_status_t status = CELIX_SUCCESS;
 	dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
 
+    status = dm_destroy(dependency_activator->userData, dependency_activator->context,
+                        dependency_activator->manager);
+
+    if (status == CELIX_SUCCESS) {
+        dependencyManager_destroy(dependency_activator->manager);
+    }
+
+	dependency_activator->userData = NULL;
+	dependency_activator->manager = NULL;
+
 	if (dependency_activator != NULL) {
 		free(dependency_activator->info);
 	}

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index a36e232..fb89b05 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -63,12 +63,11 @@ static celix_status_t executor_schedule(dm_executor_pt executor, dm_component_pt
 static celix_status_t executor_create(dm_component_pt component __attribute__((unused)),
dm_executor_pt *executor);
 static celix_status_t executor_destroy(dm_executor_pt *executor);
 
-static celix_status_t component_destroyComponent(dm_component_pt component);
 static celix_status_t component_invokeRemoveRequiredDependencies(dm_component_pt component);
 static celix_status_t component_invokeRemoveInstanceBoundDependencies(dm_component_pt component);
 static celix_status_t component_invokeRemoveOptionalDependencies(dm_component_pt component);
-static celix_status_t component_registerService(dm_component_pt component);
-static celix_status_t component_unregisterService(dm_component_pt component);
+static celix_status_t component_registerServices(dm_component_pt component);
+static celix_status_t component_unregisterServices(dm_component_pt component);
 static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
 static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt
component);
 static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
@@ -497,10 +496,10 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
         dm_event_pt old = arrayList_remove(events, (unsigned int) index);
         pthread_mutex_unlock(&component->mutex);
 
-        serviceDependency_invokeSet(dependency, event);
 
         switch (component->state) {
             case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
+                serviceDependency_invokeSet(dependency, event);
                 bool instanceBound = false;
                 serviceDependency_isInstanceBound(dependency, &instanceBound);
                 if (!instanceBound) {
@@ -516,6 +515,7 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
                 break;
             }
             case DM_CMP_STATE_TRACKING_OPTIONAL:
+                serviceDependency_invokeSet(dependency, event);
                 serviceDependency_invokeRemove(dependency, event);
                 dm_event_pt hevent = NULL;
                 component_getDependencyEvent(component, dependency, &hevent);
@@ -729,85 +729,48 @@ celix_status_t component_calculateNewState(dm_component_pt component,
dm_compone
 
 celix_status_t component_performTransition(dm_component_pt component, dm_component_state_t
oldState, dm_component_state_t newState, bool *transition) {
     celix_status_t status = CELIX_SUCCESS;
-    printf("performing transition from %i to %i\n", oldState, newState);
+    //printf("performing transition for %s in thread %i from %i to %i\n", component->name,
pthread_self(), oldState, newState);
 
-    if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED)
{
+    if (oldState == newState) {
+        *transition = false;
+    } else if (oldState == DM_CMP_STATE_INACTIVE && newState == DM_CMP_STATE_WAITING_FOR_REQUIRED)
{
         component_startDependencies(component, component->dependencies);
-//        #TODO Add listener support
-//        notifyListeners(newState);
         *transition = true;
-        return status;
-    }
-
-    if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED)
{
-        // #TODO Remove
-//        component_instantiateComponent(component);
+    } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED)
{
         component_invokeAddRequiredDependencies(component);
         component_invokeAutoConfigDependencies(component);
-        dm_component_state_t stateBeforeCallingInit = component->state;
         if (component->callbackInit) {
-        	component->callbackInit(component->implementation);
-        }
-        if (stateBeforeCallingInit == component->state) {
-//            #TODO Add listener support
-//            notifyListeners(newState); // init did not change current state, we can notify
about this new state
+        	status = component->callbackInit(component->implementation);
         }
         *transition = true;
-        return status;
-    }
-
-    if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState
== DM_CMP_STATE_TRACKING_OPTIONAL) {
+    } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED &&
newState == DM_CMP_STATE_TRACKING_OPTIONAL) {
         component_invokeAddRequiredInstanceBoundDependencies(component);
         component_invokeAutoConfigInstanceBoundDependencies(component);
         if (component->callbackStart) {
-        	component->callbackStart(component->implementation);
+        	status = component->callbackStart(component->implementation);
         }
         component_invokeAddOptionalDependencies(component);
-        component_registerService(component);
-//            #TODO Add listener support
-//        notifyListeners(newState);
-        return true;
-    }
-
-    if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED)
{
-        component_unregisterService(component);
+        component_registerServices(component);
+        *transition = true;
+    } else if (oldState == DM_CMP_STATE_TRACKING_OPTIONAL && newState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED)
{
+        component_unregisterServices(component);
         component_invokeRemoveOptionalDependencies(component);
         if (component->callbackStop) {
-        	component->callbackStop(component->implementation);
+        	status = component->callbackStop(component->implementation);
         }
         component_invokeRemoveInstanceBoundDependencies(component);
-//            #TODO Add listener support
-//        notifyListeners(newState);
         *transition = true;
-        return status;
-    }
-
-    if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState
== DM_CMP_STATE_WAITING_FOR_REQUIRED) {
+    } else if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED &&
newState == DM_CMP_STATE_WAITING_FOR_REQUIRED) {
     	if (component->callbackDeinit) {
-    		component->callbackDeinit(component->implementation);
+    		status = component->callbackDeinit(component->implementation);
     	}
         component_invokeRemoveRequiredDependencies(component);
-//            #TODO Add listener support
-//        notifyListeners(newState);
-//        bool needInstance = false;
-//        component_someDependenciesNeedInstance(component, &needInstance);
-//        if (!needInstance) {
-            component_destroyComponent(component);
-//        }
         *transition = true;
-        return status;
-    }
-
-    if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE)
{
+    } else if (oldState == DM_CMP_STATE_WAITING_FOR_REQUIRED && newState == DM_CMP_STATE_INACTIVE)
{
         component_stopDependencies(component);
-        component_destroyComponent(component);
-//            #TODO Add listener support
-//        notifyListeners(newState);
         *transition = true;
-        return status;
     }
 
-    *transition = false;
     return status;
 }
 
@@ -1117,15 +1080,7 @@ celix_status_t component_configureImplementation(dm_component_pt component,
dm_s
     return status;
 }
 
-celix_status_t component_destroyComponent(dm_component_pt component) {
-    celix_status_t status = CELIX_SUCCESS;
-
-//    component->implementation = NULL;
-
-    return status;
-}
-
-celix_status_t component_registerService(dm_component_pt component) {
+celix_status_t component_registerServices(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
     if (component->context) {
@@ -1141,7 +1096,7 @@ celix_status_t component_registerService(dm_component_pt component)
{
     return status;
 }
 
-celix_status_t component_unregisterService(dm_component_pt component) {
+celix_status_t component_unregisterServices(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;
 
     unsigned int i;

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_dependency_manager_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_dependency_manager_impl.c b/dependency_manager/private/src/dm_dependency_manager_impl.c
index 059ce54..7636121 100644
--- a/dependency_manager/private/src/dm_dependency_manager_impl.c
+++ b/dependency_manager/private/src/dm_dependency_manager_impl.c
@@ -50,15 +50,13 @@ celix_status_t dependencyManager_create(bundle_context_pt context __attribute__(
 
 }
 
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	arrayList_destroy((*manager)->components);
+void dependencyManager_destroy(dm_dependency_manager_pt manager) {
+	if (manager != NULL) {
+		//TODO destroy components
+		arrayList_destroy(manager->components);
 
-	free(*manager);
-	(*manager) = NULL;
-
-	return status;
+		free(manager);
+	}
 }
 
 celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component)
{
@@ -70,11 +68,19 @@ celix_status_t dependencyManager_add(dm_dependency_manager_pt manager,
dm_compon
 	return status;
 }
 
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt
component) {
+celix_status_t depedencyManager_removeAllComponents(dm_dependency_manager_pt manager) {
 	celix_status_t status;
 
-	arrayList_removeElement(manager->components, component);
-	status = component_stop(component);
+	while (!arrayList_isEmpty(manager->components)) {
+		dm_component_pt cmp = arrayList_remove(manager->components, 0);
+        printf("Removing comp %s\n", cmp->name);
+        status = component_stop(cmp);
+        //TODO component_destroy(&cmp);
+
+		if (status != CELIX_SUCCESS) {
+			break;
+		}
+	}
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_event.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_event.c b/dependency_manager/private/src/dm_event.c
index 60b7892..3fc7241 100644
--- a/dependency_manager/private/src/dm_event.c
+++ b/dependency_manager/private/src/dm_event.c
@@ -26,6 +26,8 @@
  */
 
 #include <stdlib.h>
+#include <constants.h>
+#include <utils.h>
 
 #include "dm_event.h"
 
@@ -37,12 +39,23 @@ celix_status_t event_create(dm_event_type_e event_type, bundle_pt bundle,
bundle
 		status = CELIX_ENOMEM;
 	}
 
+	char *serviceIdStr = NULL;
+	serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_ID, &serviceIdStr);
+	long servId = atol(serviceIdStr);
+
+	//FIXME service ranking can dynamicly change, but service reference can be removed at any
time.
+	char *rankingStr = NULL;
+	serviceReference_getProperty(reference, (char *)OSGI_FRAMEWORK_SERVICE_RANKING, &rankingStr);
+	long ranking = rankingStr == NULL ? 0 : atol(rankingStr);
+
 	if (status == CELIX_SUCCESS) {
 		(*event)->bundle = bundle;
 		(*event)->event_type = event_type;
 		(*event)->context = context;
 		(*event)->reference = reference;
 		(*event)->service = service;
+		(*event)->serviceId = servId;
+		(*event)->ranking = ranking;
 	}
 
 	return status;
@@ -72,7 +85,7 @@ celix_status_t event_equals(void *a, void *b, bool *equals) {
 		dm_event_pt a_ptr = a;
 		dm_event_pt b_ptr = b;
 
-		status = serviceReference_equals(a_ptr->reference, b_ptr->reference, equals);
+		*equals = a_ptr->serviceId == b_ptr->serviceId;
 	}
 
 	return status;
@@ -81,7 +94,7 @@ celix_status_t event_equals(void *a, void *b, bool *equals) {
 celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
 	celix_status_t status;
 
-	status = serviceReference_compareTo(event->reference, compareTo->reference, compare);
+	*compare = utils_compareServiceIdsAndRanking(event->serviceId, event->ranking, compareTo->serviceId,
compareTo->ranking);
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index e0bf489..b88f21d 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
+#include <assert.h>
 
 #include "constants.h"
 
@@ -273,6 +274,10 @@ celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency)
{
 	}
 
 	if (status == CELIX_SUCCESS) {
+		dependency->isStarted = false;
+	}
+
+	if (status == CELIX_SUCCESS) {
 		if (dependency->tracker) {
             tmp_status = serviceTracker_close(dependency->tracker);
             if (tmp_status != CELIX_SUCCESS) {
@@ -285,10 +290,6 @@ celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency)
{
 		}
 	}
 
-	if (status == CELIX_SUCCESS) {
-		dependency->isStarted = false;
-	}
-
 	return status;
 }
 
@@ -319,8 +320,10 @@ celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt
dependenc
 
 	return status;
 }
+
 celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency, dm_event_pt
event) {
 	celix_status_t status = CELIX_SUCCESS;
+	assert(dependency->isStarted == true);
 	array_list_pt serviceReferences = NULL;
 	int i;
 	int curRanking = INT_MIN;
@@ -329,7 +332,6 @@ celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency,
 
 	serviceReferences = serviceTracker_getServiceReferences(dependency->tracker);
 
-	fprintf(stderr,"found %d servicereferences\n",arrayList_size(serviceReferences));
 	/* Find the service with the higest ranking */
 	for (i = 0; i < arrayList_size(serviceReferences); i++) {
 		service_reference_pt serviceReference = arrayList_get(serviceReferences, i);
@@ -364,8 +366,6 @@ celix_status_t serviceDependency_invokeSet(dm_service_dependency_pt dependency,
 		service = NULL;
 	}
 
-	fprintf(stderr, "Ranking found: %d service %p\n", curRanking, service);
-
 	if (dependency->set) {
 		dependency->set(dependency->component->implementation, service);
 	}

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/dependency_manager/public/include/dm_dependency_manager.h
----------------------------------------------------------------------
diff --git a/dependency_manager/public/include/dm_dependency_manager.h b/dependency_manager/public/include/dm_dependency_manager.h
index 44c1643..22b0ad6 100644
--- a/dependency_manager/public/include/dm_dependency_manager.h
+++ b/dependency_manager/public/include/dm_dependency_manager.h
@@ -36,10 +36,11 @@
 typedef struct dm_dependency_manager *dm_dependency_manager_pt;
 
 celix_status_t dependencyManager_create(bundle_context_pt context, dm_dependency_manager_pt
*manager);
-celix_status_t dependencyManager_destroy(dm_dependency_manager_pt *manager);
+void dependencyManager_destroy(dm_dependency_manager_pt manager);
 
 celix_status_t dependencyManager_add(dm_dependency_manager_pt manager, dm_component_pt component);
-celix_status_t dependencyManager_remove(dm_dependency_manager_pt manager, dm_component_pt
component);
+
+celix_status_t depedencyManager_removeAllComponents(dm_dependency_manager_pt manager);
 
 /**
  * returns a dm_ of dm_dependency_manager_info. Caller has ownership.

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
----------------------------------------------------------------------
diff --git a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
index 2ce9bab..a5cf185 100644
--- a/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
+++ b/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
@@ -82,15 +82,6 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
 
 celix_status_t dm_destroy(void * userData, bundle_context_pt context, dm_dependency_manager_pt
manager) {
 	struct data * data = (struct data *) userData;
-	dependencyManager_remove(manager, data->service);
-
-	component_removeServiceDependency(data->service, data->dep);
-	serviceDependency_destroy(&data->dep);
-
-	component_removeServiceDependency(data->service, data->dep2);
-	serviceDependency_destroy(&data->dep2);
-
-	component_destroy(&data->service);
 
 	arrayList_destroy(data->publishers);
 	data->publishers = NULL;

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/private/src/service_reference.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_reference.c b/framework/private/src/service_reference.c
index 778877c..1f473ea 100644
--- a/framework/private/src/service_reference.c
+++ b/framework/private/src/service_reference.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <constants.h>
 #include <stdint.h>
+#include <utils.h>
 
 #include "service_reference.h"
 
@@ -170,32 +171,16 @@ celix_status_t serviceReference_compareTo(service_reference_pt reference,
servic
 	id = atol(id_str);
 	other_id = atol(other_id_str);
 
-	if (id == other_id) {
-		*compare = 0;
-	} else {
-		int rank, other_rank;
-		char *rank_str, *other_rank_str;
-		serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank_str);
-		serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &other_rank_str);
-
-		if (rank_str == NULL) {
-			rank_str = "0";
-		}
-		if (other_rank_str == NULL) {
-			other_rank_str = "0";
-		}
-
-		rank = atoi(rank_str);
-		other_rank = atoi(other_rank_str);
-
-		if (rank < other_rank) {
-			*compare = -1;
-		} else if (rank > other_rank) {
-			*compare = 1;
-		} else {
-			*compare = id < other_id ? 1 : -1;
-		}
-	}
+
+	long rank, other_rank;
+	char *rank_str, *other_rank_str;
+	serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &rank_str);
+	serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_RANKING, &other_rank_str);
+
+	rank = rank_str == NULL ? 0 : atol(rank_str);
+	other_rank = other_rank_str == NULL ? 0 : atol(other_rank_str);
+
+	utils_compareServiceIdsAndRanking(id, rank, other_id, other_rank);
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/private/src/utils.c
----------------------------------------------------------------------
diff --git a/framework/private/src/utils.c b/framework/private/src/utils.c
index f679c1d..862fba9 100644
--- a/framework/private/src/utils.c
+++ b/framework/private/src/utils.c
@@ -103,3 +103,18 @@ celix_status_t utils_isNumeric(char *number, bool *ret) {
 	}
 	return status;
 }
+
+
+FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long servId, long servRank, long otherServId,
long otherServRank) {
+	int result;
+
+	if (servId == otherServId) {
+		result = 0;
+	} else if (servRank != otherServRank) {
+		result = servRank < otherServRank ? -1 : 1;
+	} else { //equal service rank, compare service ids
+		result = servId < otherServId ? 1 : -1;
+	}
+
+	return result;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/59c8e5d8/framework/public/include/utils.h
----------------------------------------------------------------------
diff --git a/framework/public/include/utils.h b/framework/public/include/utils.h
index 090daec..19788d3 100644
--- a/framework/public/include/utils.h
+++ b/framework/public/include/utils.h
@@ -39,6 +39,8 @@ FRAMEWORK_EXPORT int utils_stringEquals(void * string, void * toCompare);
 FRAMEWORK_EXPORT char * string_ndup(const char *s, size_t n);
 FRAMEWORK_EXPORT char * utils_stringTrim(char * string);
 
+FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long servId, long servRank, long otherServId,
long otherServRank);
+
 FRAMEWORK_EXPORT celix_status_t thread_equalsSelf(celix_thread_t thread, bool *equals);
 
 FRAMEWORK_EXPORT celix_status_t utils_isNumeric(char *number, bool *ret);


Mime
View raw message