We will often need to convert from an enum to its string
representation, add an helper for that to avoid duplicating that
code.

--
v2: moved before gvir_config_clock_set_offset implementation since
it needs it
---
 libvirt-gconfig/libvirt-gconfig-domain-clock.c    |   17 +++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-clock.h    |    8 ++++++++
 libvirt-gconfig/libvirt-gconfig-helpers-private.h |    1 +
 libvirt-gconfig/libvirt-gconfig-helpers.c         |   17 +++++++++++++++++
 libvirt-gconfig/libvirt-gconfig.sym               |    2 ++
 5 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-clock.c 
b/libvirt-gconfig/libvirt-gconfig-domain-clock.c
index 7c7381b..b414c4f 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-clock.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-clock.c
@@ -27,6 +27,7 @@
 #include <libxml/tree.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
 #include "libvirt-gconfig/libvirt-gconfig-object-private.h"
 
 extern gboolean debugFlag;
@@ -81,6 +82,22 @@ GVirConfigDomainClock 
*gvir_config_domain_clock_new_from_xml(const gchar *xml,
     return GVIR_CONFIG_DOMAIN_CLOCK(object);
 }
 
+void gvir_config_domain_clock_set_offset(GVirConfigDomainClock *klock,
+                                         GVirConfigDomainClockOffset offset)
+{
+    xmlNodePtr node;
+    const char *offset_str;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CLOCK(klock));
+
+    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock));
+    g_return_if_fail(node != NULL);
+    offset_str = 
gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_CLOCK_OFFSET,
+                                             offset);
+    g_return_if_fail(offset_str != NULL);
+    xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)offset_str);
+}
+
 void gvir_config_domain_clock_set_timezone(GVirConfigDomainClock *klock,
                                            const char *tz)
 {
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-clock.h 
b/libvirt-gconfig/libvirt-gconfig-domain-clock.h
index 588bb10..6a68c24 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-clock.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-clock.h
@@ -56,12 +56,20 @@ struct _GVirConfigDomainClockClass
     gpointer padding[20];
 };
 
+typedef enum {
+    GVIR_CONFIG_DOMAIN_CLOCK_UTC,
+    GVIR_CONFIG_DOMAIN_CLOCK_LOCALTIME,
+    GVIR_CONFIG_DOMAIN_CLOCK_TIMEZONE,
+    GVIR_CONFIG_DOMAIN_CLOCK_VARIABLE
+} GVirConfigDomainClockOffset;
 
 GType gvir_config_domain_clock_get_type(void);
 
 GVirConfigDomainClock *gvir_config_domain_clock_new(void);
 GVirConfigDomainClock *gvir_config_domain_clock_new_from_xml(const gchar *xml,
                                                 GError **error);
+void gvir_config_domain_clock_set_offset(GVirConfigDomainClock *klock,
+                                         GVirConfigDomainClockOffset offset);
 void gvir_config_domain_clock_set_timezone(GVirConfigDomainClock *klock,
                                            const char *tz);
 void gvir_config_domain_clock_set_variable_offset(GVirConfigDomainClock *klock,
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h 
b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
index c7a5d6a..59efd24 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
@@ -40,6 +40,7 @@ xmlChar * gvir_config_xml_get_child_element_content (xmlNode  
  *node,
                                                      const char *child_name);
 char *gvir_config_xml_get_child_element_content_glib (xmlNode    *node,
                                                       const char *child_name);
+const char *gvir_config_genum_get_nick (GType enum_type, gint value);
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_HELPERS_PRIVATE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c 
b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 2e28429..d7e1140 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -178,3 +178,20 @@ gvir_config_xml_get_child_element_content_glib (xmlNode    
*node,
 
         return copy;
 }
+
+const char *gvir_config_genum_get_nick (GType enum_type, gint value)
+{
+    GEnumClass *enum_class;
+    GEnumValue *enum_value;
+
+    g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
+
+    enum_class = g_type_class_ref(enum_type);
+    enum_value = g_enum_get_value(enum_class, value);
+    g_type_class_unref(enum_class);
+
+    if (enum_value != NULL)
+        return enum_value->value_nick;
+
+    g_return_val_if_reached(NULL);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig.sym 
b/libvirt-gconfig/libvirt-gconfig.sym
index 7ba073b..ab4fce8 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -16,8 +16,10 @@ LIBVIRT_GOBJECT_0.0.1 {
        gvir_config_domain_set_name;
 
        gvir_config_domain_clock_get_type;
+       gvir_config_domain_clock_offset_get_type;
        gvir_config_domain_clock_new;
        gvir_config_domain_clock_new_from_xml;
+       gvir_config_domain_clock_set_offset;
        gvir_config_domain_clock_set_timezone;
        gvir_config_domain_clock_set_variable_offset;
 
-- 
1.7.7.3

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

Reply via email to