[Multi-valued V2 (grilo) 01/12] core: Add a new class to handle multivalued properties.



GrlMedia and derived classes inherits from this multivalued class.

To keep as simple as possible GrlMedia, it will only deal with single values.

For handling multivalued properties, use GrlDataMulti class.

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 src/Makefile.am           |    2 +
 src/data/grl-data-multi.c |  104 +++++++++++++++++++++++++++++++++++++++++++++
 src/data/grl-data-multi.h |   99 ++++++++++++++++++++++++++++++++++++++++++
 src/data/grl-media.c      |    2 +-
 src/data/grl-media.h      |    6 +-
 5 files changed, 209 insertions(+), 4 deletions(-)
 create mode 100644 src/data/grl-data-multi.c
 create mode 100644 src/data/grl-data-multi.h

diff --git a/src/Makefile.am b/src/Makefile.am
index e5b82cc..91dac9e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,7 @@ lib@GRL_NAME@_la_SOURCES =					\
 
 data_c_sources =		\
 	data/grl-data.c		\
+	data/grl-data-multi.c	\
 	data/grl-media.c	\
 	data/grl-media-audio.c	\
 	data/grl-media-video.c	\
@@ -78,6 +79,7 @@ lib@GRL_NAME@inc_HEADERS =	\
 
 data_h_headers =		\
 	data/grl-data.h		\
+	data/grl-data-multi.h	\
 	data/grl-media.h	\
 	data/grl-media-box.h	\
 	data/grl-media-audio.h	\
