[gupnp-dlna/wip/new-api: 18/46] Add a function converting GUPnPDLNANativeValue to GValue.



commit 4046716c05d2a23236eaccfbf40872aa4cebfc8e
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Thu Nov 29 18:54:44 2012 +0100

    Add a function converting GUPnPDLNANativeValue to GValue.

 .../native/sets/gupnp-dlna-native-value.c          |   76 +++++++++++++++++++-
 .../native/sets/gupnp-dlna-native-value.h          |    5 ++
 2 files changed, 79 insertions(+), 2 deletions(-)
---
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.c b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.c
index a9a3d44..6883a5f 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.c
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.c
@@ -41,6 +41,11 @@ struct _GUPnPDLNANativeValueVTable {
 
         GUPnPDLNANativeValueUnion *
         (* get_sort_value) (GUPnPDLNANativeValue *base);
+
+        gboolean
+        (* to_g_value) (GUPnPDLNANativeValue     *base,
+                        GUPnPDLNANativeValueType *type,
+                        GValue                   *g_value);
 };
 
 /* single */
@@ -70,12 +75,18 @@ single_to_string (GUPnPDLNANativeValue     *base,
 static GUPnPDLNANativeValueUnion *
 single_get_sort_value (GUPnPDLNANativeValue *base);
 
+static gboolean
+single_to_g_value (GUPnPDLNANativeValue     *base,
+                   GUPnPDLNANativeValueType *type,
+                   GValue                   *g_value);
+
 static GUPnPDLNANativeValueVTable single_vtable = {
         single_is_superset,
         single_copy,
         single_free,
         single_to_string,
-        single_get_sort_value
+        single_get_sort_value,
+        single_to_g_value
 };
 
 static gboolean
@@ -140,6 +151,18 @@ single_get_sort_value (GUPnPDLNANativeValue *base)
         return &value->value;
 }
 
+static gboolean
+single_to_g_value (GUPnPDLNANativeValue     *base,
+                   GUPnPDLNANativeValueType *type,
+                   GValue                   *g_value)
+{
+        GUPnPDLNANativeValueSingle *value = (GUPnPDLNANativeValueSingle *) base;
+
+        gupnp_dlna_native_value_type_to_g_value (type, &value->value, g_value);
+
+        return TRUE;
+}
+
 /* range */
 typedef struct _GUPnPDLNANativeValueRange GUPnPDLNANativeValueRange;
 
@@ -168,12 +191,18 @@ range_to_string (GUPnPDLNANativeValue     *base,
 static GUPnPDLNANativeValueUnion *
 range_get_sort_value (GUPnPDLNANativeValue *base);
 
+static gboolean
+range_to_g_value (GUPnPDLNANativeValue     *base,
+                  GUPnPDLNANativeValueType *type,
+                  GValue                   *g_value);
+
 static GUPnPDLNANativeValueVTable range_vtable = {
         range_is_superset,
         range_copy,
         range_free,
         range_to_string,
-        range_get_sort_value
+        range_get_sort_value,
+        range_to_g_value
 };
 
 static gboolean
@@ -257,6 +286,30 @@ range_get_sort_value (GUPnPDLNANativeValue *base)
         return &range->min;
 }
 
+static gboolean
+range_to_g_value (GUPnPDLNANativeValue     *base,
+                  GUPnPDLNANativeValueType *type,
+                  GValue                   *g_value)
+{
+        GValue from = G_VALUE_INIT;
+        GValue to = G_VALUE_INIT;
+        GUPnPDLNANativeValueRange *range = (GUPnPDLNANativeValueRange *) base;
+        gboolean result;
+
+        gupnp_dlna_native_value_type_to_g_value (type, &range->min, &from);
+        gupnp_dlna_native_value_type_to_g_value (type, &range->max, &to);
+        result = gupnp_dlna_native_value_type_flatten (type,
+                                                       g_value,
+                                                       &from,
+                                                       &to);
+        g_value_unset (&from);
+        g_value_unset (&to);
+
+        return result;
+}
+
+/* API */
+
 GUPnPDLNANativeValue *
 gupnp_dlna_native_value_new_single (GUPnPDLNANativeValueType *type,
                                     const gchar              *raw)
@@ -391,3 +444,22 @@ gupnp_dlna_native_value_compare (GUPnPDLNANativeValue     *base,
                                                      other_union);
 
 }
+
+GValue *
+gupnp_dlna_native_value_to_g_value (GUPnPDLNANativeValue     *base,
+                                    GUPnPDLNANativeValueType *type)
+{
+        GValue *g_value;
+
+        g_return_val_if_fail (base->vtable != NULL, NULL);
+        g_return_val_if_fail (base->vtable->to_g_value != NULL, NULL);
+
+        g_value = g_slice_new0 (GValue);
+
+        if (base->vtable->to_g_value (base, type, g_value)) {
+                g_slice_free (GValue, g_value);
+                g_value = NULL;
+        }
+
+        return g_value;
+}
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.h b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.h
index 0c722d7..7059e63 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.h
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value.h
@@ -23,6 +23,7 @@
 #define __GUPNP_DLNA_NATIVE_VALUE_H__
 
 #include <glib.h>
+#include <glib-object.h>
 #include "gupnp-dlna-native-info-value.h"
 #include "gupnp-dlna-native-value-type.h"
 
@@ -65,6 +66,10 @@ gupnp_dlna_native_value_compare (GUPnPDLNANativeValue     *base,
                                  GUPnPDLNANativeValue     *other,
                                  GUPnPDLNANativeValueType *type);
 
+GValue *
+gupnp_dlna_native_value_to_g_value (GUPnPDLNANativeValue     *base,
+                                    GUPnPDLNANativeValueType *type);
+
 G_END_DECLS
 
 #endif /* __GUPNP_DLNA_NATIVE_VALUE_H__ */



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