Connect service based on service type
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 1 Apr 2010 10:15:54 +0000 (12:15 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Sat, 3 Apr 2010 00:01:34 +0000 (02:01 +0200)
__connman_service_connect_type() tries to find the appropriate service
based on the service_type argument, and connect it. If the argument is
CONNMAN_SERVICE_TYPE_UNKNOWN, the first available service is picked.

src/connman.h
src/service.c

index af53a683809cdc8951534046d22ddae0aeba269d..af242509d3f9b903dcaade313fbcec80cc126744 100644 (file)
@@ -415,6 +415,7 @@ int __connman_service_connect(struct connman_service *service);
 int __connman_service_disconnect(struct connman_service *service);
 int __connman_service_create_and_connect(DBusMessage *msg);
 void __connman_service_auto_connect(void);
+struct connman_service *__connman_service_connect_type(enum connman_service_type type);
 
 const char *__connman_service_type2string(enum connman_service_type type);
 
index 38ee18ddcbe982796a7ceea662141f3fce0760f1..e0e363eb1ef9b09344ce5746b8e1958b83ae7a05 100644 (file)
@@ -999,6 +999,64 @@ static connman_bool_t get_reconnect_state(struct connman_service *service)
        return __connman_device_get_reconnect(device);
 }
 
+struct connman_service *
+__connman_service_connect_type(enum connman_service_type type)
+{
+       struct connman_service *service;
+       GSequenceIter *iter;
+       int err;
+
+       DBG("type %d", type);
+
+       /*
+        * We go through the already sorted service list.
+        * We pick the first one matching our type, or just
+        * the first available one if we have no type.
+        */
+       iter = g_sequence_get_begin_iter(service_list);
+       service = g_sequence_get(iter);
+
+       /*
+        * If the first service is connected or about to be
+        * connected, we return it, regardless of the type.
+        */
+       if ((g_sequence_iter_is_end(iter) == FALSE) &&
+               (is_connecting(service) == TRUE ||
+                       is_connected(service) == TRUE))
+               return service;
+
+       while (g_sequence_iter_is_end(iter) == FALSE) {
+               if (service->type == type ||
+                       type == CONNMAN_SERVICE_TYPE_UNKNOWN)
+                       break;
+
+               iter = g_sequence_iter_next(iter);
+               service = g_sequence_get(iter);
+       }
+
+       if (g_sequence_iter_is_end(iter))
+               return NULL;
+
+       service->ignore = FALSE;
+
+       service->userconnect = TRUE;
+
+       set_reconnect_state(service, FALSE);
+
+       err = __connman_service_connect(service);
+       if (err < 0) {
+               if (err == -ENOKEY)
+                       if (__connman_agent_request_passphrase(service,
+                                                               NULL, NULL))
+                               return service;
+
+               if (err != -EINPROGRESS)
+                       return NULL;
+       }
+
+       return service;
+}
+
 static DBusMessage *connect_service(DBusConnection *conn,
                                        DBusMessage *msg, void *user_data)
 {