From: Patrik Flykt <patrik.fl...@linux.intel.com>

Look up services from the service list according to their types
using the entries in the 'PreferredTechnologies' string array.
Return the newly allocated service sequence to the caller.
---
 src/service.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/service.c b/src/service.c
index 5dd998a..5b502a4 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2911,6 +2911,51 @@ static connman_bool_t is_ignore(struct connman_service 
*service)
        return FALSE;
 }
 
+struct preferred_tech_data {
+       GSequence *preferred_list;
+       enum connman_service_type type;
+};
+
+static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
+{
+       struct connman_service *service = data;
+       struct preferred_tech_data *tech_data = user_data;
+
+       if (service->type == tech_data->type) {
+               g_sequence_append(tech_data->preferred_list, service);
+
+               DBG("type %d service %p %s", tech_data->type, service,
+                               service->name);
+       }
+}
+
+static GSequence* preferred_tech_list_get(GSequence *list)
+{
+       char **tech_array;
+       struct preferred_tech_data tech_data;
+       int i;
+
+       tech_array = connman_setting_get_string_list("PreferredTechnologies");
+       if (tech_array == NULL)
+               return NULL;
+
+       tech_data.preferred_list = g_sequence_new(NULL);
+
+       for (i = 0; tech_array[i] != NULL; i += 1) {
+               tech_data.type = __connman_service_string2type(tech_array[i]);
+
+               DBG("type %d %s", tech_data.type, tech_array[i]);
+
+               if (tech_data.type == CONNMAN_SERVICE_TYPE_UNKNOWN)
+                       continue;
+
+               g_sequence_foreach(service_list, preferred_tech_add_by_type,
+                               &tech_data);
+       }
+
+       return tech_data.preferred_list;
+}
+
 void __connman_service_auto_connect(void)
 {
        struct connman_service *service = NULL;
-- 
1.7.9.1

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to