celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1667604 - in /celix/trunk/framework: private/src/service_reference.c public/include/service_reference.h
Date Wed, 18 Mar 2015 19:33:20 GMT
Author: abroekhuis
Date: Wed Mar 18 19:33:19 2015
New Revision: 1667604

URL: http://svn.apache.org/r1667604
Log:
Added compareTo function to service_reference

Modified:
    celix/trunk/framework/private/src/service_reference.c
    celix/trunk/framework/public/include/service_reference.h

Modified: celix/trunk/framework/private/src/service_reference.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/service_reference.c?rev=1667604&r1=1667603&r2=1667604&view=diff
==============================================================================
--- celix/trunk/framework/private/src/service_reference.c (original)
+++ celix/trunk/framework/private/src/service_reference.c Wed Mar 18 19:33:19 2015
@@ -25,6 +25,7 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <constants.h>
 
 #include "service_reference.h"
 
@@ -157,6 +158,47 @@ int serviceReference_equals2(void *refer
 	return equal;
 }
 
+celix_status_t serviceReference_compareTo(service_reference_pt reference, service_reference_pt
compareTo, int *compare) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	long id, other_id;
+	char *id_str, *other_id_str;
+	serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &id_str);
+	serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_SERVICE_ID, &other_id_str);
+
+	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;
+		}
+	}
+
+	return status;
+}
+
 unsigned int serviceReference_hashCode(void *referenceP) {
 	service_reference_pt reference = referenceP;
 	int prime = 31;

Modified: celix/trunk/framework/public/include/service_reference.h
URL: http://svn.apache.org/viewvc/celix/trunk/framework/public/include/service_reference.h?rev=1667604&r1=1667603&r2=1667604&view=diff
==============================================================================
--- celix/trunk/framework/public/include/service_reference.h (original)
+++ celix/trunk/framework/public/include/service_reference.h Wed Mar 18 19:33:19 2015
@@ -47,5 +47,6 @@ FRAMEWORK_EXPORT celix_status_t serviceR
 FRAMEWORK_EXPORT celix_status_t serviceReference_equals(service_reference_pt reference, service_reference_pt
compareTo, bool *equal);
 FRAMEWORK_EXPORT unsigned int serviceReference_hashCode(void *referenceP);
 FRAMEWORK_EXPORT int serviceReference_equals2(void *reference1, void *reference2);
+FRAMEWORK_EXPORT celix_status_t serviceReference_compareTo(service_reference_pt reference,
service_reference_pt compareTo, int *compare);
 
 #endif /* SERVICE_REFERENCE_H_ */



Mime
View raw message