gnome-session r5368 - in trunk: . gnome-session



Author: vuntz
Date: Wed Mar 25 16:58:55 2009
New Revision: 5368
URL: http://svn.gnome.org/viewvc/gnome-session?rev=5368&view=rev

Log:
2009-03-25  Vincent Untz  <vuntz gnome org>

	Remove the END_SESSION_LAST phase since it was considered to break the
	design. Instead, just use a second step in the END_SESSION phase.

	* gnome-session/gsm-manager.[ch]: (phase_num_to_name): remove
	END_SESSION_LAST phase
	(end_phase): always clean up next_query_clients, and remove
	END_SESSION_LAST phase.
	(on_phase_timeout): remove END_SESSION_LAST phase
	(_client_end_session): change the function signature so that we can
	merge this old function and _client_end_session_last
	(_client_end_session_last): killed
	(_client_end_session_helper): new, helper used for
	do_phase_end_session() since _client_end_session() cannot be directly
	used anymore
	(do_phase_end_session): use _client_end_session_helper(), and save
	session if there's nothing to do
	(do_phase_end_session_last): renamed to...
	(do_phase_end_session_part_2): ... this. Don't reset the phase timeout
	since we're still in the END_SESSION phase. Clean up next_query_clients
	after having used it.
	(start_phase): always clean up next_query_clients, remove
	END_SESSION_LAST phase
	(maybe_save_session): s/END_SESSION_LAST/END_SESSION/
	(on_client_end_session_response): only accept to end a client last if
	we're in END_SESSION. Start the second step of END_SESSION if there's
	no clients that haven't replied, no inhibitor and if there are clients
	to end last. Note that we don't remove the phase timeout here since it
	will either be needed in the second step or will be removed in
	end_phase().


Modified:
   trunk/ChangeLog
   trunk/gnome-session/gsm-manager.c
   trunk/gnome-session/gsm-manager.h

Modified: trunk/gnome-session/gsm-manager.c
==============================================================================
--- trunk/gnome-session/gsm-manager.c	(original)
+++ trunk/gnome-session/gsm-manager.c	Wed Mar 25 16:58:55 2009
@@ -99,9 +99,9 @@
         gboolean                forceful_logout;
         GSList                 *query_clients;
         guint                   query_timeout_id;
-        /* This is used for GSM_MANAGER_PHASE_END_SESSION_LAST only at the
-         * moment, since it uses a sublist of all running client that replied
-         * in a specific way */
+        /* This is used for GSM_MANAGER_PHASE_END_SESSION only at the moment,
+         * since it uses a sublist of all running client that replied in a
+         * specific way */
         GSList                 *next_query_clients;
 
         GtkWidget              *inhibit_dialog;
@@ -350,9 +350,6 @@
         case GSM_MANAGER_PHASE_END_SESSION:
                 name = "END_SESSION";
                 break;
-        case GSM_MANAGER_PHASE_END_SESSION_LAST:
-                name = "END_SESSION_LAST";
-                break;
         case GSM_MANAGER_PHASE_EXIT:
                 name = "EXIT";
                 break;
@@ -378,10 +375,8 @@
         g_slist_free (manager->priv->query_clients);
         manager->priv->query_clients = NULL;
 
-        if (manager->priv->phase < GSM_MANAGER_PHASE_QUERY_END_SESSION) {
-                g_slist_free (manager->priv->next_query_clients);
-                manager->priv->next_query_clients = NULL;
-        }
+        g_slist_free (manager->priv->next_query_clients);
+        manager->priv->next_query_clients = NULL;
 
         if (manager->priv->phase_timeout_id > 0) {
                 g_source_remove (manager->priv->phase_timeout_id);
@@ -398,7 +393,6 @@
         case GSM_MANAGER_PHASE_RUNNING:
         case GSM_MANAGER_PHASE_QUERY_END_SESSION:
         case GSM_MANAGER_PHASE_END_SESSION:
-        case GSM_MANAGER_PHASE_END_SESSION_LAST:
                 manager->priv->phase++;
                 start_phase (manager);
                 break;
@@ -453,7 +447,6 @@
                 break;
         case GSM_MANAGER_PHASE_QUERY_END_SESSION:
         case GSM_MANAGER_PHASE_END_SESSION:
-        case GSM_MANAGER_PHASE_END_SESSION_LAST:
                 break;
         case GSM_MANAGER_PHASE_EXIT:
                 break;
@@ -545,8 +538,7 @@
 
 
 static gboolean
-_client_end_session (const char           *id,
-                     GsmClient            *client,
+_client_end_session (GsmClient            *client,
                      ClientEndSessionData *data)
 {
         gboolean ret;
@@ -567,6 +559,14 @@
         return FALSE;
 }
 
+static gboolean
+_client_end_session_helper (const char           *id,
+                            GsmClient            *client,
+                            ClientEndSessionData *data)
+{
+        return _client_end_session (client, data);
+}
+
 static void
 do_phase_end_session (GsmManager *manager)
 {
@@ -593,37 +593,19 @@
                                                                          manager);
 
                 gsm_store_foreach (manager->priv->clients,
-                                   (GsmStoreFunc)_client_end_session,
+                                   (GsmStoreFunc)_client_end_session_helper,
                                    &data);
         } else {
-                end_phase (manager);
-        }
-}
-
-static gboolean
-_client_end_session_last (GsmClient            *client,
-                          ClientEndSessionData *data)
-{
-        gboolean ret;
-        GError  *error;
+                if (data.flags & GSM_CLIENT_END_SESSION_FLAG_SAVE) {
+                        maybe_save_session (manager);
+                }
 
-        error = NULL;
-        ret = gsm_client_end_session (client, data->flags, &error);
-        if (! ret) {
-                g_warning ("Unable to query client: %s", error->message);
-                g_error_free (error);
-                /* FIXME: what should we do if we can't communicate with client? */
-        } else {
-                g_debug ("GsmManager: adding client to end-session-last clients: %s", gsm_client_peek_id (client));
-                data->manager->priv->query_clients = g_slist_prepend (data->manager->priv->query_clients,
-                                                                      client);
+                end_phase (manager);
         }
-
-        return FALSE;
 }
 
 static void
