[PATCH 1/3] service: Update service list sorting

Patrik Flykt patrik.flykt at linux.intel.com
Wed Sep 25 05:24:36 PDT 2013


Update service list sorting to follow more closely the description in
doc/overview.txt. Services are now properly sorted as ethernet,
bluetooth, cellular, wifi and VPN. If the strengths are equal, sorting
is done according to service name. Using order for sorting before
favorite has been removed.
---
 src/service.c |   48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/service.c b/src/service.c
index 4ec425c..f8ad812 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4537,6 +4537,7 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 	struct connman_service *service_a = (void *) a;
 	struct connman_service *service_b = (void *) b;
 	enum connman_service_state state_a, state_b;
+	gint strength;
 
 	state_a = service_a->state;
 	state_b = service_b->state;
@@ -4571,12 +4572,6 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 			return 1;
 	}
 
-	if (service_a->order > service_b->order)
-		return -1;
-
-	if (service_a->order < service_b->order)
-		return 1;
-
 	if (service_a->favorite && !service_b->favorite)
 		return -1;
 
@@ -4584,23 +4579,38 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 		return 1;
 
 	if (service_a->type != service_b->type) {
-		switch (service_a->type) {
-		case CONNMAN_SERVICE_TYPE_UNKNOWN:
-		case CONNMAN_SERVICE_TYPE_SYSTEM:
-		case CONNMAN_SERVICE_TYPE_ETHERNET:
-		case CONNMAN_SERVICE_TYPE_GPS:
-		case CONNMAN_SERVICE_TYPE_VPN:
-		case CONNMAN_SERVICE_TYPE_GADGET:
-			break;
-		case CONNMAN_SERVICE_TYPE_WIFI:
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
 			return 1;
-		case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-		case CONNMAN_SERVICE_TYPE_CELLULAR:
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
 			return -1;
-		}
+		if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
+			return 1;
 	}
 
-	return (gint) service_b->strength - (gint) service_a->strength;
+	strength = (gint) service_b->strength - (gint) service_a->strength;
+	if (strength)
+		return strength;
+
+	return g_strcmp0(service_a->name, service_b->name);
 }
 
 /**
-- 
1.7.10.4




More information about the connman mailing list