From: Daniel Wagner Date: Fri, 8 Apr 2011 08:22:01 +0000 (+0200) Subject: session: Fix Session.Connect()/Disconnect() X-Git-Tag: 0.73~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b40e04e2f1ee1ca30b1a2d91dfea286c78480dd;p=platform%2Fupstream%2Fconnman.git session: Fix Session.Connect()/Disconnect() 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(). --- diff --git a/src/connman.h b/src/connman.h index fa28ead5..55b512ba 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/service.c b/src/service.c index 20352bff..dcbe0bad 100644 --- a/src/service.c +++ b/src/service.c @@ -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) { diff --git a/src/session.c b/src/session.c index 2b29a1e5..6ebd141c 100644 --- a/src/session.c +++ b/src/session.c @@ -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); }