session: Call update_info() if service changes
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 28 Apr 2011 16:05:06 +0000 (18:05 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 2 May 2011 16:17:34 +0000 (18:17 +0200)
Instead of trying to figure out when to call update_info() at various
places, just call update_info() at the end of session_changed when the
selected service has been changed.

Another noteworthy change is the remove of g_timeout_add_seconds(...,
session_notify(), ...). It was introduced to 'fix' a problem where
sometimes the notification message was not send. The source of this
problem seemed to be that session_notify() couldn't be called if the
current context was called from a incoming D-Bus call
(e.g. Session.Connect()). Though without g_timeout_add_seconds it
still works now. So it's properly better to remove it again since it's
seems not necessary.

src/session.c

index 6b5192b..8dab52c 100644 (file)
@@ -732,18 +732,6 @@ static void update_info(struct session_info *info)
        }
 }
 
-static void notify_service_changes(struct connman_session *session)
-{
-       struct session_info *info = &session->info;
-       struct session_info *info_last = &session->info_last;
-
-       if (info->service == info_last->service)
-               return;
-
-       update_info(info);
-       session->info_dirty = TRUE;
-}
-
 static void select_and_connect(struct connman_session *session,
                                connman_bool_t do_connect)
 {
@@ -784,14 +772,13 @@ static void select_and_connect(struct connman_session *session,
                if (do_connect == TRUE)
                        __connman_service_connect(info->service);
        }
-
-       notify_service_changes(session);
 }
 
 static void session_changed(struct connman_session *session,
                                enum connman_session_trigger trigger)
 {
        struct session_info *info = &session->info;
+       struct session_info *info_last = &session->info_last;
        GSequenceIter *iter;
 
        /*
@@ -817,8 +804,6 @@ static void session_changed(struct connman_session *session,
                                __connman_service_disconnect(info->service);
                                info->service = NULL;
                        }
-
-                       notify_service_changes(session);
                }
 
                /* Try to free ride */
@@ -841,7 +826,6 @@ static void session_changed(struct connman_session *session,
                        __connman_service_disconnect(info->service);
 
                info->service = NULL;
-               notify_service_changes(session);
 
                break;
        case CONNMAN_SESSION_TRIGGER_PERIODIC:
@@ -867,25 +851,15 @@ static void session_changed(struct connman_session *session,
                if (info->online == FALSE && info->service != NULL)
                        info->service = NULL;
 
-               notify_service_changes(session);
-
                break;
        }
 
-       switch (trigger) {
-       case CONNMAN_SESSION_TRIGGER_UNKNOWN:
-               break;
-       case CONNMAN_SESSION_TRIGGER_CONNECT:
-       case CONNMAN_SESSION_TRIGGER_DISCONNECT:
-       case CONNMAN_SESSION_TRIGGER_ECALL:
-               g_timeout_add_seconds(0, session_notify, session);
-               break;
-       case CONNMAN_SESSION_TRIGGER_SETTING:
-       case CONNMAN_SESSION_TRIGGER_PERIODIC:
-       case CONNMAN_SESSION_TRIGGER_SERVICE:
-               session_notify(session);
-               break;
+       if (info->service != info_last->service) {
+               update_info(info);
+               session->info_dirty = TRUE;
        }
+
+       session_notify(session);
 }
 
 static DBusMessage *connect_session(DBusConnection *conn,