[gnome-boxes] Wait until all machines are suspended



commit 524265e4132711ca7965bed9472b22103720ceec
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Fri Sep 7 17:45:24 2012 +0200

    Wait until all machines are suspended
    
    We need to wait until all suspend() calls are finished to be sure
    that the call went through. We shouldn't hold the app though, so
    it needs to be done in a seperate loop when the program exits.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683473

 src/app.vala |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 6054115..216f6a9 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -154,6 +154,15 @@ private class Boxes.App: Boxes.UI {
         application.activate.connect_after ((app) => {
             window.present ();
         });
+        application.shutdown.connect (() => {
+            MainLoop loop = new MainLoop ();
+            Idle.add (() => {
+                suspend_machines.begin (() => { loop.quit (); });
+                return false;
+                });
+            loop.run ();
+        });
+
     }
 
     public int run () {
@@ -564,19 +573,29 @@ private class Boxes.App: Boxes.UI {
         }
     }
 
-    public bool quit () {
-        notificationbar.cancel ();
-        save_window_geometry ();
-        window.hide ();
-
+    private async void suspend_machines () {
+        var waiting_counter = 0;
+        debug ("Suspending running boxes");
         foreach (var item in collection.items.data)
             if (item is LibvirtMachine) {
                 var machine = item as LibvirtMachine;
 
-                if (machine.connection == default_connection)
-                    machine.suspend.begin ();
+                if (machine.connection == default_connection) {
+                    waiting_counter++;
+                    machine.suspend.begin (() => { suspend_machines.callback (); });
+                }
             }
 
+        while (waiting_counter > 0) {
+            yield;
+            waiting_counter--;
+        }
+        debug ("Running boxes suspended");
+    }
+
+    public bool quit () {
+        notificationbar.cancel ();
+        save_window_geometry ();
         wizard.cleanup ();
         window.destroy ();
 



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