[gnome-boxes/wip/show-ip: 1/9] util-app: Add get_system_virt_connection()



commit 8decdfd3d978404c09f08de3d5a20e450994152e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Jul 3 12:06:00 2015 +0100

    util-app: Add get_system_virt_connection()
    
    This moves creation of system libvirt connection to utils. We'll be
    starting to re-use the same connection for fetching the IP address of
    guests in a following patch.
    
    This also implies that this connection is never properly unrefed/freed.
    Keeping in mind that this instance was kept around for lifetime of Boxes
    already and that libvirt is fully capable of cleaning up after apps, this
    is not such a bad thing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744004

 src/libvirt-system-importer.vala |    8 ++------
 src/util-app.vala                |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/libvirt-system-importer.vala b/src/libvirt-system-importer.vala
index 887e2d2..e1259b6 100644
--- a/src/libvirt-system-importer.vala
+++ b/src/libvirt-system-importer.vala
@@ -39,13 +39,9 @@ private class Boxes.LibvirtSystemImporter: GLib.Object {
     }
 
     public async LibvirtSystemImporter () throws GLib.Error {
-        connection = new GVir.Connection ("qemu+unix:///system");
+        connection = yield get_system_virt_connection ();
 
-        yield connection.open_read_only_async (null);
-        debug ("Connected to system libvirt, now fetching domains..");
-        yield connection.fetch_domains_async (null);
-
-        domains = connection.get_domains ();
+        domains = system_virt_connection.get_domains ();
         debug ("Fetched %u domains from system libvirt.", domains.length ());
         if (domains.length () == 0)
             throw new LibvirtSystemImporterError.NO_IMPORTS (_("No boxes to import"));
diff --git a/src/util-app.vala b/src/util-app.vala
index 3acc449..bae728e 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -164,6 +164,22 @@ namespace Boxes {
         return libvirt_bridge_net_available;
     }
 
+    private static GVir.Connection? system_virt_connection = null;
+
+    public async GVir.Connection get_system_virt_connection () throws GLib.Error {
+        if (system_virt_connection != null)
+            return system_virt_connection;
+
+        system_virt_connection = new GVir.Connection ("qemu+unix:///system");
+
+        yield system_virt_connection.open_read_only_async (null);
+
+        debug ("Connected to system libvirt, now fetching domains..");
+        yield system_virt_connection.fetch_domains_async (null);
+
+        return system_virt_connection;
+    }
+
     private string? get_logo_path (Osinfo.Os os, string[] extensions = {".svg", ".png", ".jpg"}) {
         if (extensions.length == 0)
             return null;


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