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

[libvirt] [libvirt-designer] Add GvirDesignerDomain::osinfo-db



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.
---
 examples/virtxml.c                           |  2 +-
 libvirt-designer/libvirt-designer-domain.c   | 34 ++++++++++++++++++++++++++--
 libvirt-designer/libvirt-designer-domain.h   |  3 ++-
 libvirt-designer/libvirt-designer-internal.h |  3 ---
 libvirt-designer/libvirt-designer-main.c     | 12 ----------
 libvirt-designer/libvirt-designer-main.h     |  2 ++
 6 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/examples/virtxml.c b/examples/virtxml.c
index a68843d..c5a5e24 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -558,7 +558,7 @@ main(int argc, char *argv[])
         goto cleanup;
     }
 
-    domain = gvir_designer_domain_new(os, platform, caps);
+    domain = gvir_designer_domain_new(db, os, platform, caps);
 
     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..49e8068 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,16 @@ 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_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
                                     PROP_OS,
                                     g_param_spec_object("os",
                                                         "Os",
@@ -215,11 +238,13 @@ static void gvir_designer_domain_init(GVirDesignerDomain *design)
 }
 
 
-GVirDesignerDomain *gvir_designer_domain_new(OsinfoOs *os,
+GVirDesignerDomain *gvir_designer_domain_new(OsinfoDb *db,
+                                             OsinfoOs *os,
                                              OsinfoPlatform *platform,
                                              GVirConfigCapabilities *caps)
 {
     return GVIR_DESIGNER_DOMAIN(g_object_new(GVIR_DESIGNER_TYPE_DOMAIN,
+                                             "osinfo-db", db,
                                              "os", os,
                                              "platform", platform,
                                              "capabilities", caps,
@@ -721,7 +746,12 @@ 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) {
+            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-domain.h b/libvirt-designer/libvirt-designer-domain.h
index 38731a2..4d68ff6 100644
--- a/libvirt-designer/libvirt-designer-domain.h
+++ b/libvirt-designer/libvirt-designer-domain.h
@@ -66,7 +66,8 @@ struct _GVirDesignerDomainClass
 
 GType gvir_designer_domain_get_type(void);
 
-GVirDesignerDomain *gvir_designer_domain_new(OsinfoOs *os,
+GVirDesignerDomain *gvir_designer_domain_new(OsinfoDb *osinfo_db,
+                                             OsinfoOs *os,
                                              OsinfoPlatform *platform,
                                              GVirConfigCapabilities *caps);
 
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__
 
-- 
1.8.1.4


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