[libvirt-glib/libvirt-gconfig 10/17] gconfig: Add GVirCofigDomainGraphicsRemote class

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

 



Seems that GVirConfigDomainGraphics* were built with a strong focus on
writing/setting configs, but not reading those.

For instance, considering virt-viewer's case, where the app is just
consuming an already built xml, for getting the port attribute of a
GVirDomainConfigGraphis{Spice,Vnc} you have to know, beforehand, the
type of the connection and then call
gvir_config_domain_graphics_{sdl,spice}_get_port(). It means creating an
abstraction on virt-viewer side, that will ended up in some code like:
    if (GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(graphics))
        _get_whatever_you_want_using_specific_spice_api()
    else
        _get_whatever_you want_using_specific_vnc_api()

In order to avoid this, let's introduce GVirConfigDomainGraphicsRemote
class that, at least for now, is intended to be a helper for the case
explained above. It introduces a new hierarchy in the project, where,
instead of having GVirConfigDomainGraphics{Spice,Vnc,Rdp} inheriting
from GVirCOnfigDomainGraphics, these classes will inherit from
GVirConfigDomainGraphicsRemote (see the next patches) which inherits
from from GVirConfigGraphics (it will cause an ABI breakage, though).

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 libvirt-gconfig/Makefile.am                        |   2 +
 .../libvirt-gconfig-domain-graphics-remote.c       | 103 +++++++++++++++++++++
 .../libvirt-gconfig-domain-graphics-remote.h       |  70 ++++++++++++++
 libvirt-gconfig/libvirt-gconfig.h                  |   1 +
 libvirt-gconfig/libvirt-gconfig.sym                |   5 +
 po/POTFILES.in                                     |   1 +
 6 files changed, 182 insertions(+)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index f308539..45fc559 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -47,6 +47,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-domain-graphics.h \
 			libvirt-gconfig-domain-graphics-desktop.h \
 			libvirt-gconfig-domain-graphics-rdp.h \
+			libvirt-gconfig-domain-graphics-remote.h \
 			libvirt-gconfig-domain-graphics-sdl.h \
 			libvirt-gconfig-domain-graphics-spice.h \
 			libvirt-gconfig-domain-graphics-vnc.h \
@@ -138,6 +139,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-domain-graphics.c \
 			libvirt-gconfig-domain-graphics-desktop.c \
 			libvirt-gconfig-domain-graphics-rdp.c \
+			libvirt-gconfig-domain-graphics-remote.c \
 			libvirt-gconfig-domain-graphics-sdl.c \
 			libvirt-gconfig-domain-graphics-spice.c \
 			libvirt-gconfig-domain-graphics-vnc.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c
