session: Fix Session.Connect()/Disconnect()
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Fri, 8 Apr 2011 08:22:01 +0000 (10:22 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Fri, 8 Apr 2011 14:53:25 +0000 (16:53 +0200)
Instead of using __connman_service_session_connect() for connecting
session.c uses __connman_service_connect() directly
(__connman_service_disconnect accordingly). Those two calls are using
their own glib callback source and can update the session state
accoring the return value from __connman_service_connect()/disconnect().

src/connman.h
src/service.c
src/session.c

index fa28ead5836779bbbf0442d62a44143ba0f4723c..55b512ba1fefe102a6e7115eb27af89ca0ce6ce5 100644 (file)
@@ -517,8 +517,6 @@ int __connman_service_disconnect(struct connman_service *service);
 int __connman_service_disconnect_all(void);
 int __connman_service_create_and_connect(DBusMessage *msg);
 void __connman_service_auto_connect(void);
-int __connman_service_session_connect(GSequence *service_list,
-                                       struct connman_service **service);
 
 const char *__connman_service_type2string(enum connman_service_type type);
 
index 20352bffcf51fd1fa74866a1ef23c27ce22f2b1d..dcbe0bad1cf47d324a278adb25a1c4a6fc4419d8 100644 (file)
@@ -2598,57 +2598,6 @@ void __connman_service_auto_connect(void)
        }
 }
 
-static connman_bool_t session_is_ignore(struct connman_service *service)
-{
-       if (combine_state(service->state_ipv4, service->state_ipv6) ==
-                                               CONNMAN_SERVICE_STATE_FAILURE)
-               return TRUE;
-
-       return FALSE;
-}
-
-int __connman_service_session_connect(GSequence *list,
-                                       struct connman_service **ret_service)
-{
-       struct connman_service *service;
-       GSequenceIter *iter;
-
-       DBG("list %p", list);
-
-       iter = g_sequence_get_begin_iter(list);
-
-       while (g_sequence_iter_is_end(iter) == FALSE) {
-               service = g_sequence_get(iter);
-
-               if (service->pending != NULL)
-                       return -EINPROGRESS;
-
-               if (is_connected(service) == TRUE)
-                       return -EISCONN;
-
-               if (is_connecting(service) == TRUE)
-                       return -EALREADY;
-
-               if (session_is_ignore(service) == FALSE &&
-                       combine_state(service->state_ipv4,
-                                       service->state_ipv6) ==
-                                               CONNMAN_SERVICE_STATE_IDLE)
-                       break;
-
-               service = NULL;
-
-               iter = g_sequence_iter_next(iter);
-       }
-
-       if (service == NULL)
-               return -EINVAL;
-
-
-       *ret_service = service;
-
-       return __connman_service_connect(service);
-}
-
 static void remove_timeout(struct connman_service *service)
 {
        if (service->timeout > 0) {
index 2b29a1e5a6b9d7dc19e8590d4c8c16b927e6b450..6ebd141c8ecd09146a9d880f8a08a14ecf66dd74 100644 (file)
@@ -588,11 +588,23 @@ static DBusMessage *destroy_session(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static gboolean session_do_connect(gpointer user_data)
+{
+       struct connman_session *session = user_data;
+
+       __connman_service_connect(session->service);
+
+       service_changed(session);
+       return FALSE;
+}
+
 static DBusMessage *connect_session(DBusConnection *conn,
                                        DBusMessage *msg, void *user_data)
 {
        struct connman_session *session = user_data;
-       int err;
+       struct connman_service *service = NULL;
+       GSourceFunc callback;
+       GSequenceIter *iter;
 
        DBG("session %p", session);
 
@@ -604,35 +616,60 @@ static DBusMessage *connect_session(DBusConnection *conn,
 
        g_sequence_foreach(session->service_list, print_name, NULL);
 
-       err = __connman_service_session_connect(session->service_list,
-                                               &session->service);
-       if (err < 0)
-               return __connman_error_failed(msg, -err);
 
-       update_service(session);
-       g_timeout_add_seconds(0, service_changed, session);
+       iter = g_sequence_get_begin_iter(session->service_list);
+
+       while (g_sequence_iter_is_end(iter) == FALSE) {
+               service = g_sequence_get(iter);
+
+               if (__connman_service_is_connecting(service) == TRUE ||
+                               __connman_service_is_connected(service) == TRUE) {
+                       callback = service_changed;
+                       break;
+               }
+
+               if (__connman_service_is_idle(service) == TRUE) {
+                       callback = session_do_connect;
+                       break;
+               }
+
+               iter = g_sequence_iter_next(iter);
+       }
+
+       if (session != NULL) {
+               session->service = service;
+               update_service(session);
+               g_timeout_add_seconds(0, callback, session);
+       }
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static gboolean session_do_disconnect(gpointer user_data)
+{
+       struct connman_session *session = user_data;
+
+       if (__connman_service_disconnect(session->service) < 0)
+               return FALSE;
+
+       session->service = NULL;
+       update_service(session);
+       service_changed(session);
+
+       return FALSE;
+}
+
 static DBusMessage *disconnect_session(DBusConnection *conn,
                                        DBusMessage *msg, void *user_data)
 {
        struct connman_session *session = user_data;
-       int err;
 
        DBG("session %p", session);
 
        if (session->service == NULL)
                return __connman_error_already_disabled(msg);
 
-       err = __connman_service_disconnect(session->service);
-       if (err < 0)
-               return __connman_error_failed(msg, -err);
-
-       session->service = NULL;
-       update_service(session);
-       g_timeout_add_seconds(0, service_changed, session);
+       g_timeout_add_seconds(0, session_do_disconnect, session);
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }