[gupnp-dlna/wip/new-api: 16/46] Add GUPnPDLNA{Fraction,Int}Range.



commit a653e47ac3129cfd81926e7ac43c5ac8d6e1bb3c
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Thu Nov 29 18:40:09 2012 +0100

    Add GUPnPDLNA{Fraction,Int}Range.
    
    They will be needed for serialization of GUPnPDLNAValueList's values
    into GValues.

 libgupnp-dlna/Makefile.am                   |    6 +-
 libgupnp-dlna/gupnp-dlna-g-values-private.h |   22 ++++
 libgupnp-dlna/gupnp-dlna-g-values.c         |  180 +++++++++++++++++++++++++++
 libgupnp-dlna/gupnp-dlna-g-values.h         |  111 ++++++++++++++++
 4 files changed, 317 insertions(+), 2 deletions(-)
---
diff --git a/libgupnp-dlna/Makefile.am b/libgupnp-dlna/Makefile.am
index 703f40c..351d4ab 100644
--- a/libgupnp-dlna/Makefile.am
+++ b/libgupnp-dlna/Makefile.am
@@ -113,7 +113,8 @@ libgupnp_dlna_2_0_la_SOURCES = \
 	gupnp-dlna-profile-backend.c \
 	gupnp-dlna-profile.c \
 	gupnp-dlna-restriction.c \
-	gupnp-dlna-value-list.c
+	gupnp-dlna-value-list.c \
+	gupnp-dlna-g-values.c
 libgupnp_dlna_2_0_la_LIBADD = \
 	$(gupnp_libadd) \
 	libloader.la \
@@ -130,7 +131,8 @@ libgupnp_dlna_inc_HEADERS = \
 	gupnp-dlna-profile-guesser.h \
 	gupnp-dlna-profile.h \
 	gupnp-dlna-restriction.h \
-	gupnp-dlna-value-list.h
+	gupnp-dlna-value-list.h \
+	gupnp-dlna-g-values.h
 
 libgupnp_dlna_metadata_incdir = \
 	$(libgupnp_dlna_incdir)/metadata
diff --git a/libgupnp-dlna/gupnp-dlna-g-values-private.h b/libgupnp-dlna/gupnp-dlna-g-values-private.h
index 9963719..9be8c31 100644
--- a/libgupnp-dlna/gupnp-dlna-g-values-private.h
+++ b/libgupnp-dlna/gupnp-dlna-g-values-private.h
@@ -25,6 +25,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include "gupnp-dlna-g-values.h"
+
 G_BEGIN_DECLS
 
 struct _GUPnPDLNAFraction
@@ -33,6 +35,26 @@ struct _GUPnPDLNAFraction
         gint denominator;
 };
 
+struct _GUPnPDLNAFractionRange
+{
+        GUPnPDLNAFraction *min;
+        GUPnPDLNAFraction *max;
+};
+
+struct _GUPnPDLNAIntRange
+{
+        gint min;
+        gint max;
+};
+
+GUPnPDLNAFractionRange *
+gupnp_dlna_fraction_range_new_take (GUPnPDLNAFraction *min,
+                                    GUPnPDLNAFraction *max);
+
+GUPnPDLNAIntRange *
+gupnp_dlna_int_range_new (gint min,
+                          gint max);
+
 G_END_DECLS
 
 #endif /* __GUPNP_DLNA_G_VALUES_PRIVATE_H__ */
