[gnome-boxes] Machine provides API for restarting



commit d9556fe9453f067cf178c9e797931afc063e6435
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Feb 11 13:25:09 2014 +0000

    Machine provides API for restarting
    
    Currently this is only actually implemented by LibvirtMachine as its the
    only machine that needs to be restarted if user changes some of its
    properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710300

 src/libvirt-machine-properties.vala |   68 +----------------------------------
 src/libvirt-machine.vala            |   65 +++++++++++++++++++++++++++++++++
 src/machine.vala                    |    1 +
 src/ovirt-machine.vala              |    2 +
 src/remote-machine.vala             |    4 ++
 5 files changed, 73 insertions(+), 67 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index f950313..7e20d81 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -6,7 +6,6 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
     private const uint64 MEGABYTES = 1000 * 1000;
 
     private weak LibvirtMachine machine; // Weak ref for avoiding cyclic ref */
-    private uint shutdown_timeout;
 
     public LibvirtMachineProperties (LibvirtMachine machine) {
         this.machine = machine;
@@ -462,72 +461,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             return;
 
         var message = _("Changes require restart of '%s'. Attempt restart?").printf (machine.name);
-        App.app.notificationbar.display_for_action (message, _("_Yes"), reboot);
-    }
-
-    private void reboot () {
-        if (machine.state == Machine.MachineState.SAVED) {
-            debug ("'%s' is in saved state. Resuming it..", machine.name);
-            machine.start.begin (Machine.ConnectFlags.NONE, null, (obj, res) => {
-                try {
-                    machine.start.end (res);
-                    reboot ();
-                } catch (GLib.Error error) {
-                    warning ("Failed to start '%s': %s", machine.domain.get_name (), error.message);
-                }
-            });
-
-            return;
-        }
-
-        machine.stay_on_display = true;
-        ulong state_id = 0;
-        Gd.Notification notification = null;
-        debug ("Rebooting '%s'..", machine.name);
-
-        state_id = machine.notify["state"].connect (() => {
-            if (machine.state == Machine.MachineState.STOPPED ||
-                machine.state == Machine.MachineState.FORCE_STOPPED) {
-                debug ("'%s' stopped.", machine.name);
-                machine.start.begin (Machine.ConnectFlags.NONE, null, (obj, res) => {
-                    try {
-                        machine.start.end (res);
-                    } catch (GLib.Error error) {
-                        warning ("Failed to start '%s': %s", machine.domain.get_name (), error.message);
-                    }
-                });
-
-                machine.disconnect (state_id);
-                if (shutdown_timeout != 0) {
-                    Source.remove (shutdown_timeout);
-                    shutdown_timeout = 0;
-                }
-                if (notification != null) {
-                    notification.dismiss ();
-                    notification = null;
-                }
-            }
-        });
-
-        shutdown_timeout = Timeout.add_seconds (5, () => {
-            // Seems guest ignored ACPI shutdown, lets force shutdown with user's consent
-            Notification.OKFunc really_force_shutdown = () => {
-                notification = null;
-                machine.force_shutdown (false);
-            };
-
-            var message = _("Restart of '%s' is taking too long. Force it to shutdown?").printf 
(machine.name);
-            notification = App.app.notificationbar.display_for_action (message,
-                                                                       _("_Yes"),
-                                                                       (owned) really_force_shutdown,
-                                                                       null,
-                                                                       -1);
-            shutdown_timeout = 0;
-
-            return false;
-        });
-
-        machine.try_shutdown ();
+        App.app.notificationbar.display_for_action (message, _("_Yes"), machine.restart);
     }
 
     private SizeProperty? add_storage_property (ref List<Boxes.Property> list) {
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 07b5402..485b790 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -544,4 +544,69 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             }
         }
     }
+
+    public override void restart () {
+        if (state == Machine.MachineState.SAVED) {
+            debug ("'%s' is in saved state. Resuming it..", name);
+            start.begin (Machine.ConnectFlags.NONE, null, (obj, res) => {
+                try {
+                    start.end (res);
+                    restart ();
+                } catch (GLib.Error error) {
+                    warning ("Failed to start '%s': %s", domain.get_name (), error.message);
+                }
+            });
+
+            return;
+        }
+
+        stay_on_display = true;
+        ulong state_id = 0;
+        Gd.Notification notification = null;
+        debug ("Rebooting '%s'..", name);
+
+        state_id = notify["state"].connect (() => {
+            if (state == Machine.MachineState.STOPPED ||
+                state == Machine.MachineState.FORCE_STOPPED) {
+                debug ("'%s' stopped.", name);
+                start.begin (Machine.ConnectFlags.NONE, null, (obj, res) => {
+                    try {
+                        start.end (res);
+                    } catch (GLib.Error error) {
+                        warning ("Failed to start '%s': %s", domain.get_name (), error.message);
+                    }
+                });
+
+                disconnect (state_id);
+                if (shutdown_timeout != 0) {
+                    Source.remove (shutdown_timeout);
+                    shutdown_timeout = 0;
+                }
+                if (notification != null) {
+                    notification.dismiss ();
+                    notification = null;
+                }
+            }
+        });
+
+        shutdown_timeout = Timeout.add_seconds (5, () => {
+            // Seems guest ignored ACPI shutdown, lets force shutdown with user's consent
+            Notification.OKFunc really_force_shutdown = () => {
+                notification = null;
+                force_shutdown (false);
+            };
+
+            var message = _("Restart of '%s' is taking too long. Force it to shutdown?").printf (name);
+            notification = App.app.notificationbar.display_for_action (message,
+                                                                       _("_Yes"),
+                                                                       (owned) really_force_shutdown,
+                                                                       null,
+                                                                       -1);
+            shutdown_timeout = 0;
+
+            return false;
+        });
+
+        try_shutdown ();
+    }
 }
diff --git a/src/machine.vala b/src/machine.vala
index df2ec5f..e9f8da9 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -273,6 +273,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     }
 
     public abstract async void connect_display (ConnectFlags flags) throws GLib.Error;
+    public abstract void restart ();
 
     public virtual void disconnect_display () {
         if (display == null)
diff --git a/src/ovirt-machine.vala b/src/ovirt-machine.vala
index 6b78874..8518db6 100644
--- a/src/ovirt-machine.vala
+++ b/src/ovirt-machine.vala
@@ -75,6 +75,8 @@ private class Boxes.OvirtMachine: Boxes.Machine {
         return list;
     }
 
+    public override void restart () {} // See FIXME on RemoteMachine.restart
+
     private Display create_display_connection () throws GLib.Error {
         if (vm.display.address == null || vm.display.address == "")
             throw new Boxes.Error.INVALID ("empty display address for %s", vm.name);
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index a4911e9..9d725a9 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -89,4 +89,8 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
 
         source.delete ();
     }
+
+    // FIXME: Implement this. We don't currently need it because we don't set any properties here that 
requires a
+    //        restart and this method is currently used for that purpose only.
+    public override void restart () {}
 }


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