GESTrackObject: Subclass from GInitiallyUnowned
authorEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 20 Dec 2010 10:58:21 +0000 (11:58 +0100)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 20 Dec 2010 11:03:48 +0000 (12:03 +0100)
The floating reference will be owned by the Track

ges/ges-track-object.c
ges/ges-track-object.h
ges/ges-track.c

index 5bf8bb2..5e044dc 100644 (file)
@@ -34,7 +34,8 @@
 #include "ges-track-object.h"
 #include "ges-timeline-object.h"
 
-G_DEFINE_ABSTRACT_TYPE (GESTrackObject, ges_track_object, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (GESTrackObject, ges_track_object,
+    G_TYPE_INITIALLY_UNOWNED);
 
 struct _GESTrackObjectPrivate
 {
index a0713e0..7371df3 100644 (file)
@@ -78,7 +78,7 @@ typedef struct _GESTrackObjectPrivate GESTrackObjectPrivate;
  * The GESTrackObject base class.
  */
 struct _GESTrackObject {
-  GObject parent;
+  GInitiallyUnowned parent;
 
   /*< private >*/
   guint64 start;
@@ -111,7 +111,7 @@ struct _GESTrackObject {
  */ 
 struct _GESTrackObjectClass {
   /*< private >*/
-  GObjectClass parent_class;
+  GInitiallyUnownedClass parent_class;
 
   /*< public >*/
   /* virtual methods for subclasses */
index 474a465..dea2b83 100644 (file)
@@ -292,9 +292,12 @@ ges_track_set_caps (GESTrack * track, const GstCaps * caps)
 /**
  * ges_track_add_object:
  * @track: a #GESTrack
- * @object: the #GESTrackObject to add
+ * @object: (transfer full): the #GESTrackObject to add
  *
- * Adds the given object to the track.
+ * Adds the given object to the track. Sets the object's controlling track,
+ * and thus takes ownership of the @object.
+ *
+ * An object can only be added to one track.
  *
  * Returns: #TRUE if the object was properly added. #FALSE if the track does not
  * want to accept the object.
@@ -333,6 +336,8 @@ ges_track_add_object (GESTrack * track, GESTrackObject * object)
     return FALSE;
   }
 
+  g_object_ref_sink (object);
+
   track->priv->trackobjects = g_list_append (track->priv->trackobjects, object);
 
   return TRUE;
@@ -343,7 +348,10 @@ ges_track_add_object (GESTrack * track, GESTrackObject * object)
  * @track: a #GESTrack
  * @object: the #GESTrackObject to remove
  *
- * Removes the object from the track.
+ * Removes the object from the track and unparents it.
+ * Unparenting it means the reference owned by @track on the @object will be
+ * removed. If you wish to use the @object after this function, make sure you
+ * call g_object_ref() before removing it from the @track.
  *
  * Returns: #TRUE if the object was removed, else #FALSE if the track
  * could not remove the object (like if it didn't belong to the track).
@@ -377,6 +385,8 @@ ges_track_remove_object (GESTrack * track, GESTrackObject * object)
   ges_track_object_set_track (object, NULL);
   priv->trackobjects = g_list_remove (priv->trackobjects, object);
 
+  g_object_unref (object);
+
   return TRUE;
 }