-do_phase_end_session_last (GsmManager *manager)
+do_phase_end_session_part_2 (GsmManager *manager)
 {
         ClientEndSessionData data;
 
@@ -638,19 +620,16 @@
         }
         data.flags |= GSM_CLIENT_END_SESSION_FLAG_LAST;
 
-        if (manager->priv->phase_timeout_id > 0) {
-                g_source_remove (manager->priv->phase_timeout_id);
-                manager->priv->phase_timeout_id = 0;
-        }
+        /* keep the timeout that was started at the beginning of the
+         * GSM_MANAGER_PHASE_END_SESSION phase */
 
         if (g_slist_length (manager->priv->next_query_clients) > 0) {
-                manager->priv->phase_timeout_id = g_timeout_add_seconds (10,
-                                                                         (GSourceFunc)on_phase_timeout,
-                                                                         manager);
-
                 g_slist_foreach (manager->priv->next_query_clients,
-                                 (GFunc)_client_end_session_last,
+                                 (GFunc)_client_end_session,
                                  &data);
+
+                g_slist_free (manager->priv->next_query_clients);
+                manager->priv->next_query_clients = NULL;
         } else {
                 if (data.flags & GSM_CLIENT_END_SESSION_FLAG_SAVE) {
                         maybe_save_session (manager);
@@ -1159,10 +1138,8 @@
         manager->priv->pending_apps = NULL;
         g_slist_free (manager->priv->query_clients);
         manager->priv->query_clients = NULL;
-        if (manager->priv->phase < GSM_MANAGER_PHASE_END_SESSION) {
-                g_slist_free (manager->priv->next_query_clients);
-                manager->priv->next_query_clients = NULL;
-        }
+        g_slist_free (manager->priv->next_query_clients);
+        manager->priv->next_query_clients = NULL;
 
         if (manager->priv->query_timeout_id > 0) {
                 g_source_remove (manager->priv->query_timeout_id);
@@ -1192,9 +1169,6 @@
         case GSM_MANAGER_PHASE_END_SESSION:
                 do_phase_end_session (manager);
                 break;
-        case GSM_MANAGER_PHASE_END_SESSION_LAST:
-                do_phase_end_session_last (manager);
-                break;
         case GSM_MANAGER_PHASE_EXIT:
                 do_phase_exit (manager);
                 break;
@@ -1727,7 +1701,7 @@
         /* We only allow session saving when session is running or when
          * logging out */
         if (manager->priv->phase != GSM_MANAGER_PHASE_RUNNING &&
-            manager->priv->phase != GSM_MANAGER_PHASE_END_SESSION_LAST) {
+            manager->priv->phase != GSM_MANAGER_PHASE_END_SESSION) {
                 goto out;
         }
 
@@ -1804,18 +1778,26 @@
                                           (gpointer)gsm_client_peek_id (client));
         }
 
-        if (do_last) {
-                manager->priv->next_query_clients =  g_slist_prepend (manager->priv->next_query_clients,
-                                                                      client);
+        if (do_last && manager->priv->phase == GSM_MANAGER_PHASE_END_SESSION) {
+                /* This only makes sense if we're in part 1 of
+                 * GSM_MANAGER_PHASE_END_SESSION. Doing this in part 2 can only
+                 * happen because of a buggy client that loops wanting to be
+                 * last again and again. The phase timeout will take care of
+                 * this issue. */
+                manager->priv->next_query_clients = g_slist_prepend (manager->priv->next_query_clients,
+                                                                     client);
         }
 
-        if (manager->priv->query_clients == NULL
-            && gsm_store_size (manager->priv->inhibitors) == 0) {
-                if (manager->priv->query_timeout_id > 0) {
-                        g_source_remove (manager->priv->query_timeout_id);
-                        manager->priv->query_timeout_id = 0;
-                }
+        /* we can continue to the next step if all clients have replied and
+         * if there's no inhibitor */
+        if (manager->priv->query_clients != NULL
+            || gsm_store_size (manager->priv->inhibitors) != 0) {
+                return;
+        }
 
+        if (manager->priv->next_query_clients != NULL) {
+                do_phase_end_session_part_2 (manager);
+        } else {
                 if (auto_save_is_enabled (manager)) {
                         maybe_save_session (manager);
                 }

Modified: trunk/gnome-session/gsm-manager.h
==============================================================================
--- trunk/gnome-session/gsm-manager.h	(original)
+++ trunk/gnome-session/gsm-manager.h	Wed Mar 25 16:58:55 2009
@@ -83,7 +83,6 @@
         /* shutting down */
         GSM_MANAGER_PHASE_QUERY_END_SESSION,
         GSM_MANAGER_PHASE_END_SESSION,
-        GSM_MANAGER_PHASE_END_SESSION_LAST, /* for apps that want to be done after all other apps */
         GSM_MANAGER_PHASE_EXIT
 } GsmManagerPhase;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]