[libvirt-designer PATCHv2] Add GvirDesignerDomain::osinfo_db

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

 



virtxml was doing its own loading of the libosinfo database,
and gvir_designer_init() was loading it a second time.
By adding a GVirDesignerDomain::osinfo_db property, applications
can share the same OsinfoDb as libvirt-designer. The association
is made per libvirt-designer domain for more flexibility.
If no OsinfoDb is associated with a domain when needed,
libvirt-designer will automatically try to load it.
---
 examples/virtxml.c                           |  2 ++
 libvirt-designer/libvirt-designer-domain.c   | 49 +++++++++++++++++++++++++++-
 libvirt-designer/libvirt-designer-internal.h |  3 --
 libvirt-designer/libvirt-designer-main.c     | 12 -------
 libvirt-designer/libvirt-designer-main.h     |  2 ++
 libvirt-designer/libvirt-designer.sym        |  1 +
 6 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/examples/virtxml.c b/examples/virtxml.c
index a68843d..be6ee7a 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -559,6 +559,8 @@ main(int argc, char *argv[])
     }
 
     domain = gvir_designer_domain_new(os, platform, caps);
+    if (db != NULL)
+        g_object_set(G_OBJECT(domain), "osinfo-db", db, NULL);
 
     gvir_designer_domain_setup_machine(domain, &error);
     CHECK_ERROR;
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index 3e31bd1..b78b8d3 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -35,6 +35,7 @@ struct _GVirDesignerDomainPrivate
 {
     GVirConfigDomain *config;
     GVirConfigCapabilities *caps;
+    OsinfoDb *osinfo_db;
     OsinfoOs *os;
     OsinfoPlatform *platform;
 
@@ -66,6 +67,7 @@ enum {
     PROP_OS,
     PROP_PLATFORM,
     PROP_CAPS,
+    PROP_OSINFO_DB,
 };
 
 static void gvir_designer_domain_get_property(GObject *object,
@@ -83,6 +85,10 @@ static void gvir_designer_domain_get_property(GObject *object,
         g_value_set_object(value, priv->config);
         break;
 
+    case PROP_OSINFO_DB:
+        g_value_set_object(value, priv->osinfo_db);
+        break;
+
     case PROP_OS:
         g_value_set_object(value, priv->os);
         break;
@@ -112,6 +118,11 @@ static void gvir_designer_domain_set_property(GObject *object,
     GVirDesignerDomainPrivate *priv = design->priv;
 
     switch (prop_id) {
+    case PROP_OSINFO_DB:
+        if (priv->osinfo_db)
+            g_object_unref(priv->osinfo_db);
+        priv->osinfo_db = g_value_dup_object(value);
+        break;
     case PROP_OS:
         if (priv->os)
             g_object_unref(priv->os);
@@ -147,6 +158,8 @@ static void gvir_designer_domain_finalize(GObject *object)
     g_object_unref(priv->caps);
     if (priv->deployment)
         g_object_unref(priv->deployment);
+    if (priv->osinfo_db)
+        g_object_unref(priv->osinfo_db);
 
     G_OBJECT_CLASS(gvir_designer_domain_parent_class)->finalize(object);
 }
@@ -171,6 +184,15 @@ static void gvir_designer_domain_class_init(GVirDesignerDomainClass *klass)
                                                         G_PARAM_STATIC_STRINGS));
 
     g_object_class_install_property(object_class,
+                                    PROP_OSINFO_DB,
+                                    g_param_spec_object("osinfo-db",
+                                                        "Osinfo Database",
+                                                        "libosinfo database",
+                                                        OSINFO_TYPE_DB,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE |
+                                                        G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
                                     PROP_OS,
                                     g_param_spec_object("os",
                                                         "Os",
@@ -709,6 +731,23 @@ cleanup:
 }
 
 
+static void gvir_designer_domain_load_osinfo_db(GVirDesignerDomain *domain)
+{
+    /* Init libosinfo and load databases from default paths */
+    /* XXX maybe we want to let users tell a different path via
+     * env variable or argv */
+    OsinfoLoader *osinfo_loader = NULL;
+    OsinfoDb *db;
+
+    osinfo_loader = osinfo_loader_new();
+    osinfo_loader_process_default_path(osinfo_loader, NULL);
+
+    db = osinfo_loader_get_db(osinfo_loader);
+    if (db != NULL)
+        g_object_set(G_OBJECT(domain), "osinfo-db", db, NULL);
+    g_object_unref(G_OBJECT(osinfo_loader));
+}
+
 static OsinfoDeviceLink *
 gvir_designer_domain_get_preferred_device(GVirDesignerDomain *design,
                                           const char *class,
@@ -721,7 +760,15 @@ gvir_designer_domain_get_preferred_device(GVirDesignerDomain *design,
     OsinfoDeviceLink *dev_link = NULL;
 
     if (!deployment) {
-        priv->deployment = deployment = osinfo_db_find_deployment(osinfo_db,
+        if (!priv->osinfo_db)
+            gvir_designer_domain_load_osinfo_db(design);
+
+        if (!priv->osinfo_db) {
+            g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0,
+                        "Unable to find any deployment in libosinfo database");
+            goto cleanup;
+        }
+        priv->deployment = deployment = osinfo_db_find_deployment(priv->osinfo_db,
                                                                   priv->os,
                                                                   priv->platform);
         if (!deployment) {
diff --git a/libvirt-designer/libvirt-designer-internal.h b/libvirt-designer/libvirt-designer-internal.h
index bbef922..e95edfc 100644
--- a/libvirt-designer/libvirt-designer-internal.h
+++ b/libvirt-designer/libvirt-designer-internal.h
@@ -24,7 +24,4 @@
 #ifndef __LIBVIRT_DESIGNER_INTERNAL_H__
 #define __LIBVIRT_DESIGNER_INTERNAL_H__
 
-extern OsinfoLoader *osinfo_loader;
-extern OsinfoDb *osinfo_db;
-
 #endif /* __LIBVIRT_DESIGNER_INTERNAL_H__ */
diff --git a/libvirt-designer/libvirt-designer-main.c b/libvirt-designer/libvirt-designer-main.c
index 5c70b57..927eb21 100644
--- a/libvirt-designer/libvirt-designer-main.c
+++ b/libvirt-designer/libvirt-designer-main.c
@@ -30,9 +30,6 @@
 #include <libvirt-designer/libvirt-designer.h>
 #include <libvirt-gconfig/libvirt-gconfig.h>
 
-OsinfoLoader *osinfo_loader = NULL;
-OsinfoDb *osinfo_db = NULL;
-
 /**
  * gvir_designer_init:
  * @argc: (inout): pointer to application's argc
@@ -57,7 +54,6 @@ static void gvir_log_handler(const gchar *log_domain G_GNUC_UNUSED,
         fprintf(stderr, "%s\n", message);
 }
 
-
 /**
  * gvir_designer_init_check:
  * @argc: (inout): pointer to application's argc
@@ -85,13 +81,5 @@ gboolean gvir_designer_init_check(int *argc,
                           gvir_log_handler, NULL);
 #endif
 
-    /* Init libosinfo and load databases from default paths */
-    /* XXX maybe we want to let users tell a different path via
-     * env variable or argv */
-    osinfo_loader = osinfo_loader_new();
-    osinfo_loader_process_default_path(osinfo_loader, NULL);
-
-    osinfo_db = osinfo_loader_get_db(osinfo_loader);
-
     return TRUE;
 }
diff --git a/libvirt-designer/libvirt-designer-main.h b/libvirt-designer/libvirt-designer-main.h
index 2500ef7..5e82f8a 100644
--- a/libvirt-designer/libvirt-designer-main.h
+++ b/libvirt-designer/libvirt-designer-main.h
@@ -24,6 +24,8 @@
 #error "Only <libvirt-gdesigner/libvirt-gdesigner.h> can be included directly."
 #endif
 
+#include <osinfo/osinfo.h>
+
 #ifndef __LIBVIRT_DESIGNER_MAIN_H__
 #define __LIBVIRT_DESIGNER_MAIN_H__
 
diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
index 79db09f..6f63abc 100644
--- a/libvirt-designer/libvirt-designer.sym
+++ b/libvirt-designer/libvirt-designer.sym
@@ -2,6 +2,7 @@ LIBVIRT_DESIGNER_0.0.1 {
    global:
 	gvir_designer_init;
 	gvir_designer_init_check;
+	gvir_designer_get_osinfo_db;
 
 	gvir_designer_domain_new;
 	gvir_designer_domain_get_type;
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]