diff --git a/libgupnp-dlna/gupnp-dlna-g-values.c b/libgupnp-dlna/gupnp-dlna-g-values.c
new file mode 100644
index 0000000..40478f6
--- /dev/null
+++ b/libgupnp-dlna/gupnp-dlna-g-values.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Authors: Krzesimir Nowak <krnowak openismus com>
+ *
+ * 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 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, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gupnp-dlna-g-values-private.h"
+
+G_DEFINE_BOXED_TYPE (GUPnPDLNAFraction,
+                     gupnp_dlna_fraction,
+                     gupnp_dlna_fraction_copy,
+                     gupnp_dlna_fraction_free)
+
+G_DEFINE_BOXED_TYPE (GUPnPDLNAFractionRange,
+                     gupnp_dlna_fraction_range,
+                     gupnp_dlna_fraction_range_copy,
+                     gupnp_dlna_fraction_range_free)
+
+G_DEFINE_BOXED_TYPE (GUPnPDLNAIntRange,
+                     gupnp_dlna_int_range,
+                     gupnp_dlna_int_range_copy,
+                     gupnp_dlna_int_range_free)
+
+GUPnPDLNAFractionRange *
+gupnp_dlna_fraction_range_new_take (GUPnPDLNAFraction *min,
+                                    GUPnPDLNAFraction *max)
+{
+        GUPnPDLNAFractionRange *range;
+
+        g_return_val_if_fail (min != NULL, NULL);
+        g_return_val_if_fail (max != NULL, NULL);
+
+        range = g_slice_new (GUPnPDLNAFractionRange);
+        range->min = min;
+        range->max = max;
+
+        return range;
+}
+
+GUPnPDLNAIntRange *
+gupnp_dlna_int_range_new (gint min,
+                          gint max)
+{
+        GUPnPDLNAIntRange *range;
+
+        g_return_val_if_fail (min <= max, NULL);
+
+        range = g_slice_new (GUPnPDLNAIntRange);
+        range->min = min;
+        range->max = max;
+
+        return range;
+}
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_copy (GUPnPDLNAFraction *fraction)
+{
+        GUPnPDLNAFraction *dup;
+
+        if (fraction == NULL)
+                return NULL;
+
+        dup = g_slice_new (GUPnPDLNAFraction);
+        dup->numerator = fraction->numerator;
+        dup->denominator = fraction->denominator;
+
+        return dup;
+}
+
+void
+gupnp_dlna_fraction_free (GUPnPDLNAFraction *fraction)
+{
+        if (fraction == NULL)
+                return;
+
+        g_slice_free (GUPnPDLNAFraction, fraction);
+}
+
+gint
+gupnp_dlna_fraction_get_numerator (GUPnPDLNAFraction *fraction)
+{
+        g_return_val_if_fail (fraction != NULL, 0);
+
+        return fraction->numerator;
+}
+
+gint
+gupnp_dlna_fraction_get_denominator (GUPnPDLNAFraction *fraction)
+{
+        g_return_val_if_fail (fraction != NULL, 0);
+
+        return fraction->denominator;
+}
+
+GUPnPDLNAFractionRange *
+gupnp_dlna_fraction_range_copy (GUPnPDLNAFractionRange *range)
+{
+        if (range == NULL)
+                return NULL;
+
+        return gupnp_dlna_fraction_range_new_take
+                                        (gupnp_dlna_fraction_copy (range->min),
+                                         gupnp_dlna_fraction_copy (range->max));
+}
+
+void
+gupnp_dlna_fraction_range_free (GUPnPDLNAFractionRange *range)
+{
+        if (range == NULL)
+                return;
+
+        gupnp_dlna_fraction_free (range->min);
+        gupnp_dlna_fraction_free (range->max);
+        g_slice_free (GUPnPDLNAFractionRange, range);
+}
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_range_get_min (GUPnPDLNAFractionRange *range)
+{
+        g_return_val_if_fail (range != NULL, NULL);
+
+        return range->min;
+}
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_range_get_max (GUPnPDLNAFractionRange *range)
+{
+        g_return_val_if_fail (range != NULL, NULL);
+
+        return range->max;
+}
+
+GUPnPDLNAIntRange *
+gupnp_dlna_int_range_copy (GUPnPDLNAIntRange *range)
+{
+        if (range == NULL)
+                return NULL;
+
+        return gupnp_dlna_int_range_new (range->min, range->max);
+}
+
+void
+gupnp_dlna_int_range_free (GUPnPDLNAIntRange *range)
+{
+        if (range == NULL)
+                return;
+
+        g_slice_free (GUPnPDLNAIntRange, range);
+}
+
+gint
+gupnp_dlna_int_range_get_min (GUPnPDLNAIntRange *range)
+{
+        g_return_val_if_fail (range != NULL, 0);
+
+        return range->min;
+}
+
+gint
+gupnp_dlna_int_range_get_max (GUPnPDLNAIntRange *range)
+{
+        g_return_val_if_fail (range != NULL, 0);
+
+        return range->max;
+}
diff --git a/libgupnp-dlna/gupnp-dlna-g-values.h b/libgupnp-dlna/gupnp-dlna-g-values.h
new file mode 100644
index 0000000..6f0a031
--- /dev/null
+++ b/libgupnp-dlna/gupnp-dlna-g-values.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Authors: Krzesimir Nowak <krnowak openismus com>
+ *
+ * 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 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, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GUPNP_DLNA_G_VALUES_H__
+#define __GUPNP_DLNA_G_VALUES_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GUPnPDLNAFraction GUPnPDLNAFraction;
+typedef struct _GUPnPDLNAFractionRange GUPnPDLNAFractionRange;
+typedef struct _GUPnPDLNAIntRange GUPnPDLNAIntRange;
+
+#define GUPNP_DLNA_FRACTION(x) \
+        ((GUPnPDLNAFraction *) x)
+
+#define GUPNP_DLNA_FRACTION_RANGE(x) \
+        ((GUPnPDLNAFractionRange *) x)
+
+#define GUPNP_DLNA_INT_RANGE(x) \
+        ((GUPnPDLNAIntRange *) x)
+
+/**
+ * GUPNP_TYPE_DLNA_FRACTION:
+ *
+ * The #GType for #GUPnPDLNAFraction.
+ */
+#define GUPNP_TYPE_DLNA_FRACTION (gupnp_dlna_fraction_get_type ())
+
+/**
+ * GUPNP_TYPE_DLNA_FRACTION_RANGE:
+ *
+ * The #GType for #GUPnPDLNAFractionRange.
+ */
+#define GUPNP_TYPE_DLNA_FRACTION_RANGE (gupnp_dlna_fraction_range_get_type ())
+
+/**
+ * GUPNP_TYPE_DLNA_INT_RANGE:
+ *
+ * The #GType for #GUPnPDLNAIntRange.
+ */
+#define GUPNP_TYPE_DLNA_INT_RANGE (gupnp_dlna_int_range_get_type ())
+
+GType
+gupnp_dlna_fraction_get_type (void) G_GNUC_CONST;
+
+GType
+gupnp_dlna_fraction_range_get_type (void) G_GNUC_CONST;
+
+GType
+gupnp_dlna_int_range_get_type (void) G_GNUC_CONST;
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_copy (GUPnPDLNAFraction *fraction);
+
+void
+gupnp_dlna_fraction_free (GUPnPDLNAFraction *fraction);
+
+gint
+gupnp_dlna_fraction_get_numerator (GUPnPDLNAFraction *fraction);
+
+gint
+gupnp_dlna_fraction_get_denominator (GUPnPDLNAFraction *fraction);
+
+GUPnPDLNAFractionRange *
+gupnp_dlna_fraction_range_copy (GUPnPDLNAFractionRange *range);
+
+void
+gupnp_dlna_fraction_range_free (GUPnPDLNAFractionRange *range);
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_range_get_min (GUPnPDLNAFractionRange *range);
+
+GUPnPDLNAFraction *
+gupnp_dlna_fraction_range_get_max (GUPnPDLNAFractionRange *range);
+
+GUPnPDLNAIntRange *
+gupnp_dlna_int_range_copy (GUPnPDLNAIntRange *range);
+
+void
+gupnp_dlna_int_range_free (GUPnPDLNAIntRange *range);
+
+gint
+gupnp_dlna_int_range_get_min (GUPnPDLNAIntRange *range);
+
+gint
+gupnp_dlna_int_range_get_max (GUPnPDLNAIntRange *range);
+
+G_END_DECLS
+
+#endif /* __GUPNP_DLNA_G_VALUES_H__ */



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