service: Prefer online state over ready when comparing services
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Wed, 24 Aug 2011 08:36:41 +0000 (11:36 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 24 Aug 2011 09:46:32 +0000 (11:46 +0200)
src/service.c

index 0380dbe..4ab3750 100644 (file)
@@ -3297,9 +3297,21 @@ static gint service_compare(gconstpointer a, gconstpointer b,
        state_b = service_b->state;
 
        if (state_a != state_b) {
-               if (is_connected(service_a) == TRUE)
+               gboolean a_connected = is_connected(service_a);
+               gboolean b_connected = is_connected(service_b);
+
+               if (a_connected == TRUE && b_connected == TRUE) {
+                       /* We prefer online over ready state */
+                       if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
+                               return -1;
+
+                       if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
+                               return 1;
+               }
+
+               if (a_connected == TRUE)
                        return -1;
-               if (is_connected(service_b) == TRUE)
+               if (b_connected == TRUE)
                        return 1;
 
                if (is_connecting(service_a) == TRUE)