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