From 0ce5053ac4df908cce4c83f1df62a72205a013e1 Mon Sep 17 00:00:00 2001 From: Brandon Lewis Date: Thu, 7 Oct 2010 14:25:22 +0100 Subject: [PATCH] GESFormatter: Add data-related methods --- docs/libs/ges-sections.txt | 3 ++ ges/ges-formatter.c | 106 ++++++++++++++++++++++++++++++++++++++++----- ges/ges-formatter.h | 11 ++++- 3 files changed, 109 insertions(+), 11 deletions(-) diff --git a/docs/libs/ges-sections.txt b/docs/libs/ges-sections.txt index ee9af24..4f51450 100644 --- a/docs/libs/ges-sections.txt +++ b/docs/libs/ges-sections.txt @@ -544,6 +544,9 @@ ges_formatter_can_load_uri ges_formatter_can_save_uri ges_formatter_load ges_formatter_save +ges_formatter_set_data +ges_formatter_clear_data +ges_formatter_get_data ges_formatter_get_type GES_FORMATTER diff --git a/ges/ges-formatter.c b/ges/ges-formatter.c index 8d36e1d..9b812b9 100644 --- a/ges/ges-formatter.c +++ b/ges/ges-formatter.c @@ -36,6 +36,11 @@ G_DEFINE_TYPE (GESFormatter, ges_formatter, G_TYPE_OBJECT); static void ges_formatter_dispose (GObject * object); static void ges_formatter_finalize (GObject * object); +static gboolean load_from_uri (GESFormatter * formatter, GESTimeline * + timeline, gchar * uri); +static gboolean save_to_uri (GESFormatter * formatter, GESTimeline * + timeline, gchar * uri); + static void ges_formatter_class_init (GESFormatterClass * klass) @@ -44,6 +49,9 @@ ges_formatter_class_init (GESFormatterClass * klass) object_class->dispose = ges_formatter_dispose; object_class->finalize = ges_formatter_finalize; + + klass->load_from_uri = load_from_uri; + klass->save_to_uri = save_to_uri; } static void @@ -168,14 +176,71 @@ ges_formatter_can_save_uri (gchar * uri) } /** + * ges_formatter_set_data: + * @formatter: a pointer to a #GESFormatter instance or subclass + * @data: a pointer to the data to be set on the formatter + * @length: a #gsize indicating the length of the data in bytes + * + * Set the data that this formatter will use for loading. The formatter will + * takes ownership of the data and will free the data if + * ges_formatter_set_data is called again or when the formatter itself is + * disposed. You should calle ges_formatter_clear_data () if you do not wish + * this to happen. + */ + +void +ges_formatter_set_data (GESFormatter * formatter, void *data, gsize length) +{ + if (formatter->data) + g_free (formatter->data); + formatter->data = data; + formatter->length = length; +} + +/** + * ges_formatter_set_data: + * @formatter: a pointer to a #GESFormatter + * @length: a pointer to a location into which to store the size of the + * data in bytes. + * + * Returns: a pointer to the data. + */ + +void * +ges_formatter_get_data (GESFormatter * formatter, gsize * length) +{ + *length = formatter->length; + + return formatter->data; +} + +/** + * ges_formatter_clear_data: + * @formatter: a pointer to a #GESFormatter + * + * clears the data from a #GESFormatter without freeing it. You should call + * this before disposing or setting data on a #GESFormatter if the current data + * pointer should not be freed. + * + * Returns: a pointer to the data + */ + +void +ges_formatter_clear_data (GESFormatter * formatter) +{ + formatter->data = NULL; + formatter->length = 0; +} + +/** * ges_formatter_load: * @formatter: a pointer to a #GESFormatter instance or subclass. * @timeline: a pointer to a #GESTimeline * - * Loads data from formatter to into timeline. The data field of formatter - * must point to a block of data, and length must be correctly set to the - * length of the data. This method is only implemented in subclasses. - * + * Loads data from formatter to into timeline. You should first call + * ges_formatter_set_data () with the location and size of a block of data + * from which to read. This method is only implemented in subclasses. + * * Returns: TRUE if the data was successfully loaded into timeline * or FALSE if an error occured during loading. */ @@ -198,10 +263,9 @@ ges_formatter_load (GESFormatter * formatter, GESTimeline * timeline) * @formatter: a pointer to a #GESFormatter instance or subclass. * @timeline: a pointer to a #GESTimeline * - * Save data from timeline into formatter. Upon success, The data field of the - * formatter will point to a newly-allocated block of data, and the length - * field of the formatter will contain the length of the block. This method is - * only implemented in subclasses. + * Save data from timeline into a block of data. You can retrieve the location + * and size of this data with ges_formatter_get_data(). This method is only + * implemented in subclasses. * * Returns: TRUE if the timeline data was successfully saved for FALSE if * an error occured during saving. @@ -242,6 +306,17 @@ gboolean ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline, gchar * uri) { + GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter); + + if (klass->load_from_uri) + return klass->load_from_uri (formatter, timeline, uri); + + return FALSE; +} + +static gboolean +load_from_uri (GESFormatter * formatter, GESTimeline * timeline, gchar * uri) +{ gchar *location; GError *e = NULL; gboolean ret = TRUE; @@ -292,8 +367,19 @@ ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline, */ gboolean -ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline * timeline, - gchar * uri) +ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline * + timeline, gchar * uri) +{ + GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter); + + if (klass->save_to_uri) + return klass->save_to_uri (formatter, timeline, uri); + + return FALSE; +} + +static gboolean +save_to_uri (GESFormatter * formatter, GESTimeline * timeline, gchar * uri) { gchar *location; GError *e = NULL; diff --git a/ges/ges-formatter.h b/ges/ges-formatter.h index d35f22b..5a0d3b6 100644 --- a/ges/ges-formatter.h +++ b/ges/ges-formatter.h @@ -43,7 +43,6 @@ /** * GESFormatter: - * @parent: parent * * Base class for timeline data serialization and deserialization. */ @@ -63,6 +62,8 @@ struct _GESFormatter { * from a given URI. * @can_save_uri: class method which rturns true of a #GEFormatterClass can * write to a given URI. + * @load_from_uri: class method to deserialize data from a URI + * @save_from_uri: class method to serialize data to a URI * @save: method to save timeline data * @load: method to load timeline data * @@ -73,6 +74,8 @@ struct _GESFormatterClass { gboolean (*can_load_uri) (gchar * uri); gboolean (*can_save_uri) (gchar * uri); + gboolean (*load_from_uri) (GESFormatter *, GESTimeline *, gchar * uri); + gboolean (*save_to_uri) (GESFormatter *, GESTimeline *, gchar * uri); gboolean (*save) (GESFormatter * formatter, GESTimeline * timeline); gboolean (*load) (GESFormatter * formatter, GESTimeline * timeline); }; @@ -91,6 +94,12 @@ gboolean ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline gboolean ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline *timeline, gchar *uri); +void ges_formatter_set_data (GESFormatter * formatter, void *data, gsize + length); + +void *ges_formatter_get_data (GESFormatter *formatter, gsize *length); +void ges_formatter_clear_data (GESFormatter *formatter); + gboolean ges_formatter_load (GESFormatter * formatter, GESTimeline * timeline); gboolean ges_formatter_save (GESFormatter * formatter, GESTimeline * timeline); -- 2.7.4