[gnome-boxes] Add new SLEEPING mode for PMSUSPEND



commit 39d2544d5bdc33d211504b1be2d1c185300dfbc5
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Oct 3 14:59:13 2012 +0200

    Add new SLEEPING mode for PMSUSPEND
    
    We do this without any hard dependency on the new symbols
    in libvirt-glib so that we can still build with the old libvirt.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685383

 configure.ac                 |   10 ++++++++++
 src/Makefile.am              |    1 +
 src/config.vapi              |    1 +
 src/libvirt-machine.vala     |   28 ++++++++++++++++++++++++----
 src/machine.vala             |    3 ++-
 vapi/libvirt-workaround.vapi |    7 +++++++
 6 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 77dbfc7..54a030b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,6 +115,16 @@ LIBGD_INIT([
   vapi
 ])
 
+old_LIBS=$LIBS
+LIBS="$LIBS $BOXES_LIBS"
+AC_CHECK_FUNCS([gvir_domain_wakeup_async],
+        [AC_DEFINE([HAVE_WAKEUP], [1], [Runtime check version hack])],
+        [AC_DEFINE([HAVE_WAKEUP], [0], [Runtime check version hack])
+         # define these to nothing so we still build
+         AC_DEFINE([gvir_domain_wakeup_async], [], [Runtime check version hack])
+         AC_DEFINE([gvir_domain_wakeup_finish], [], [Runtime check version hack])])
+LIBS=$old_libs
+
 dnl Strict compiler
 AC_ARG_ENABLE([strict-cc],
   AS_HELP_STRING([--enable-strict-cc],[Enable strict C compiler]))
diff --git a/src/Makefile.am b/src/Makefile.am
index bf88e4a..72d7aa8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,6 +22,7 @@ AM_VALAFLAGS =						\
 	--pkg cogl-1.0					\
 	--pkg config					\
 	--pkg common					\
+	--pkg libvirt-workaround			\
 	--pkg gd-1.0					\
 	--pkg gdk-pixbuf-2.0				\
 	--pkg gio-2.0-workaround			\
diff --git a/src/config.vapi b/src/config.vapi
index 1d94e77..a27faa8 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -9,4 +9,5 @@ namespace Config {
         public const string DATADIR;
         public const string PACKAGE_BUGREPORT;
         public const string PACKAGE_URL;
+        public const bool HAVE_WAKEUP;
 }
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 7c0c63f..a5f3deb 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -9,6 +9,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     public GVir.StorageVol? storage_volume;
     public VMCreator? vm_creator; // Under installation if this is set to non-null
 
+    private const GVir.DomainState DomainStatePMSUSPENDED = (GVir.DomainState)7; //DomainState.PMSUSPENDED, but we don't want a hard compile dependency
+
     public bool save_on_quit {
         get { return source.get_boolean ("source", "save-on-quit"); }
         set { source.set_boolean ("source", "save-on-quit", value); }
@@ -101,6 +103,9 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             case DomainState.CRASHED:
                 state = MachineState.STOPPED;
                 break;
+            case DomainStatePMSUSPENDED:
+                state = MachineState.SLEEPING;
+                break;
             default:
             case DomainState.NONE:
                 state = MachineState.UNKNOWN;
@@ -119,6 +124,10 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             else
                 state = MachineState.STOPPED;
         });
+        var pmsuspended_id = Signal.lookup ("pmsuspended", domain.get_type ());
+        if (pmsuspended_id != 0) {
+            Signal.connect_object(domain, "pmsuspended", (GLib.Callback) LibvirtMachine.pmsuspended_callback, this, 0);
+        }
         notify["state"].connect (() => {
             if (state == MachineState.RUNNING)
                 reconnect_display ();
@@ -133,6 +142,12 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         set_stats_enable (true);
     }
 
+    // This is done as a method and not a lambda as we don't want a hard build
+    // dep on the new pmsuspended signal yet.
+    private static void pmsuspended_callback (GVir.Domain domain, LibvirtMachine machine) {
+        machine.state = MachineState.SLEEPING;
+    }
+
     private void update_cpu_stat (DomainInfo info, ref MachineStat stat) {
         var prev = stats[STATS_SIZE - 1];
 
@@ -361,7 +376,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             warning ("Failed to get information on '%s'", name);
         }
 
-        if (state != DomainState.RUNNING && state != DomainState.PAUSED)
+        if (state != DomainState.RUNNING && state != DomainState.PAUSED && state != DomainStatePMSUSPENDED)
             return null;
 
         var stream = connection.get_stream (0);
@@ -531,7 +546,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                     config.set ("current-memory", value);
                 domain.set_config (config);
                 debug ("RAM changed to %llu", value);
-                if (state == MachineState.RUNNING || state == MachineState.PAUSED)
+                if (state == MachineState.RUNNING || state == MachineState.PAUSED || state == MachineState.SLEEPING)
                     notify_reboot_required ();
             } catch (GLib.Error error) {
                 warning ("Failed to change RAM of box '%s' to %llu: %s",
@@ -540,7 +555,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                          error.message);
             }
 
-            if (state == MachineState.RUNNING || state == MachineState.PAUSED)
+            if (state == MachineState.RUNNING || state == MachineState.PAUSED || state == MachineState.SLEEPING)
                 update_ram_property (property);
 
             return false;
@@ -553,7 +568,12 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
 
         if (state == MachineState.PAUSED)
             yield domain.resume_async (null);
-        else {
+        else if (state == MachineState.SLEEPING) {
+            if (Config.HAVE_WAKEUP)
+                yield ((BoxesGVir.Domain)domain).wakeup_async (0, null);
+            else
+                throw new Boxes.Error.INVALID ("Wakeup not supported");
+        } else {
             if (domain.get_saved ())
                 // Translators: The %s will be expanded with the name of the vm
                 status = _("Restoring %s from disk").printf (name);
diff --git a/src/machine.vala b/src/machine.vala
index c459159..8b3b1a8 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -32,7 +32,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
         STOPPED,
         RUNNING,
         PAUSED,
-        SAVED
+        SAVED,
+        SLEEPING
     }
 
     // The current screenshot without running status applied
diff --git a/vapi/libvirt-workaround.vapi b/vapi/libvirt-workaround.vapi
new file mode 100644
index 0000000..65b7016
--- /dev/null
+++ b/vapi/libvirt-workaround.vapi
@@ -0,0 +1,7 @@
+[CCode (cprefix = "GVir", gir_namespace = "LibvirtGObject", gir_version = "1.0", lower_case_cprefix = "gvir_")]
+namespace BoxesGVir {
+	[CCode (cheader_filename = "libvirt-gobject/libvirt-gobject.h", type_id = "gvir_domain_get_type ()")]
+	public class Domain : GLib.Object {
+		public async bool wakeup_async (uint flags, GLib.Cancellable? cancellable) throws GLib.Error;
+	}
+}



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