Return a proper order value for the default service
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 15 Jul 2009 07:54:43 +0000 (09:54 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 15 Jul 2009 07:54:43 +0000 (09:54 +0200)
src/connection.c
src/service.c

index b20a5a1..ac6c2e5 100644 (file)
@@ -243,8 +243,7 @@ static struct gateway_data *add_gateway(int index, const char *gateway)
                                                        find_element, data);
 
        service = __connman_element_get_service(data->element);
-       if (service != NULL)
-               data->order = __connman_service_get_order(service);
+       data->order = __connman_service_get_order(service);
 
        gateway_list = g_slist_append(gateway_list, data);
 
@@ -281,12 +280,16 @@ static void set_default_gateway(struct gateway_data *data)
 static struct gateway_data *find_default_gateway(void)
 {
        struct gateway_data *found = NULL;
+       unsigned int order = 0;
        GSList *list;
 
        for (list = gateway_list; list; list = list->next) {
                struct gateway_data *data = list->data;
-               /* just return the last one for now */
-               found = data;
+
+               if (found == NULL || data->order > order) {
+                       found = data;
+                       order = data->order;
+               }
        }
 
        return found;
@@ -640,7 +643,6 @@ static void update_order(void)
                struct connman_service *service;
 
                service = __connman_element_get_service(data->element);
-
                data->order = __connman_service_get_order(service);
        }
 }
index 786efd7..79e4cb0 100644 (file)
@@ -1333,9 +1333,20 @@ struct connman_service *__connman_service_lookup_from_network(struct connman_net
 
 unsigned int __connman_service_get_order(struct connman_service *service)
 {
+       GSequenceIter *iter;
+
        if (service == NULL)
                return 0;
 
+       if (service->favorite == FALSE)
+               return 0;
+
+       iter = g_hash_table_lookup(service_hash, service->identifier);
+       if (iter != NULL) {
+               if (g_sequence_iter_get_position(iter) == 0)
+                       return 1;
+       }
+
        return service->order;
 }