new file mode 100644
index 0000000..e8b090f
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c
@@ -0,0 +1,103 @@
+/*
+ * libvirt-gconfig-domain-graphics-remote.c: libvirt domain graphics remote configuration
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include <glib/gi18n-lib.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE, GVirConfigDomainGraphicsRemotePrivate))
+
+struct _GVirConfigDomainGraphicsRemotePrivate
+{
+    gboolean unused;
+};
+
+typedef GVirConfigObject *(*GVirConfigDomainGraphicsRemoteNewFromXml)(const gchar *xml, GError **error);
+
+G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainGraphicsRemote, gvir_config_domain_graphics_remote, GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS);
+
+static void gvir_config_domain_graphics_remote_class_init(GVirConfigDomainGraphicsRemoteClass *klass)
+{
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainGraphicsRemotePrivate));
+}
+
+static void gvir_config_domain_graphics_remote_init(GVirConfigDomainGraphicsRemote *graphics)
+{
+    graphics->priv = GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE_GET_PRIVATE(graphics);
+}
+
+GVirConfigDomainGraphicsRemote *
+gvir_config_domain_graphics_remote_new_from_xml(const gchar *xml,
+                                                GError **error)
+{
+    GVirConfigDomainGraphicsRemoteNewFromXml functions[] = {
+        (GVirConfigDomainGraphicsRemoteNewFromXml)gvir_config_domain_graphics_vnc_new_from_xml,
+        (GVirConfigDomainGraphicsRemoteNewFromXml)gvir_config_domain_graphics_spice_new_from_xml,
+        (GVirConfigDomainGraphicsRemoteNewFromXml)gvir_config_domain_graphics_rdp_new_from_xml,
+    };
+    GVirConfigObject *object;
+
+    for (int i = 0; i < G_N_ELEMENTS(functions); i++) {
+        GVirConfigDomainGraphicsRemoteNewFromXml function = functions[i];
+
+        object = GVIR_CONFIG_OBJECT(function(xml, NULL));
+        if (object != NULL)
+            break;
+    }
+
+    if (object == NULL) {
+        g_set_error(error,
+                    GVIR_CONFIG_OBJECT_ERROR,
+                    0,
+                    _("Unable to create a new GraphicRemote object from the XML"));
+    }
+
+    return GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE(object);
+}
+
+gboolean gvir_config_domain_graphics_remote_get_autoport(GVirConfigDomainGraphicsRemote *graphics)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_REMOTE(graphics), FALSE);
+
+    return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(graphics),
+                                                    NULL, "autoport", FALSE);
+}
+
+const gchar *gvir_config_domain_graphics_remote_get_host(GVirConfigDomainGraphicsRemote *graphics)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_REMOTE(graphics), NULL);
+
+    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(graphics),
+                                            NULL, "listen");
+}
+
+int gvir_config_domain_graphics_remote_get_port(GVirConfigDomainGraphicsRemote *graphics)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_REMOTE(graphics), 0);
+
+    return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(graphics),
+                                                   NULL, "port", 0);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h
new file mode 100644
index 0000000..d9de6df
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h
@@ -0,0 +1,70 @@
+/*
+ * libvirt-gconfig-domain-graphics-remote.h: libvirt domain graphics  remote configuration
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_REMOTE_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_REMOTE_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE            (gvir_config_domain_graphics_remote_get_type ())
+#define GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE, GVirConfigDomainGraphicsRemote))
+#define GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE, GVirConfigDomainGraphicsRemoteClass))
+#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_REMOTE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE))
+#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_REMOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE))
+#define GVIR_CONFIG_DOMAIN_GRAPHICS_REMOTE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_REMOTE, GVirConfigDomainGraphicsRemoteClass))
+
+typedef struct _GVirConfigDomainGraphicsRemote GVirConfigDomainGraphicsRemote;
+typedef struct _GVirConfigDomainGraphicsRemotePrivate GVirConfigDomainGraphicsRemotePrivate;
+typedef struct _GVirConfigDomainGraphicsRemoteClass GVirConfigDomainGraphicsRemoteClass;
+
+struct _GVirConfigDomainGraphicsRemote
+{
+    GVirConfigDomainGraphics parent;
+
+    GVirConfigDomainGraphicsRemotePrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainGraphicsRemoteClass
+{
+    GVirConfigDomainGraphicsClass parent_class;
+
+    gpointer padding[20];
+};
+
+GType gvir_config_domain_graphics_remote_get_type(void);
+
+GVirConfigDomainGraphicsRemote *gvir_config_domain_graphics_remote_new_from_xml(const gchar *xml,
+                                                                                GError **error);
+
+gboolean  gvir_config_domain_graphics_remote_get_autoport(GVirConfigDomainGraphicsRemote *interface);
+const gchar *gvir_config_domain_graphics_remote_get_host(GVirConfigDomainGraphicsRemote *graphics);
+int gvir_config_domain_graphics_remote_get_port(GVirConfigDomainGraphicsRemote *interface);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_REMOTE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 4624003..1ff369b 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -62,6 +62,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index ed47610..6dca69a 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -734,9 +734,14 @@ global:
 } LIBVIRT_GCONFIG_0.2.1;
 
 LIBVIRT_GCONFIG_0.2.4 {
+global:
 	gvir_config_domain_graphics_rdp_get_autoport;
 	gvir_config_domain_graphics_rdp_get_host;
 	gvir_config_domain_graphics_rdp_set_host;
+	gvir_config_domain_graphics_remote_get_autoport;
+	gvir_config_domain_graphics_remote_get_host;
+	gvir_config_domain_graphics_remote_get_port;
+	gvir_config_domain_graphics_remote_get_type;
 	gvir_config_domain_graphics_sdl_get_display;
 	gvir_config_domain_graphics_sdl_get_fullscreen;
 	gvir_config_domain_graphics_spice_get_autoport;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 335ec67..da68459 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,4 +1,5 @@
 libvirt-gconfig/libvirt-gconfig-helpers.c
 libvirt-gconfig/libvirt-gconfig-object.c
+libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c
 libvirt-gobject/libvirt-gobject-connection.c
 libvirt-gobject/libvirt-gobject-stream.c
-- 
2.5.0

--
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]