diff --git a/src/data/grl-data-multi.c b/src/data/grl-data-multi.c
new file mode 100644
index 0000000..2047bc7
--- /dev/null
+++ b/src/data/grl-data-multi.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Contact: Iago Toral Quiroga <itoral igalia com>
+ *
+ * Authors: Juan A. Suarez Romero <jasuarez igalia 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; 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+/**
+ * SECTION:grl-data-multi
+ * @short_description: Low-level class to store multivalued data
+ * @see_also: #GrlMedia, #GrlMediaBox, #GrlMediaVideo, #GrlMediaAudio, #GrlMediaImage
+ *
+ * This class acts as dictionary where keys and their values can be stored. It
+ * is suggested to better high level classes, like #GrlMedia, which
+ * provides functions to access known properties.
+ */
+
+#include "grl-data-multi.h"
+#include "grl-log.h"
+
+struct _GrlDataMultiPrivate {
+  GHashTable *extended_data;
+};
+
+static void grl_data_multi_finalize (GObject *object);
+
+#define GRL_DATA_MULTI_GET_PRIVATE(o)                                   \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GRL_TYPE_DATA_MULTI, GrlDataMultiPrivate))
+
+G_DEFINE_TYPE (GrlDataMulti, grl_data_multi, GRL_TYPE_DATA);
+
+static void
+free_list_values (GrlKeyID key,
+                  GList *values,
+                  gpointer user_data)
+{
+  g_list_foreach (values, (GFunc) g_object_unref, NULL);
+  g_list_free (values);
+}
+
+
+static void
+grl_data_multi_class_init (GrlDataMultiClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *)klass;
+
+  gobject_class->finalize = grl_data_multi_finalize;
+
+  g_type_class_add_private (klass, sizeof (GrlDataMultiPrivate));
+}
+
+static void
+grl_data_multi_init (GrlDataMulti *self)
+{
+  self->priv = GRL_DATA_MULTI_GET_PRIVATE (self);
+  self->priv->extended_data = g_hash_table_new_full (g_direct_hash,
+                                                     g_direct_equal,
+                                                     NULL,
+                                                     NULL);
+}
+
+static void
+grl_data_multi_finalize (GObject *object)
+{
+  GrlDataMulti *mdata = GRL_DATA_MULTI (object);
+
+  g_hash_table_foreach (mdata->priv->extended_data,
+                        (GHFunc) free_list_values,
+                        NULL);
+  g_hash_table_unref (mdata->priv->extended_data);
+
+  G_OBJECT_CLASS (grl_data_multi_parent_class)->finalize (object);
+}
+
+/**
+ * grl_data_multi_new:
+ *
+ * Creates a new multivalued data object.
+ *
+ * Returns: a new multivalued data object.
+ **/
+GrlDataMulti *
+grl_data_multi_new (void)
+{
+  return g_object_new (GRL_TYPE_DATA_MULTI,
+		       NULL);
+}
diff --git a/src/data/grl-data-multi.h b/src/data/grl-data-multi.h
new file mode 100644
index 0000000..3e25973
--- /dev/null
+++ b/src/data/grl-data-multi.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Contact: Iago Toral Quiroga <itoral igalia com>
+ *
+ * Authors: Juan A. Suarez Romero <jasuarez igalia 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; 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#if !defined (_GRILO_H_INSIDE_) && !defined (GRILO_COMPILATION)
+#error "Only <grilo.h> can be included directly."
+#endif
+
+#ifndef _GRL_DATA_MULTI_H_
+#define _GRL_DATA_MULTI_H_
+
+#include <grl-data.h>
+#include <glib-object.h>
+/* #include <grl-metadata-key.h> */
+/* #include <grl-definitions.h> */
+
+G_BEGIN_DECLS
+
+#define GRL_TYPE_DATA_MULTI                     \
+  (grl_data_multi_get_type())
+
+#define GRL_DATA_MULTI(obj)                           \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                 \
+                               GRL_TYPE_DATA_MULTI,   \
+                               GrlDataMulti))
+
+#define GRL_DATA_MULTI_CLASS(klass)                   \
+  (G_TYPE_CHECK_CLASS_CAST ((klass),                  \
+                            GRL_TYPE_DATA_MULTI,      \
+                            GrlDataMultiClass))
+
+#define GRL_IS_DATA_MULTI(obj)                          \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj),                   \
+                               GRL_TYPE_DATA_MULTI))
+
+#define GRL_IS_DATA_MULTI_CLASS(klass)                  \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass),                    \
+                            GRL_TYPE_DATA_MULTI))
+
+#define GRL_DATA_MULTI_GET_CLASS(obj)                   \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj),                    \
+                              GRL_TYPE_DATA_MULTI,      \
+                              GrlDataMultiClass))
+
+typedef struct _GrlDataMulti        GrlDataMulti;
+typedef struct _GrlDataMultiPrivate GrlDataMultiPrivate;
+typedef struct _GrlDataMultiClass   GrlDataMultiClass;
+
+/**
+ * GrlDataMultiClass:
+ * @parent_class: the parent class structure
+ *
+ * Grilo Data Multivalued class
+ */
+struct _GrlDataMultiClass
+{
+  GrlDataClass parent_class;
+
+  /*< private >*/
+  gpointer _grl_reserved[GRL_PADDING];
+};
+
+struct _GrlDataMulti
+{
+  GrlData parent;
+
+  /*< private >*/
+  GrlDataMultiPrivate *priv;
+
+  gpointer _grl_reserved[GRL_PADDING_SMALL];
+};
+
+GType grl_data_multi_get_type (void) G_GNUC_CONST;
+
+GrlDataMulti *grl_data_multi_new (void);
+
+G_END_DECLS
+
+#endif /* _GRL_DATA_MULTI_H_ */
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index d37bed3..ad3cf63 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -44,7 +44,7 @@ GRL_LOG_DOMAIN(media_log_domain);
 static void grl_media_dispose (GObject *object);
 static void grl_media_finalize (GObject *object);
 
-G_DEFINE_TYPE (GrlMedia, grl_media, GRL_TYPE_DATA);
+G_DEFINE_TYPE (GrlMedia, grl_media, GRL_TYPE_DATA_MULTI);
 
 static void
 grl_media_class_init (GrlMediaClass *klass)
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 31c2928..347b48f 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -29,7 +29,7 @@
 #ifndef _GRL_MEDIA_H_
 #define _GRL_MEDIA_H_
 
-#include <grl-data.h>
+#include <grl-data-multi.h>
 #include <grl-definitions.h>
 
 G_BEGIN_DECLS
@@ -85,7 +85,7 @@ typedef struct _GrlMediaClass GrlMediaClass;
  */
 struct _GrlMediaClass
 {
-  GrlDataClass parent_class;
+  GrlDataMultiClass parent_class;
 
   /*< private >*/
   gpointer _grl_reserved[GRL_PADDING];
@@ -93,7 +93,7 @@ struct _GrlMediaClass
 
 struct _GrlMedia
 {
-  GrlData parent;
+  GrlDataMulti parent;
 
   /*< private >*/
   gpointer _grl_reserved[GRL_PADDING_SMALL];
-- 
1.7.4



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