Add helper function to set GstObject pointers with proper ref/unref sequence.
[platform/upstream/gstreamer.git] / gst / gstobject.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstobject.c: Fundamental class used for all of GStreamer
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "gst_private.h"
24
25 #include "gstobject.h"
26 #include "gstlog.h"
27
28 /* Object signals and args */
29 enum {
30   PARENT_SET,
31   PARENT_UNSET,
32 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
33   OBJECT_SAVED,
34 #endif
35   DEEP_NOTIFY,
36   LAST_SIGNAL
37 };
38
39 enum {
40   ARG_0,
41   ARG_NAME,
42   /* FILL ME */
43 };
44
45 enum {
46   SO_OBJECT_LOADED,
47   SO_LAST_SIGNAL
48 };
49
50 GType _gst_object_type = 0;
51 static GHashTable *object_name_counts = NULL;
52 G_LOCK_DEFINE_STATIC (object_name_mutex);
53
54 typedef struct _GstSignalObject GstSignalObject;
55 typedef struct _GstSignalObjectClass GstSignalObjectClass;
56
57 static GType            gst_signal_object_get_type      (void);
58 static void             gst_signal_object_class_init    (GstSignalObjectClass *klass);
59 static void             gst_signal_object_init          (GstSignalObject *object);
60
61 static guint gst_signal_object_signals[SO_LAST_SIGNAL] = { 0 };
62
63 static void             gst_object_class_init           (GstObjectClass *klass);
64 static void             gst_object_init                 (GstObject *object);
65
66 static void             gst_object_set_property         (GObject * object, guint prop_id, const GValue * value,
67                                                          GParamSpec * pspec);
68 static void             gst_object_get_property         (GObject * object, guint prop_id, GValue * value,
69                                                          GParamSpec * pspec);
70 static void             gst_object_dispatch_properties_changed (GObject     *object,
71                                                          guint        n_pspecs,
72                                                          GParamSpec **pspecs);
73
74 static void             gst_object_dispose              (GObject *object);
75 static void             gst_object_finalize             (GObject *object);
76
77 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
78 static void             gst_object_real_restore_thyself (GstObject *object, xmlNodePtr self);
79 #endif
80
81 static GObjectClass *parent_class = NULL;
82 static guint gst_object_signals[LAST_SIGNAL] = { 0 };
83
84 GType
85 gst_object_get_type (void)
86 {
87   if (!_gst_object_type) {
88     static const GTypeInfo object_info = {
89       sizeof (GstObjectClass),
90       NULL,
91       NULL,
92       (GClassInitFunc) gst_object_class_init,
93       NULL,
94       NULL,
95       sizeof (GstObject),
96       32,
97       (GInstanceInitFunc) gst_object_init,
98       NULL
99     };
100     _gst_object_type = g_type_register_static (G_TYPE_OBJECT, "GstObject", &object_info, G_TYPE_FLAG_ABSTRACT);
101   }
102   return _gst_object_type;
103 }
104
105 static void
106 gst_object_class_init (GstObjectClass *klass)
107 {
108   GObjectClass *gobject_class;
109
110   gobject_class = (GObjectClass*) klass;
111
112   parent_class = g_type_class_ref (G_TYPE_OBJECT);
113
114   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_object_set_property);
115   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_object_get_property);
116
117   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NAME,
118     g_param_spec_string ("name", "Name", "The name of the object",
119                          NULL, G_PARAM_READWRITE));
120
121   gst_object_signals[PARENT_SET] =
122     g_signal_new ("parent_set", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
123                   G_STRUCT_OFFSET (GstObjectClass, parent_set), NULL, NULL,
124                   g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
125                   G_TYPE_OBJECT);
126   gst_object_signals[PARENT_UNSET] =
127     g_signal_new ("parent_unset", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
128                   G_STRUCT_OFFSET (GstObjectClass, parent_unset), NULL, NULL,
129                   g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
130                   G_TYPE_OBJECT);
131 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
132   gst_object_signals[OBJECT_SAVED] =
133     g_signal_new ("object_saved", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
134                   G_STRUCT_OFFSET (GstObjectClass, object_saved), NULL, NULL,
135                   g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
136                   G_TYPE_POINTER);
137   
138   klass->restore_thyself = gst_object_real_restore_thyself;
139 #endif
140   gst_object_signals[DEEP_NOTIFY] =
141     g_signal_new ("deep_notify", G_TYPE_FROM_CLASS (klass),
142                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
143                   G_STRUCT_OFFSET (GstObjectClass, deep_notify), NULL, NULL,
144                   gst_marshal_VOID__OBJECT_PARAM, G_TYPE_NONE,
145                   2, G_TYPE_OBJECT, G_TYPE_PARAM);
146
147   klass->path_string_separator = "/";
148
149   klass->signal_object = g_object_new (gst_signal_object_get_type (), NULL);
150
151   /* see the comments at gst_element_dispatch_properties_changed */
152   gobject_class->dispatch_properties_changed
153                 = GST_DEBUG_FUNCPTR (gst_object_dispatch_properties_changed);
154
155   gobject_class->dispose = gst_object_dispose;
156   gobject_class->finalize = gst_object_finalize;
157 }
158
159 static void
160 gst_object_init (GstObject *object)
161 {
162   object->lock = g_mutex_new();
163   object->parent = NULL;
164   object->name = NULL;
165
166   object->flags = 0;
167   GST_FLAG_SET (object, GST_FLOATING);
168 }
169
170 /**
171  * gst_object_ref:
172  * @object: GstObject to reference
173  *
174  * Increments the refence count on the object.
175  *
176  * Returns: A pointer to the object
177  */
178 GstObject*
179 gst_object_ref (GstObject *object)
180 {
181   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
182
183   GST_DEBUG (GST_CAT_REFCOUNTING, "ref '%s' %d->%d",GST_OBJECT_NAME(object),
184              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count+1);
185
186   g_object_ref (G_OBJECT (object));
187   return object;
188 }
189
190 /**
191  * gst_object_unref:
192  * @object: GstObject to unreference
193  *
194  * Decrements the refence count on the object.  If reference count hits
195  * zero, destroy the object.
196  */
197 void
198 gst_object_unref (GstObject *object)
199 {
200   g_return_if_fail (GST_IS_OBJECT (object));
201
202   GST_DEBUG (GST_CAT_REFCOUNTING, "unref '%s' %d->%d",GST_OBJECT_NAME(object),
203              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count-1);
204
205   g_object_unref (G_OBJECT (object));
206 }
207
208 /**
209  * gst_object_sink:
210  * @object: GstObject to sink
211  *
212  * Removes floating reference on an object.  Any newly created object has
213  * a refcount of 1 and is FLOATING.  This function should be used when
214  * creating a new object to symbolically 'take ownership of' the object.
215  * Use #gst_object_set_parent to have this done for you.
216  */
217 void
218 gst_object_sink (GstObject *object)
219 {
220   g_return_if_fail (object != NULL);
221   g_return_if_fail (GST_IS_OBJECT (object));
222
223   GST_DEBUG (GST_CAT_REFCOUNTING, "sink '%s'",GST_OBJECT_NAME(object));
224   if (GST_OBJECT_FLOATING (object))
225   {
226     GST_FLAG_UNSET (object, GST_FLOATING);
227     gst_object_unref (object);
228   }
229 }
230
231 /**
232  * gst_object_swap:
233  * @oldobj: pointer to place of old GstObject
234  * @newobj: new GstObject
235  *
236  * Unrefs the object pointer to by oldobj, refs the newobj and
237  * puts the newobj in *oldobj.
238  */
239 void
240 gst_object_swap (GstObject **oldobj, GstObject *newobj)
241 {
242   if (*oldobj != newobj) {
243     if (newobj)
244       gst_object_ref (newobj);
245     if (*oldobj)
246       gst_object_unref (*oldobj);
247
248     *oldobj = newobj;
249   }
250 }
251
252 /**
253  * gst_object_destroy:
254  * @object: GstObject to destroy
255  *
256  * Destroy the object.
257  * 
258  */
259 void
260 gst_object_destroy (GstObject *object)
261 {
262   g_return_if_fail (object != NULL);
263   g_return_if_fail (GST_IS_OBJECT (object));
264
265   GST_DEBUG (GST_CAT_REFCOUNTING, "destroy '%s'",GST_OBJECT_NAME(object));
266   if (!GST_OBJECT_DESTROYED (object))
267   {
268     /* need to hold a reference count around all class method
269      * invocations.
270      */
271     g_object_run_dispose (G_OBJECT (object));
272   }
273 }
274
275 static void
276 gst_object_dispose (GObject *object)
277 {
278   GST_DEBUG (GST_CAT_REFCOUNTING, "dispose '%s'",GST_OBJECT_NAME(object));
279   GST_FLAG_SET (GST_OBJECT (object), GST_DESTROYED);
280   GST_OBJECT_PARENT (object) = NULL;
281
282   parent_class->dispose (object);
283 }
284
285 /* finilize is called when the object has to free its resources */
286 static void
287 gst_object_finalize (GObject *object)
288 {
289   GstObject *gstobject = GST_OBJECT (object);
290
291   GST_DEBUG (GST_CAT_REFCOUNTING, "finalize '%s'",GST_OBJECT_NAME(object));
292
293   g_signal_handlers_destroy (object);
294
295   if (gstobject->name != NULL)
296     g_free (gstobject->name);
297
298   g_mutex_free (gstobject->lock);
299
300   parent_class->finalize (object);
301 }
302
303 /* Changing a GObject property of an element will result in "deep_notify"
304  * signals being emitted by the element itself, as well as in each parent
305  * element. This is so that an application can connect a listener to the
306  * top-level bin to catch property-change notifications for all contained
307  * elements. */
308 static void
309 gst_object_dispatch_properties_changed (GObject     *object,
310                                         guint        n_pspecs,
311                                         GParamSpec **pspecs)
312 {
313   GstObject *gst_object;
314   guint i;
315
316   /* do the standard dispatching */
317   G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
318
319   /* now let the parent dispatch those, too */
320   gst_object = GST_OBJECT_PARENT (object);
321   while (gst_object) {
322     /* need own category? */
323     for (i = 0; i < n_pspecs; i++) {
324       GST_DEBUG (GST_CAT_EVENT, "deep notification from %s to %s (%s)", GST_OBJECT_NAME (object),
325                  GST_OBJECT_NAME (gst_object), pspecs[i]->name);
326       g_signal_emit (gst_object, gst_object_signals[DEEP_NOTIFY], g_quark_from_string (pspecs[i]->name),
327                      (GstObject *) object, pspecs[i]);
328     }
329
330     gst_object = GST_OBJECT_PARENT (gst_object);
331   }
332 }
333
334 /** 
335  * gst_object_default_deep_notify:
336  * @object: the #GObject that signalled the notify.
337  * @orig: a #GstObject that initiated the notify.
338  * @pspec: a #GParamSpec of the property.
339  * @excluded_props: a set of user-specified properties to exclude or
340  *  NULL to show all changes.
341  *
342  * Adds a default deep_notify signal callback to an
343  * element. The user data should contain a pointer to an array of
344  * strings that should be excluded from the notify.
345  * The default handler will print the new value of the property 
346  * using g_print.
347  */
348 void
349 gst_object_default_deep_notify (GObject *object, GstObject *orig,
350                                 GParamSpec *pspec, gchar **excluded_props)
351 {
352   GValue value = { 0, }; /* the important thing is that value.type = 0 */
353   gchar *str = 0;
354   gchar *name = NULL;
355
356   if (pspec->flags & G_PARAM_READABLE) {
357     /* let's not print these out for excluded properties... */
358     while (excluded_props != NULL && *excluded_props != NULL) {
359       if (strcmp (pspec->name, *excluded_props) == 0)
360         return;
361       excluded_props++;
362     }
363     g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
364     g_object_get_property (G_OBJECT (orig), pspec->name, &value);
365
366     if (G_IS_PARAM_SPEC_ENUM (pspec)) {
367       GEnumValue *enum_value;
368       enum_value = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (pspec->value_type)),
369       g_value_get_enum (&value));
370
371       str = g_strdup_printf ("%s (%d)", enum_value->value_nick,
372                                         enum_value->value);
373     }
374     else {
375       str = g_strdup_value_contents (&value);
376     }
377     name = gst_object_get_path_string (orig);
378     g_print ("%s: %s = %s\n", name, pspec->name, str);
379     g_free (name);
380     g_free (str);
381     g_value_unset (&value);
382   } else {
383     name = gst_object_get_path_string (orig);
384     g_warning ("Parameter %s not readable in %s.",
385                pspec->name, name);
386     g_free (name);
387   }
388 }
389
390 static void
391 gst_object_set_name_default (GstObject *object)
392 {
393   gint count;
394   gchar *name, *tmp;
395   const gchar *type_name;
396   
397   type_name = G_OBJECT_TYPE_NAME (object);
398
399   /* to ensure guaranteed uniqueness across threads, only one thread
400    * may ever assign a name */
401   G_LOCK (object_name_mutex);
402
403   if (!object_name_counts)
404     object_name_counts = g_hash_table_new (g_str_hash, g_str_equal);
405
406   count = GPOINTER_TO_INT (g_hash_table_lookup (object_name_counts, type_name));
407   g_hash_table_insert (object_name_counts, g_strdup (type_name), 
408                        GINT_TO_POINTER (count + 1));
409   
410   G_UNLOCK (object_name_mutex);
411
412   /* GstFooSink -> foosinkN */
413   if (strncmp (type_name, "Gst", 3) == 0)
414     type_name += 3;
415   tmp = g_strdup_printf ("%s%d", type_name, count);
416   name = g_ascii_strdown (tmp, strlen (tmp));
417   g_free (tmp);
418   
419   gst_object_set_name (object, name);
420   g_free (name);
421 }
422
423 /**
424  * gst_object_set_name:
425  * @object: GstObject to set the name of
426  * @name: new name of object
427  *
428  * Sets the name of the object, or gives the element a guaranteed unique
429  * name (if @name is NULL).
430  */
431 void
432 gst_object_set_name (GstObject *object, const gchar *name)
433 {
434   g_return_if_fail (object != NULL);
435   g_return_if_fail (GST_IS_OBJECT (object));
436
437   if (object->name != NULL)
438     g_free (object->name);
439
440   if (name != NULL)
441     object->name = g_strdup (name);
442   else
443     gst_object_set_name_default (object);
444 }
445
446 /**
447  * gst_object_get_name:
448  * @object: GstObject to get the name of
449  *
450  * Get the name of the object.
451  *
452  * Returns: name of the object
453  */
454 const gchar*
455 gst_object_get_name (GstObject *object)
456 {
457   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
458
459   return object->name;
460 }
461
462 /**
463  * gst_object_set_parent:
464  * @object: GstObject to set parent of
465  * @parent: new parent of object
466  *
467  * Set the parent of the object.  The object's reference count is
468  * incremented.
469  * signals the parent-set signal
470  */
471 void
472 gst_object_set_parent (GstObject *object, GstObject *parent)
473 {
474   g_return_if_fail (object != NULL);
475   g_return_if_fail (GST_IS_OBJECT (object));
476   g_return_if_fail (parent != NULL);
477   g_return_if_fail (GST_IS_OBJECT (parent));
478   g_return_if_fail (object != parent);
479
480   if (object->parent != NULL) {
481     GST_ERROR_OBJECT (object,object->parent, "object's parent is already set, must unparent first");
482     return;
483   }
484
485   gst_object_ref (object);
486   gst_object_sink (object);
487   object->parent = parent;
488
489   g_signal_emit (G_OBJECT (object), gst_object_signals[PARENT_SET], 0, parent);
490 }
491
492 /**
493  * gst_object_get_parent:
494  * @object: GstObject to get parent of
495  *
496  * Return the parent of the object.
497  *
498  * Returns: parent of the object
499  */
500 GstObject*
501 gst_object_get_parent (GstObject *object)
502 {
503   g_return_val_if_fail (object != NULL, NULL);
504   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
505
506   return object->parent;
507 }
508
509 /**
510  * gst_object_unparent:
511  * @object: GstObject to unparent
512  *
513  * Clear the parent of the object, removing the associated reference.
514  */
515 void
516 gst_object_unparent (GstObject *object)
517 {
518   g_return_if_fail (object != NULL);
519   g_return_if_fail (GST_IS_OBJECT(object));
520   if (object->parent == NULL)
521     return;
522
523   GST_DEBUG (GST_CAT_REFCOUNTING, "unparent '%s'",GST_OBJECT_NAME(object));
524   
525   g_signal_emit (G_OBJECT (object), gst_object_signals[PARENT_UNSET], 0, object->parent);
526
527   object->parent = NULL;
528   gst_object_unref (object);
529 }
530
531 /**
532  * gst_object_check_uniqueness:
533  * @list: a list of #GstObject to check through
534  * @name: the name to search for
535  *
536  * This function checks through the list of objects to see if the name
537  * given appears in the list as the name of an object.  It returns TRUE if
538  * the name does not exist in the list.
539  *
540  * Returns: TRUE if the name doesn't appear in the list, FALSE if it does.
541  */
542 gboolean
543 gst_object_check_uniqueness (GList *list, const gchar *name)
544 {
545   g_return_val_if_fail (name != NULL, FALSE);
546
547   while (list) {
548     GstObject *child = GST_OBJECT (list->data);
549
550     list = g_list_next (list);
551       
552     if (strcmp (GST_OBJECT_NAME (child), name) == 0) 
553       return FALSE;
554   }
555
556   return TRUE;
557 }
558
559
560 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
561 /**
562  * gst_object_save_thyself:
563  * @object: GstObject to save
564  * @parent: The parent XML node to save the object into
565  *
566  * Saves the given object into the parent XML node.
567  *
568  * Returns: the new xmlNodePtr with the saved object
569  */
570 xmlNodePtr
571 gst_object_save_thyself (GstObject *object, xmlNodePtr parent)
572 {
573   GstObjectClass *oclass;
574
575   g_return_val_if_fail (object != NULL, parent);
576   g_return_val_if_fail (GST_IS_OBJECT (object), parent);
577   g_return_val_if_fail (parent != NULL, parent);
578
579   oclass = GST_OBJECT_GET_CLASS (object);
580
581   if (oclass->save_thyself)
582     oclass->save_thyself (object, parent);
583
584   g_signal_emit (G_OBJECT (object), gst_object_signals[OBJECT_SAVED], 0, parent);
585
586   return parent;
587 }
588
589 /**
590  * gst_object_restore_thyself:
591  * @object: GstObject to load into
592  * @self: The XML node to load the object from
593  *
594  * Restores the given object with the data from the parent XML node.
595  */
596 void
597 gst_object_restore_thyself (GstObject *object, xmlNodePtr self)
598 {
599   GstObjectClass *oclass;
600
601   g_return_if_fail (object != NULL);
602   g_return_if_fail (GST_IS_OBJECT (object));
603   g_return_if_fail (self != NULL);
604
605   oclass = GST_OBJECT_GET_CLASS (object);
606
607   if (oclass->restore_thyself)
608     oclass->restore_thyself (object, self);
609 }
610
611 static void
612 gst_object_real_restore_thyself (GstObject *object, xmlNodePtr self)
613 {
614   g_return_if_fail (object != NULL);
615   g_return_if_fail (GST_IS_OBJECT (object));
616   g_return_if_fail (self != NULL);
617   
618 /* FIXME: the signalobject stuff doesn't work
619  *  gst_class_signal_emit_by_name (object, "object_loaded", self); */
620 }
621 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */
622
623 static void
624 gst_object_set_property (GObject* object, guint prop_id, 
625                          const GValue* value, GParamSpec* pspec)
626 {
627   GstObject *gstobject;
628             
629   /* it's not null if we got it, but it might not be ours */
630   g_return_if_fail (GST_IS_OBJECT (object));
631               
632   gstobject = GST_OBJECT (object);
633
634   switch (prop_id) {
635     case ARG_NAME:
636       gst_object_set_name (gstobject, g_value_get_string (value));
637       break;
638     default:
639       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
640       break;
641   }
642 }
643
644 static void
645 gst_object_get_property (GObject* object, guint prop_id, 
646                          GValue* value, GParamSpec* pspec)
647 {
648   GstObject *gstobject;
649             
650   /* it's not null if we got it, but it might not be ours */
651   g_return_if_fail (GST_IS_OBJECT (object));
652               
653   gstobject = GST_OBJECT (object);
654
655   switch (prop_id) {
656     case ARG_NAME:
657       g_value_set_string (value, (gchar*)GST_OBJECT_NAME (gstobject));
658       break;
659     default:
660       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
661       break;
662   }
663 }
664
665 /**
666  * gst_object_get_path_string:
667  * @object: GstObject to get the path from
668  *
669  * Generates a string describing the path of the object in
670  * the object hierarchy. Only useful (or used) for debugging
671  *
672  * Returns: a string describing the path of the object
673  */
674 gchar*
675 gst_object_get_path_string (GstObject *object)
676 {
677   GSList *parentage = NULL;
678   GSList *parents;
679   void *parent;
680   gchar *prevpath, *path;
681   const char *component;
682   gchar *separator = "";
683   gboolean free_component;
684
685   parentage = g_slist_prepend (NULL, object);
686
687   path = g_strdup ("");
688
689   /* first walk the object hierarchy to build a list of the parents */
690   do {
691     if (GST_IS_OBJECT (object)) {
692       parent = gst_object_get_parent (object);
693     } else {
694       parentage = g_slist_prepend (parentage, NULL);
695       parent = NULL;
696     }
697
698     if (parent != NULL) {
699       parentage = g_slist_prepend (parentage, parent);
700     }
701
702     object = parent;
703   } while (object != NULL);
704
705   /* then walk the parent list and print them out */
706   parents = parentage;
707   while (parents) {
708     if (GST_IS_OBJECT (parents->data)) {
709       GstObjectClass *oclass = GST_OBJECT_GET_CLASS (parents->data);
710
711       component = gst_object_get_name (parents->data);
712       separator = oclass->path_string_separator;
713       free_component = FALSE;
714     } else {
715       component = g_strdup_printf("%p",parents->data);
716       separator = "/";
717       free_component = TRUE;
718     }
719
720     prevpath = path;
721     path = g_strjoin (separator, prevpath, component, NULL);
722     g_free(prevpath);
723     if (free_component)
724       g_free((gchar *)component);
725
726     parents = g_slist_next(parents);
727   }
728
729   g_slist_free (parentage);
730
731   return path;
732 }
733
734
735
736 struct _GstSignalObject {
737   GObject object;
738 };
739
740 struct _GstSignalObjectClass {
741   GObjectClass        parent_class;
742
743   /* signals */
744 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
745   void          (*object_loaded)           (GstSignalObject *object, GstObject *new, xmlNodePtr self);
746 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */
747 };
748
749 static GType
750 gst_signal_object_get_type (void)
751 {
752   static GType signal_object_type = 0;
753
754   if (!signal_object_type) {
755     static const GTypeInfo signal_object_info = {
756       sizeof(GstSignalObjectClass),
757       NULL,
758       NULL,
759       (GClassInitFunc)gst_signal_object_class_init,
760       NULL,
761       NULL,
762       sizeof(GstSignalObject),
763       16,
764       (GInstanceInitFunc)gst_signal_object_init,
765       NULL
766     };
767     signal_object_type = g_type_register_static(G_TYPE_OBJECT, "GstSignalObject", &signal_object_info, 0);
768   }
769   return signal_object_type;
770 }
771
772 static void
773 gst_signal_object_class_init (GstSignalObjectClass *klass)
774 {
775   GObjectClass *gobject_class;
776
777   gobject_class = (GObjectClass*) klass;
778
779   parent_class = g_type_class_ref (G_TYPE_OBJECT);
780
781 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
782   gst_signal_object_signals[SO_OBJECT_LOADED] =
783     g_signal_new ("object_loaded", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
784                   G_STRUCT_OFFSET (GstObjectClass, parent_set), NULL, NULL,
785                   gst_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2,
786                   G_TYPE_OBJECT, G_TYPE_POINTER);
787 #endif
788 }
789
790 static void
791 gst_signal_object_init (GstSignalObject *object)
792 {
793 }
794
795 /**
796  * gst_class_signal_connect
797  * @klass: the GstObjectClass to attach the signal to
798  * @name: the name of the signal to attach to
799  * @func: the signal function
800  * @func_data: a pointer to user data
801  *
802  * Connect to a class signal.
803  *
804  * Returns: the signal id.
805  */
806 guint
807 gst_class_signal_connect (GstObjectClass *klass,
808                           const gchar    *name,
809                           gpointer  func,
810                           gpointer       func_data)
811 {
812   return g_signal_connect (klass->signal_object, name, func, func_data);
813 }
814
815 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
816 /**
817  * gst_class_signal_emit_by_name:
818  * @object: the object that sends the signal
819  * @name: the name of the signal to emit
820  * @self: data for the signal
821  *
822  * emits the named class signal.
823  */
824 void
825 gst_class_signal_emit_by_name (GstObject *object,
826                                const gchar *name,
827                                xmlNodePtr self)
828 {
829   GstObjectClass *oclass;
830
831   oclass = GST_OBJECT_GET_CLASS (object);
832
833   g_signal_emit_by_name (oclass->signal_object, name, object, self);
834 }
835
836 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */