From: Fabiano Fidêncio <fiden...@redhat.com>

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 <fiden...@redhat.com>
---
 libvirt-gconfig/Makefile.am                        |  2 +
 .../libvirt-gconfig-domain-graphics-remote.c       | 95 ++++++++++++++++++++++
 .../libvirt-gconfig-domain-graphics-remote.h       | 69 ++++++++++++++++
 libvirt-gconfig/libvirt-gconfig.h                  |  1 +
 libvirt-gconfig/libvirt-gconfig.sym                |  2 +
 po/POTFILES.in                                     |  1 +
 6 files changed, 170 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 ba08a11..64812bb 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \
                        libvirt-gconfig-domain-graphics-listen-none.h \
                        libvirt-gconfig-domain-graphics-listen-unix.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 \
@@ -148,6 +149,7 @@ GCONFIG_SOURCE_FILES = \
                        libvirt-gconfig-domain-graphics-listen-none.c \
                        libvirt-gconfig-domain-graphics-listen-unix.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..46b97f2
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <fiden...@redhat.com>
+ */
+
+#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);
+}
+
+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..cae8d21
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-remote.h
@@ -0,0 +1,69 @@
+/*
+ * 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 <fiden...@redhat.com>
+ */
+
+#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);
+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 45d3839..b6e8433 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-listen.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym 
b/libvirt-gconfig/libvirt-gconfig.sym
index 4cd5f4d..7d17b01 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -757,6 +757,8 @@ global:
        gvir_config_domain_graphics_listen_unix_new;
        gvir_config_domain_graphics_listen_unix_new_from_xml;
        gvir_config_domain_graphics_listen_unix_set_path;
+       gvir_config_domain_graphics_remote_get_port;
+       gvir_config_domain_graphics_remote_get_type;
        gvir_config_domain_graphics_spice_add_listen;
        gvir_config_domain_graphics_spice_get_listen;
        gvir_config_domain_graphics_spice_get_tls_port;
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.7.4

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

Reply via email to